diff options
Diffstat (limited to 'bot')
-rw-r--r-- | bot/ircmeeting/agenda.py | 10 | ||||
-rw-r--r-- | bot/tests/run_test.py | 11 |
2 files changed, 20 insertions, 1 deletions
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py index 928ff5f..775dfd9 100644 --- a/bot/ircmeeting/agenda.py +++ b/bot/ircmeeting/agenda.py @@ -79,6 +79,7 @@ class Agenda(object): self._voters = self._get_json(self.conf.voters_url) self._agenda = self._get_json(self.conf.agenda_url) self._votes = { } + self._voters.sort() for i in self._agenda: self._votes[i[0]] = { } @@ -93,7 +94,14 @@ class Agenda(object): return(opt) self._votes[self._agenda[self._current_item][0]][nick] = self._agenda[self._current_item][1][opt] - return str.format(self.vote_confirm_msg, opt, self._agenda[self._current_item][1][opt]) + + users_who_voted = self._votes[self._agenda[self._current_item][0]].keys() + users_who_voted.sort() + + reply = str.format(self.vote_confirm_msg, opt, self._agenda[self._current_item][1][opt]) + if users_who_voted == self._voters: + reply += '. ' + self.end_vote() + return(reply) def _get_json(self, url): str = urllib.urlopen(url).read() diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py index 9808ee6..3c43fef 100644 --- a/bot/tests/run_test.py +++ b/bot/tests/run_test.py @@ -406,6 +406,7 @@ class MeetBotTest(unittest.TestCase): def test_agenda_voting(self): test = self.get_simple_agenda_test() + test.M.config.agenda._voters.append('t') test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\ 'Available voting options are:\n0. opt1\n1. opt2\nVote ' +\ '#vote <option number>.\nEnd voting with #endvote.') @@ -427,6 +428,16 @@ class MeetBotTest(unittest.TestCase): assert(test.votes() == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}}) + def test_agenda_close_voting_after_last_vote(self): + test = self.get_simple_agenda_test() + test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\ + 'Available voting options 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 0', 'You voted for #0 - opt1') + test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1. Voting closed.') + if __name__ == '__main__': os.chdir(os.path.join(os.path.dirname(__file__), '.')) |