Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/council-webapp:master commit in: bot/tests/, bot/tests/test_scripts/
Date: Wed, 03 Aug 2011 09:58:02
Message-Id: 0ffafa90d465fb5a45dd022530000cefc3840d74.betelgeuse@gentoo
1 commit: 0ffafa90d465fb5a45dd022530000cefc3840d74
2 Author: Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
3 AuthorDate: Mon Aug 1 22:30:21 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Wed Aug 3 08:44:32 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=0ffafa90
7
8 Improve MeetBot tests
9
10 Keep long bot input and output sequences in separate files.
11
12 ---
13 bot/tests/run_test.py | 144 ++-----------------
14 bot/tests/test_meeting.py | 30 ++++-
15 bot/tests/test_scripts/actionNickMatching.txt | 7 +
16 bot/tests/test_scripts/agenda_item_changing.json | 21 +++
17 bot/tests/test_scripts/agenda_option_adding.json | 6 +
18 bot/tests/test_scripts/agenda_option_listing.json | 7 +
19 bot/tests/test_scripts/agenda_option_removing.json | 5 +
20 bot/tests/test_scripts/agenda_voting.json | 11 ++
21 bot/tests/test_scripts/all_commands.txt | 22 +++
22 .../test_scripts/close_voting_after_last_vote.json | 6 +
23 bot/tests/test_scripts/urlMatching.txt | 8 +
24 11 files changed, 137 insertions(+), 130 deletions(-)
25
26 diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py
27 index 3f84ccb..a6077cb 100644
28 --- a/bot/tests/run_test.py
29 +++ b/bot/tests/run_test.py
30 @@ -1,4 +1,5 @@
31 # Richard Darst, 2009
32 +# Joachim Bartosik, 2011
33
34 import glob
35 import os
36 @@ -127,30 +128,8 @@ class MeetBotTest(unittest.TestCase):
37 # process_meeting(contents=file('test-script-3.log.txt').read(),
38 # extraConfig={'writer_map':self.full_writer_map})
39
40 - all_commands_test_contents = """
41 - 10:10:10 <x> #startmeeting
42 - 10:10:10 <x> #topic h6k4orkac
43 - 10:10:10 <x> #info blaoulrao
44 - 10:10:10 <x> #idea alrkkcao4
45 - 10:10:10 <x> #help ntoircoa5
46 - 10:10:10 <x> #link http://bnatorkcao.net kroacaonteu
47 - 10:10:10 <x> http://jrotjkor.net krotroun
48 - 10:10:10 <x> #action xrceoukrc
49 - 10:10:10 <x> #nick okbtrokr
50 -
51 - # Should not appear in non-log output
52 - 10:10:10 <x> #idea ckmorkont
53 - 10:10:10 <x> #undo
54 -
55 - # Assert that chairs can change the topic, and non-chairs can't.
56 - 10:10:10 <x> #chair y
57 - 10:10:10 <y> #topic topic_doeschange
58 - 10:10:10 <z> #topic topic_doesntchange
59 - 10:10:10 <x> #unchair y
60 - 10:10:10 <y> #topic topic_doesnt2change
61 + all_commands_test_contents = test_meeting.get_test_script('all_commands.txt')
62
63 - 10:10:10 <x> #endmeeting
64 - """
65 def test_contents_test2(self):
66 """Ensure that certain input lines do appear in the output.
67
68 @@ -212,15 +191,9 @@ class MeetBotTest(unittest.TestCase):
69 the nick 'jon' will no longer be assigned lines containing
70 'jonathan'.
71 """
72 - script = """
73 - 20:13:50 <x> #startmeeting
74 - 20:13:50 <somenick>
75 - 20:13:50 <someone> #action say somenickLONG
76 - 20:13:50 <someone> #action say the somenicklong
77 - 20:13:50 <somenick> I should not have an item assisgned to me.
78 - 20:13:50 <somenicklong> I should have some things assigned to me.
79 - 20:13:50 <x> #endmeeting
80 - """
81 +
82 + script = open('test_scripts/actionNickMatching.txt').read()
83 +
84 M = process_meeting(script)
85 results = M.save()['.html']
86 # This regular expression is:
87 @@ -234,16 +207,8 @@ class MeetBotTest(unittest.TestCase):
88 def test_urlMatching(self):
89 """Test properly detection of URLs in lines
90 """
91 - script = """
92 - 20:13:50 <x> #startmeeting
93 - 20:13:50 <x> #link prefix http://site1.com suffix
94 - 20:13:50 <x> http://site2.com suffix
95 - 20:13:50 <x> ftp://ftpsite1.com suffix
96 - 20:13:50 <x> #link prefix ftp://ftpsite2.com suffix
97 - 20:13:50 <x> irc://ircsite1.com suffix
98 - 20:13:50 <x> mailto://a@××××.com suffix
99 - 20:13:50 <x> #endmeeting
100 - """
101 + script = open('test_scripts/urlMatching.txt').read()
102 +
103 M = process_meeting(script)
104 results = M.save()['.html']
105 assert re.search(r'prefix.*href.*http://site1.com.*suffix',
106 @@ -358,100 +323,23 @@ class MeetBotTest(unittest.TestCase):
107
108 return(test)
109
110 - def test_agenda_item_changing(self):
111 - test = self.get_simple_agenda_test()
112 -
113 - # Test changing item before vote
114 - test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
115 - test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is third item.')
116 - test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is third item.')
117 - test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is second item.')
118 - test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
119 - test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
120 - test.answer_should_match('20:13:50 <x> #changeitem 2', 'Current agenda item is third item.')
121 - test.answer_should_match('20:13:50 <x> #changeitem 1', 'Current agenda item is second item.')
122 - test.answer_should_match('20:13:50 <x> #changeitem 0', 'Current agenda item is first item.')
123 - test.answer_should_match('20:13:50 <x> #changeitem 10', 'Your choice was out of range!')
124 - test.answer_should_match('20:13:50 <x> #changeitem puppy', 'Your choice was not recognized as a number. Please retry.')
125 -
126 - # Test changing item during vote
127 - test.process('20:13:50 <x> #startvote')
128 - test.answer_should_match('20:13:50 <x> #nextitem', 'Voting is currently ' +\
129 - 'open so I didn\'t change item. Please #endvote first')
130 - test.answer_should_match('20:13:50 <x> #previtem', 'Voting is currently ' +\
131 - 'open so I didn\'t change item. Please #endvote first')
132 - test.answer_should_match('20:13:50 <x> #changeitem 2', 'Voting is currently ' +\
133 - 'open so I didn\'t change item. Please #endvote first')
134 -
135 - # Test changing item after vote
136 - test.process('20:13:50 <x> #endvote')
137 - test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
138 - test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
139 - test.answer_should_match('20:13:50 <x> #changeitem 2', 'Current agenda item is third item.')
140 -
141 - def test_agenda_option_listing(self):
142 - test = self.get_simple_agenda_test()
143 -
144 - test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
145 - 'are:\n0. opt1\n1. opt2\n')
146 - test.process('20:13:50 <x> #nextitem')
147 - test.answer_should_match('20:13:50 <x> #option list', 'No voting options available.')
148 - test.process('20:13:50 <x> #previtem')
149 - test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
150 - 'are:\n0. opt1\n1. opt2\n')
151 -
152 - def test_agenda_option_adding(self):
153 - test = self.get_simple_agenda_test()
154 - test.process('20:13:50 <x> #nextitem')
155 - test.answer_should_match('20:13:50 <not_allowed> #option add first option',
156 - 'You can not vote or change agenda. Only x, z can.')
157 - test.answer_should_match('20:13:50 <x> #option add first option',
158 - 'You added new voting option: first option')
159 - test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
160 - 'are:\n0. first option')
161 -
162 - def test_agenda_option_removing(self):
163 - test = self.get_simple_agenda_test()
164 - test.answer_should_match('20:13:50 <not_allowed> #option remove 1',
165 - 'You can not vote or change agenda. Only x, z can.')
166 - test.answer_should_match('20:13:50 <x> #option remove 1',
167 - 'You removed voting option 1: opt2')
168 - test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
169 - 'are:\n0. opt1')
170 + def test_message_answer_tests(self):
171 + files = ['agenda_item_changing', 'agenda_option_listing',
172 + 'agenda_option_adding', 'agenda_option_removing',
173 + 'close_voting_after_last_vote']
174 + for file in files:
175 + test = self.get_simple_agenda_test()
176 + test.check_responses_from_json_file(file)
177
178 def test_agenda_voting(self):
179 test = self.get_simple_agenda_test()
180 test.M.config.agenda._voters.append('t')
181 - test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\
182 - 'Available voting options are:\n0. opt1\n1. opt2\nVote ' +\
183 - '#vote <option number>.\nEnd voting with #endvote.')
184 - test.answer_should_match('20:13:50 <x> #startvote', 'Voting is already open. ' +\
185 - 'You can end it with #endvote.')
186 - test.answer_should_match('20:13:50 <x> #vote 10', 'Your choice was out of range\!')
187 - test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1')
188 - test.answer_should_match('20:13:50 <x> #vote 1', 'You voted for #1 - opt2')
189 - test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1')
190 - test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
191 - 'are:\n0. opt1\n1. opt2\n')
192 - test.answer_should_match('20:13:50 <x> #endvote', 'Voting closed.')
193 - test.answer_should_match('20:13:50 <x> #endvote', 'Voting is already closed. ' +\
194 - 'You can start it with #startvote.')
195 -
196 + test.check_responses_from_json_file('agenda_voting')
197 test.M.config.manage_agenda = False
198 test.answer_should_match('20:13:50 <x> #endmeeting', 'Meeting ended ' +\
199 '.*\nMinutes:.*\nMinutes \(text\):.*\nLog:.*')
200 -
201 assert(test.votes() == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}, 'third item': {}})
202
203 - def test_agenda_close_voting_after_last_vote(self):
204 - test = self.get_simple_agenda_test()
205 - test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\
206 - 'Available voting options are:\n0. opt1\n1. opt2\nVote ' +\
207 - '#vote <option number>.\nEnd voting with #endvote.')
208 - test.answer_should_match('20:13:50 <x> #startvote', 'Voting is already open. ' +\
209 - 'You can end it with #endvote.')
210 - test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1')
211 - test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1. Voting closed.')
212
213 def test_agenda_time_limit_adding(self):
214 test = self.get_simple_agenda_test()
215 @@ -533,6 +421,7 @@ class MeetBotTest(unittest.TestCase):
216 error_msg = 'Received messages ' + str(test.log) + \
217 ' didn\'t match expected ' + str(expected_messages)
218 assert messages_match, error_msg
219 +
220 def test_command_help(self):
221 test = self.get_simple_agenda_test()
222 commands = ['startmeeting', 'startvote', 'vote', 'endvote',
223 @@ -556,4 +445,3 @@ if __name__ == '__main__':
224 MeetBotTest(methodName=testname).debug()
225 else:
226 MeetBotTest(methodName='test_'+testname).debug()
227 -
228
229 diff --git a/bot/tests/test_meeting.py b/bot/tests/test_meeting.py
230 index 238ba2f..218d7d1 100644
231 --- a/bot/tests/test_meeting.py
232 +++ b/bot/tests/test_meeting.py
233 @@ -1,5 +1,8 @@
234 import ircmeeting.meeting as meeting
235 import ircmeeting.writers as writers
236 +import inspect
237 +import json
238 +import os
239 import re
240 import time
241 class TestMeeting:
242 @@ -50,14 +53,37 @@ class TestMeeting:
243 line = m.group(3).strip()
244 self.M.addline(nick, "ACTION "+line, time_=time_)
245
246 - def answer_should_match(self, line, answer_regexp):
247 + def check_responses_from_json_file(self, file):
248 + json_file_name = file + ".json"
249 + json_string = get_test_script(json_file_name)
250 + json_data = json.loads(json_string)
251 + prefix = "(in " + file + ")"
252 + for line in json_data:
253 + if line.__class__ in [str, unicode]:
254 + self.process(line)
255 + elif (line.__class__ in [list, tuple]) and (len(line) == 2):
256 + self.answer_should_match(line[0], line[1], prefix)
257 + else:
258 + error_msg = "In file " + file + "Each item in test case must " +\
259 + "be string, unicode string, list of length 2. Item `" +\
260 + str(line) + "` doesn't fulfill those requirements."
261 + raise AssertionError(error_msg)
262 +
263 + def answer_should_match(self, line, answer_regexp, prefix = ''):
264 self.log = []
265 self.process(line)
266 answer = '\n'.join(self.log)
267 - error_msg = "Answer for:\n\t'" + line + "'\n was \n\t'" + answer +\
268 + error_msg = prefix + "Answer for:\n\t'" + line + "'\n was \n\t'" + answer +\
269 "'\ndid not match regexp\n\t'" + answer_regexp + "'"
270 answer_matches = re.match(answer_regexp, answer)
271 assert answer_matches, error_msg
272
273 def votes(self):
274 return(self.M.config.agenda._votes)
275 +
276 +def get_test_script(test_script_file_name):
277 + this_file_path = inspect.getfile(inspect.currentframe())
278 + this_dir_path = os.path.dirname(this_file_path)
279 + test_script_path = os.path.join(this_dir_path, 'test_scripts', test_script_file_name)
280 + test_script_file = open(test_script_path)
281 + return test_script_file.read()
282
283 diff --git a/bot/tests/test_scripts/actionNickMatching.txt b/bot/tests/test_scripts/actionNickMatching.txt
284 new file mode 100644
285 index 0000000..392a503
286 --- /dev/null
287 +++ b/bot/tests/test_scripts/actionNickMatching.txt
288 @@ -0,0 +1,7 @@
289 +20:13:50 <x> #startmeeting
290 +20:13:50 <somenick>
291 +20:13:50 <someone> #action say somenickLONG
292 +20:13:50 <someone> #action say the somenicklong
293 +20:13:50 <somenick> I should not have an item assisgned to me.
294 +20:13:50 <somenicklong> I should have some things assigned to me.
295 +20:13:50 <x> #endmeeting
296
297 diff --git a/bot/tests/test_scripts/agenda_item_changing.json b/bot/tests/test_scripts/agenda_item_changing.json
298 new file mode 100644
299 index 0000000..c78e9be
300 --- /dev/null
301 +++ b/bot/tests/test_scripts/agenda_item_changing.json
302 @@ -0,0 +1,21 @@
303 +[
304 +["20:13:50 <x> #nextitem", "Current agenda item is second item."],
305 +["20:13:50 <x> #nextitem", "Current agenda item is third item."],
306 +["20:13:50 <x> #nextitem", "Current agenda item is third item."],
307 +["20:13:50 <x> #previtem", "Current agenda item is second item."],
308 +["20:13:50 <x> #previtem", "Current agenda item is first item."],
309 +["20:13:50 <x> #previtem", "Current agenda item is first item."],
310 +["20:13:50 <x> #changeitem 2", "Current agenda item is third item."],
311 +["20:13:50 <x> #changeitem 1", "Current agenda item is second item."],
312 +["20:13:50 <x> #changeitem 0", "Current agenda item is first item."],
313 +["20:13:50 <x> #changeitem 10", "Your choice was out of range!"],
314 +["20:13:50 <x> #changeitem puppy", "Your choice was not recognized as a number. Please retry."],
315 +"20:13:50 <x> #startvote",
316 +["20:13:50 <x> #nextitem", "Voting is currently open so I didn't change item. Please #endvote first"],
317 +["20:13:50 <x> #previtem", "Voting is currently open so I didn't change item. Please #endvote first"],
318 +["20:13:50 <x> #changeitem 2", "Voting is currently open so I didn't change item. Please #endvote first"],
319 +"20:13:50 <x> #endvote",
320 +["20:13:50 <x> #nextitem", "Current agenda item is second item."],
321 +["20:13:50 <x> #previtem", "Current agenda item is first item."],
322 +["20:13:50 <x> #changeitem 2", "Current agenda item is third item."]
323 +]
324
325 diff --git a/bot/tests/test_scripts/agenda_option_adding.json b/bot/tests/test_scripts/agenda_option_adding.json
326 new file mode 100644
327 index 0000000..cb3c068
328 --- /dev/null
329 +++ b/bot/tests/test_scripts/agenda_option_adding.json
330 @@ -0,0 +1,6 @@
331 +[
332 +"20:13:50 <x> #nextitem",
333 +["20:13:50 <not_allowed> #option add first option", "You can not vote or change agenda. Only x, z can."],
334 +["20:13:50 <x> #option add first option", "You added new voting option: first option"],
335 +["20:13:50 <x> #option list", "Available voting options are:\n0. first option"]
336 +]
337
338 diff --git a/bot/tests/test_scripts/agenda_option_listing.json b/bot/tests/test_scripts/agenda_option_listing.json
339 new file mode 100644
340 index 0000000..b7d261e
341 --- /dev/null
342 +++ b/bot/tests/test_scripts/agenda_option_listing.json
343 @@ -0,0 +1,7 @@
344 +[
345 +["20:13:50 <x> #option list", "Available voting options are:\n0. opt1\n1. opt2"],
346 +"20:13:50 <x> #nextitem",
347 +["20:13:50 <x> #option list", "No voting options available."],
348 +"20:13:50 <x> #previtem",
349 +["20:13:50 <x> #option list", "Available voting options are:\n0. opt1\n1. opt2"]
350 +]
351
352 diff --git a/bot/tests/test_scripts/agenda_option_removing.json b/bot/tests/test_scripts/agenda_option_removing.json
353 new file mode 100644
354 index 0000000..a7383bb
355 --- /dev/null
356 +++ b/bot/tests/test_scripts/agenda_option_removing.json
357 @@ -0,0 +1,5 @@
358 +[
359 +["20:13:50 <not_allowed> #option remove 1","You can not vote or change agenda. Only x, z can."],
360 +["20:13:50 <x> #option remove 1", "You removed voting option 1: opt2"],
361 +["20:13:50 <x> #option list", "Available voting options are:\n0. opt1"]
362 +]
363
364 diff --git a/bot/tests/test_scripts/agenda_voting.json b/bot/tests/test_scripts/agenda_voting.json
365 new file mode 100644
366 index 0000000..b1ee21c
367 --- /dev/null
368 +++ b/bot/tests/test_scripts/agenda_voting.json
369 @@ -0,0 +1,11 @@
370 +[
371 +["20:13:50 <x> #startvote", "Voting started\\. Available voting options are:\n0. opt1\n1. opt2\nVote #vote <option number>.\nEnd voting with #endvote."],
372 +["20:13:50 <x> #startvote", "Voting is already open. You can end it with #endvote."],
373 +["20:13:50 <x> #vote 10", "Your choice was out of range\\!"],
374 +["20:13:50 <x> #vote 0", "You voted for #0 - opt1"],
375 +["20:13:50 <x> #vote 1", "You voted for #1 - opt2"],
376 +["20:13:50 <z> #vote 0", "You voted for #0 - opt1"],
377 +["20:13:50 <x> #option list", "Available voting options are:\n0. opt1\n1. opt2\n"],
378 +["20:13:50 <x> #endvote", "Voting closed."],
379 +["20:13:50 <x> #endvote", "Voting is already closed. You can start it with #startvote."]
380 +]
381
382 diff --git a/bot/tests/test_scripts/all_commands.txt b/bot/tests/test_scripts/all_commands.txt
383 new file mode 100644
384 index 0000000..89a16c0
385 --- /dev/null
386 +++ b/bot/tests/test_scripts/all_commands.txt
387 @@ -0,0 +1,22 @@
388 +10:10:10 <x> #startmeeting
389 +10:10:10 <x> #topic h6k4orkac
390 +10:10:10 <x> #info blaoulrao
391 +10:10:10 <x> #idea alrkkcao4
392 +10:10:10 <x> #help ntoircoa5
393 +10:10:10 <x> #link http://bnatorkcao.net kroacaonteu
394 +10:10:10 <x> http://jrotjkor.net krotroun
395 +10:10:10 <x> #action xrceoukrc
396 +10:10:10 <x> #nick okbtrokr
397 +
398 +# Should not appear in non-log output
399 +10:10:10 <x> #idea ckmorkont
400 +10:10:10 <x> #undo
401 +
402 +# Assert that chairs can change the topic, and non-chairs can't.
403 +10:10:10 <x> #chair y
404 +10:10:10 <y> #topic topic_doeschange
405 +10:10:10 <z> #topic topic_doesntchange
406 +10:10:10 <x> #unchair y
407 +10:10:10 <y> #topic topic_doesnt2change
408 +
409 +10:10:10 <x> #endmeeting
410
411 diff --git a/bot/tests/test_scripts/close_voting_after_last_vote.json b/bot/tests/test_scripts/close_voting_after_last_vote.json
412 new file mode 100644
413 index 0000000..5c8e4ba
414 --- /dev/null
415 +++ b/bot/tests/test_scripts/close_voting_after_last_vote.json
416 @@ -0,0 +1,6 @@
417 +[
418 +["20:13:50 <x> #startvote", "Voting started\\. Available voting options are:\n0. opt1\n1. opt2\nVote #vote <option number>.\nEnd voting with #endvote."],
419 +["20:13:50 <x> #startvote", "Voting is already open. You can end it with #endvote."],
420 +["20:13:50 <x> #vote 0", "You voted for #0 - opt1"],
421 +["20:13:50 <z> #vote 0", "You voted for #0 - opt1. Voting closed."]
422 +]
423
424 diff --git a/bot/tests/test_scripts/urlMatching.txt b/bot/tests/test_scripts/urlMatching.txt
425 new file mode 100644
426 index 0000000..a33fa3f
427 --- /dev/null
428 +++ b/bot/tests/test_scripts/urlMatching.txt
429 @@ -0,0 +1,8 @@
430 +20:13:50 <x> #startmeeting
431 +20:13:50 <x> #link prefix http://site1.com suffix
432 +20:13:50 <x> http://site2.com suffix
433 +20:13:50 <x> ftp://ftpsite1.com suffix
434 +20:13:50 <x> #link prefix ftp://ftpsite2.com suffix
435 +20:13:50 <x> irc://ircsite1.com suffix
436 +20:13:50 <x> mailto://a@××××.com suffix
437 +20:13:50 <x> #endmeeting