diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-20 18:58:30 +0200 |
---|---|---|
committer | Petteri Räty <petsku@petteriraty.eu> | 2011-06-22 10:22:05 +0300 |
commit | bc787b2518ac4fedcffaaf24e14f04839c3d7d3a (patch) | |
tree | 71d1bd27d775c79ac18bbe2df7ef217d63bfe6b1 | |
parent | Close voting when last user allowed to vote voted. (diff) | |
download | council-webapp-bc787b2518ac4fedcffaaf24e14f04839c3d7d3a.tar.gz council-webapp-bc787b2518ac4fedcffaaf24e14f04839c3d7d3a.tar.bz2 council-webapp-bc787b2518ac4fedcffaaf24e14f04839c3d7d3a.zip |
Add #changeitem <no> command to MeetBot
-rw-r--r-- | bot/ircmeeting/agenda.py | 25 | ||||
-rw-r--r-- | bot/ircmeeting/meeting.py | 3 | ||||
-rw-r--r-- | bot/tests/run_test.py | 20 |
3 files changed, 38 insertions, 10 deletions
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py index 775dfd9..af03c3a 100644 --- a/bot/ircmeeting/agenda.py +++ b/bot/ircmeeting/agenda.py @@ -15,8 +15,8 @@ class Agenda(object): 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 or change agenda. Only {} can." - not_a_number_msg = "Your vote was not recognized as a number. Please retry." - out_of_range_msg = "Your vote was out of range!" + not_a_number_msg = "Your choice was not recognized as a number. Please retry." + out_of_range_msg = "Your choice was out of range!" vote_confirm_msg = "You voted for #{} - {}" # Internal @@ -109,14 +109,20 @@ class Agenda(object): result = json.loads(str) return result - def _to_voting_option_number(self, line): + def _to_number(self, line, upper_limit): if not line.isdigit(): return self.not_a_number_msg opt = int(line) - if opt < 0 or opt >= len(self._agenda[self._current_item][1]): + if opt < 0 or opt >= upper_limit: return self.out_of_range_msg return(opt) + def _to_voting_option_number(self, line): + return(self._to_number(line, len(self._agenda[self._current_item][1]))) + + def _to_agenda_item_number(self, line): + return(self._to_number(line, len(self._agenda))) + def options(self): options_list = self._agenda[self._current_item][1] n = len(options_list) @@ -138,6 +144,17 @@ class Agenda(object): options_list.append(option_text) return str.format(self.added_option_msg, option_text) + def change_agenda_item(self, line): + if not self.conf.manage_agenda: + return('') + if self._vote_open: + return self.voting_open_so_item_not_changed_msg + opt = self._to_agenda_item_number(line) + if opt.__class__ is not int: + return(opt) + self._current_item = opt + return(self.get_agenda_item()) + def remove_option(self, nick, line): if not self.conf.manage_agenda: return('') diff --git a/bot/ircmeeting/meeting.py b/bot/ircmeeting/meeting.py index 84949ed..c01176a 100644 --- a/bot/ircmeeting/meeting.py +++ b/bot/ircmeeting/meeting.py @@ -328,6 +328,9 @@ class MeetingCommands(object): def do_previtem(self, nick, time_, line, **kwargs): self.reply(self.config.agenda.prev_agenda_item()) + def do_changeitem(self, nick, time_, line, **kwargs): + self.reply(self.config.agenda.change_agenda_item(line)) + def do_startvote(self, nick, time_, line, **kwargs): for messageline in self.config.agenda.start_vote().split('\n'): self.reply(messageline) diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py index 3c43fef..1358d47 100644 --- a/bot/tests/run_test.py +++ b/bot/tests/run_test.py @@ -342,7 +342,7 @@ class MeetBotTest(unittest.TestCase): def get_simple_agenda_test(self): test = test_meeting.TestMeeting() test.set_voters(['x', 'z']) - test.set_agenda([['first item', ['opt1', 'opt2']], ['second item', []]]) + test.set_agenda([['first item', ['opt1', 'opt2']], ['second item', []], ['third item', []]]) test.M.config.manage_agenda = False test.answer_should_match("20:13:50 <x> #startmeeting", @@ -356,9 +356,16 @@ class MeetBotTest(unittest.TestCase): # Test changing item before vote 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> #nextitem', 'Current agenda item is third item.') + test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is third item.') + test.answer_should_match('20:13:50 <x> #previtem', '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.answer_should_match('20:13:50 <x> #changeitem 2', 'Current agenda item is third item.') + test.answer_should_match('20:13:50 <x> #changeitem 1', 'Current agenda item is second item.') + test.answer_should_match('20:13:50 <x> #changeitem 0', 'Current agenda item is first item.') + test.answer_should_match('20:13:50 <x> #changeitem 10', 'Your choice was out of range!') + test.answer_should_match('20:13:50 <x> #changeitem puppy', 'Your choice was not recognized as a number. Please retry.') # Test changing item during vote test.process('20:13:50 <x> #startvote') @@ -366,13 +373,14 @@ class MeetBotTest(unittest.TestCase): '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> #changeitem 2', 'Voting is currently ' +\ + 'open so I didn\'t change item. Please #endvote first') # Test changing item after vote test.process('20:13:50 <x> #endvote') 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.answer_should_match('20:13:50 <x> #changeitem 2', 'Current agenda item is third item.') def test_agenda_option_listing(self): test = self.get_simple_agenda_test() @@ -412,7 +420,7 @@ class MeetBotTest(unittest.TestCase): '#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 10', 'Your choice was out of range\!') test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1') test.answer_should_match('20:13:50 <x> #vote 1', 'You voted for #1 - opt2') test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1') @@ -426,7 +434,7 @@ class MeetBotTest(unittest.TestCase): 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': {}}) + assert(test.votes() == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}, 'third item': {}}) def test_agenda_close_voting_after_last_vote(self): test = self.get_simple_agenda_test() |