aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-16 16:31:05 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-16 17:06:46 +0200
commit2460e74c1a09fe988017437bbebdc8c6e5e41694 (patch)
treee4fec12153bcfb0924fcf9f34a416a93446c1ae5 /bot
parentReminder plugin more testable + tests for it (diff)
downloadcouncil-webapp-2460e74c1a09fe988017437bbebdc8c6e5e41694.tar.gz
council-webapp-2460e74c1a09fe988017437bbebdc8c6e5e41694.tar.bz2
council-webapp-2460e74c1a09fe988017437bbebdc8c6e5e41694.zip
Add #option list command
Diffstat (limited to 'bot')
-rw-r--r--bot/ircmeeting/agenda.py18
-rw-r--r--bot/ircmeeting/meeting.py6
-rw-r--r--bot/tests/run_test.py55
3 files changed, 59 insertions, 20 deletions
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py
index cfecc61..32ddb9f 100644
--- a/bot/ircmeeting/agenda.py
+++ b/bot/ircmeeting/agenda.py
@@ -7,7 +7,7 @@ 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>.\nEnd voting with #endvote."
+ voting_open_msg = "Voting started. {}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"
@@ -60,10 +60,7 @@ class Agenda(object):
if self._vote_open:
return self.voting_already_open_msg
self._vote_open = True
- options = "\n"
- for i in range(len(self._agenda[self._current_item][1])):
- options += str.format("{}. {}\n", i, self._agenda[self._current_item][1][i])
- return str.format(self.voting_open_msg, options)
+ return str.format(self.voting_open_msg, self.options())
def end_vote(self):
if not self.conf.manage_agenda:
@@ -104,6 +101,17 @@ class Agenda(object):
result = json.loads(str)
return result
+ def options(self):
+ options_list = self._agenda[self._current_item][1]
+ n = len(options_list)
+ if n == 0:
+ return 'No voting options available.'
+ else:
+ options = "Available voting options are:\n"
+ for i in range(n):
+ options += str.format("{}. {}\n", i, options_list[i])
+ return options
+
def post_result(self):
if not self.conf.manage_agenda:
return('')
diff --git a/bot/ircmeeting/meeting.py b/bot/ircmeeting/meeting.py
index 26138a2..d8589c4 100644
--- a/bot/ircmeeting/meeting.py
+++ b/bot/ircmeeting/meeting.py
@@ -340,6 +340,12 @@ class MeetingCommands(object):
for messageline in self.config.agenda.vote(nick, line).split('\n'):
self.reply(messageline)
+ def do_option(self, nick, time_, line, **kwargs):
+ if re.match( ' *?list', line):
+ result = self.config.agenda.options()
+ for messageline in result.split('\n'):
+ self.reply(messageline)
+
def do_endmeeting(self, nick, time_, **kwargs):
"""End the meeting."""
if not self.isChair(nick): return
diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py
index 2b6c6f3..c28f1ae 100644
--- a/bot/tests/run_test.py
+++ b/bot/tests/run_test.py
@@ -339,40 +339,65 @@ class MeetBotTest(unittest.TestCase):
assert M.config.filename().endswith('somechannel-blah1234'),\
"Filename not as expected: "+M.config.filename()
- def test_agenda(self):
- """ Test agenda management
- """
-
+ 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.M.config.manage_agenda = False
-
- # 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
+ return(test)
+
+ def test_agenda_item_changing(self):
+ test = self.get_simple_agenda_test()
+
+ # 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> #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 changing item during vote
+ test.process('20:13:50 <x> #startvote')
+ 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 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.')
+
+ def test_agenda_option_listing(self):
+ test = self.get_simple_agenda_test()
+
+ test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
+ 'are:\n0. opt1\n1. opt2\n')
+ test.process('20:13:50 <x> #nextitem')
+ test.answer_should_match('20:13:50 <x> #option list', 'No voting options available.')
+ test.process('20:13:50 <x> #previtem')
+ test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
+ 'are:\n0. opt1\n1. opt2\n')
+
+ def test_agenda_voting(self):
+ test = self.get_simple_agenda_test()
test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\
- 'Your choices are:\n0. opt1\n1. opt2\nVote ' +\
+ '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 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> #vote 1', 'You voted for #1 - opt2')
+ test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1')
+ test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
+ 'are:\n0. opt1\n1. opt2\n')
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.')