aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-14 16:21:31 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-14 18:45:39 +0200
commit9ccab32b9a8bd934555158115db64a25a266fb53 (patch)
tree08ebc18411d9203750dd88e141ccc5265f885fbd /bot
parentDisable agenda management by default (diff)
downloadcouncil-webapp-9ccab32b9a8bd934555158115db64a25a266fb53.tar.gz
council-webapp-9ccab32b9a8bd934555158115db64a25a266fb53.tar.bz2
council-webapp-9ccab32b9a8bd934555158115db64a25a266fb53.zip
Improve Supybot tests, fix bugs found in the process
Diffstat (limited to 'bot')
-rw-r--r--bot/ircmeeting/agenda.py12
-rw-r--r--bot/tests/run_test.py68
-rw-r--r--bot/tests/test_meeting.py16
3 files changed, 51 insertions, 45 deletions
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py
index 247907b..cfecc61 100644
--- a/bot/ircmeeting/agenda.py
+++ b/bot/ircmeeting/agenda.py
@@ -7,8 +7,8 @@ class Agenda(object):
empty_agenda_msg = "Agenda is empty so I can't help you manage meeting (and voting)."
current_item_msg = "Current agenda item is {}."
voting_already_open_msg = "Voting is already open. You can end it with #endvote."
- voting_open_msg = "Voting started. Your choices are: {} Vote #vote <option number>.\n End voting with #endvote."
- voting_close_msg = "Voting is closed."
+ voting_open_msg = "Voting started. Your choices are:{}Vote #vote <option number>.\nEnd voting with #endvote."
+ voting_close_msg = "Voting closed."
voting_already_closed_msg = "Voting is already closed. You can start it with #startvote."
voting_open_so_item_not_changed_msg = "Voting is currently open so I didn't change item. Please #endvote first"
can_not_vote_msg = "You can not vote. Only {} can vote"
@@ -38,7 +38,7 @@ class Agenda(object):
if not self.conf.manage_agenda:
return('')
if self._vote_open:
- return voting_open_so_item_not_changed_msg
+ return self.voting_open_so_item_not_changed_msg
else:
if (self._current_item + 1) < len(self._agenda):
self._current_item += 1
@@ -48,7 +48,7 @@ class Agenda(object):
if not self.conf.manage_agenda:
return('')
if self._vote_open:
- return voting_open_so_item_not_changed_msg
+ return self.voting_open_so_item_not_changed_msg
else:
if self._current_item > 0:
self._current_item -= 1
@@ -70,8 +70,8 @@ class Agenda(object):
return('')
if self._vote_open:
self._vote_open = False
- return self.voting_already_closed_msg
- return voting_close_msg
+ return self.voting_close_msg
+ return self.voting_already_closed_msg
def get_data(self):
if not self.conf.manage_agenda:
diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py
index f4e6e49..2b6c6f3 100644
--- a/bot/tests/run_test.py
+++ b/bot/tests/run_test.py
@@ -344,40 +344,44 @@ class MeetBotTest(unittest.TestCase):
"""
test = test_meeting.TestMeeting()
- test.M.config.manage_agenda = True
test.set_voters(['x', 'z'])
test.set_agenda([['first item', ['opt1', 'opt2']], ['second item', []]])
- test.process("""
- 20:13:50 <x> #startmeeting
- 20:13:50 <x> #nextitem
- 20:13:50 <x> #nextitem
- 20:13:50 <x> #previtem
- 20:13:50 <x> #previtem
- 20:13:50 <x> #startvote
- 20:13:50 <x> #vote 10
- 20:13:50 <x> #vote 1
- 20:13:50 <y> #vote 0
- 20:13:50 <z> #vote 0
- 20:13:50 <x> #endvote
- 20:13:50 <x> #endmeeting""")
-
-
- answers = ['Current agenda item is second item.',
- 'Current agenda item is second item.',
- 'Current agenda item is first item.',
- 'Current agenda item is first item.',
- 'Voting started. Your choices are: ',
- '0. first item',
- "1. ['opt1', 'opt2']",
- ' Vote #vote <option number>.',
- ' End voting with #endvote.',
- 'Your vote was out of range!',
- "You voted for #1 - ['opt1', 'opt2']",
- 'You can not vote. Only x, z can vote',
- 'You voted for #0 - first item']
-
- self.assert_(test.votes == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}})
- self.assert_(test.log[0:len(answers)] == answers)
+
+
+ # Test starting meeting. Enable agenda management after that
+ test.answer_should_match("20:13:50 <x> #startmeeting",
+ "Meeting started .*\nUseful Commands: #action #agreed #help #info #idea #link #topic.\n")
+ test.M.config.manage_agenda = True
+
+ # Test moving through items
+ test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
+ test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
+ test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
+ test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
+
+ # Test voting
+ test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\
+ 'Your choices are:\n0. opt1\n1. opt2\nVote ' +\
+ '#vote <option number>.\nEnd voting with #endvote.')
+ test.answer_should_match('20:13:50 <x> #startvote', 'Voting is already open. ' +\
+ 'You can end it with #endvote.')
+ test.answer_should_match('20:13:50 <x> #vote 10', 'Your vote was out of range\!')
+ test.answer_should_match('20:13:50 <x> #vote 1', 'You voted for #1 - opt2')
+ test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1')
+ test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1')
+ test.answer_should_match('20:13:50 <x> #nextitem', 'Voting is currently ' +\
+ 'open so I didn\'t change item. Please #endvote first')
+ test.answer_should_match('20:13:50 <x> #previtem', 'Voting is currently ' +\
+ 'open so I didn\'t change item. Please #endvote first')
+ test.answer_should_match('20:13:50 <x> #endvote', 'Voting closed.')
+ test.answer_should_match('20:13:50 <x> #endvote', 'Voting is already closed. ' +\
+ 'You can start it with #startvote.')
+
+ test.M.config.manage_agenda = False
+ test.answer_should_match('20:13:50 <x> #endmeeting', 'Meeting ended ' +\
+ '.*\nMinutes:.*\nMinutes \(text\):.*\nLog:.*')
+
+ assert(test.votes() == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}})
if __name__ == '__main__':
os.chdir(os.path.join(os.path.dirname(__file__), '.'))
diff --git a/bot/tests/test_meeting.py b/bot/tests/test_meeting.py
index 9315b63..78bd2dc 100644
--- a/bot/tests/test_meeting.py
+++ b/bot/tests/test_meeting.py
@@ -2,13 +2,6 @@ import ircmeeting.meeting as meeting
import ircmeeting.writers as writers
import re
import time
-def process_meeting(contents, extraConfig={}, dontSave=True,
- filename='/dev/null'):
- """Take a test script, return Meeting object of that meeting.
-
- To access the results (a dict keyed by extensions), use M.save(),
- with M being the return of this function.
- """
class TestMeeting:
logline_re = re.compile(r'\[?([0-9: ]*)\]? *<[@+]?([^>]+)> *(.*)')
loglineAction_re = re.compile(r'\[?([0-9: ]*)\]? *\* *([^ ]+) *(.*)')
@@ -57,5 +50,14 @@ class TestMeeting:
line = m.group(3).strip()
self.M.addline(nick, "ACTION "+line, time_=time_)
+ def answer_should_match(self, line, answer_regexp):
+ self.log = []
+ self.process(line)
+ answer = '\n'.join(self.log)
+ error_msg = "Answer for:\n\t'" + line + "'\n was \n\t'" + answer +\
+ "'\ndid not match regexp\n\t'" + answer_regexp + "'"
+ answer_matches = re.match(answer_regexp, answer)
+ assert answer_matches, error_msg
+
def votes(self):
return(self.M.config.agenda._votes)