public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/council-webapp:master commit in: bot/tests/, bot/tests/test_scripts/
@ 2011-08-03  9:57 Petteri Räty
  0 siblings, 0 replies; only message in thread
From: Petteri Räty @ 2011-08-03  9:57 UTC (permalink / raw
  To: gentoo-commits

commit:     0ffafa90d465fb5a45dd022530000cefc3840d74
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Mon Aug  1 22:30:21 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Aug  3 08:44:32 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=0ffafa90

Improve MeetBot tests

Keep long bot input and output sequences in separate files.

---
 bot/tests/run_test.py                              |  144 ++-----------------
 bot/tests/test_meeting.py                          |   30 ++++-
 bot/tests/test_scripts/actionNickMatching.txt      |    7 +
 bot/tests/test_scripts/agenda_item_changing.json   |   21 +++
 bot/tests/test_scripts/agenda_option_adding.json   |    6 +
 bot/tests/test_scripts/agenda_option_listing.json  |    7 +
 bot/tests/test_scripts/agenda_option_removing.json |    5 +
 bot/tests/test_scripts/agenda_voting.json          |   11 ++
 bot/tests/test_scripts/all_commands.txt            |   22 +++
 .../test_scripts/close_voting_after_last_vote.json |    6 +
 bot/tests/test_scripts/urlMatching.txt             |    8 +
 11 files changed, 137 insertions(+), 130 deletions(-)

diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py
index 3f84ccb..a6077cb 100644
--- a/bot/tests/run_test.py
+++ b/bot/tests/run_test.py
@@ -1,4 +1,5 @@
 # Richard Darst, 2009
+# Joachim Bartosik, 2011
 
 import glob
 import os
@@ -127,30 +128,8 @@ class MeetBotTest(unittest.TestCase):
     #   process_meeting(contents=file('test-script-3.log.txt').read(),
     #                   extraConfig={'writer_map':self.full_writer_map})
 
-    all_commands_test_contents = """
-    10:10:10 <x> #startmeeting
-    10:10:10 <x> #topic h6k4orkac
-    10:10:10 <x> #info blaoulrao
-    10:10:10 <x> #idea alrkkcao4
-    10:10:10 <x> #help ntoircoa5
-    10:10:10 <x> #link http://bnatorkcao.net kroacaonteu
-    10:10:10 <x> http://jrotjkor.net krotroun
-    10:10:10 <x> #action xrceoukrc
-    10:10:10 <x> #nick okbtrokr
-
-    # Should not appear in non-log output
-    10:10:10 <x> #idea ckmorkont
-    10:10:10 <x> #undo
-
-    # Assert that chairs can change the topic, and non-chairs can't.
-    10:10:10 <x> #chair y
-    10:10:10 <y> #topic topic_doeschange
-    10:10:10 <z> #topic topic_doesntchange
-    10:10:10 <x> #unchair y
-    10:10:10 <y> #topic topic_doesnt2change
+    all_commands_test_contents = test_meeting.get_test_script('all_commands.txt')
 
-    10:10:10 <x> #endmeeting
-    """
     def test_contents_test2(self):
         """Ensure that certain input lines do appear in the output.
 
@@ -212,15 +191,9 @@ class MeetBotTest(unittest.TestCase):
         the nick 'jon' will no longer be assigned lines containing
         'jonathan'.
         """
-        script = """
-        20:13:50 <x> #startmeeting
-        20:13:50 <somenick>
-        20:13:50 <someone> #action say somenickLONG
-        20:13:50 <someone> #action say the somenicklong
-        20:13:50 <somenick> I should not have an item assisgned to me.
-        20:13:50 <somenicklong> I should have some things assigned to me.
-        20:13:50 <x> #endmeeting
-        """
+
+        script = open('test_scripts/actionNickMatching.txt').read()
+
         M = process_meeting(script)
         results = M.save()['.html']
         # This regular expression is:
@@ -234,16 +207,8 @@ class MeetBotTest(unittest.TestCase):
     def test_urlMatching(self):
         """Test properly detection of URLs in lines
         """
-        script = """
-        20:13:50 <x> #startmeeting
-        20:13:50 <x> #link prefix http://site1.com suffix
-        20:13:50 <x> http://site2.com suffix
-        20:13:50 <x> ftp://ftpsite1.com suffix
-        20:13:50 <x> #link prefix ftp://ftpsite2.com suffix
-        20:13:50 <x> irc://ircsite1.com suffix
-        20:13:50 <x> mailto://a@mail.com suffix
-        20:13:50 <x> #endmeeting
-        """
+        script =  open('test_scripts/urlMatching.txt').read()
+
         M = process_meeting(script)
         results = M.save()['.html']
         assert re.search(r'prefix.*href.*http://site1.com.*suffix',
@@ -358,100 +323,23 @@ class MeetBotTest(unittest.TestCase):
 
         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 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')
-        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> #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> #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()
-
-        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_option_adding(self):
-        test = self.get_simple_agenda_test()
-        test.process('20:13:50 <x> #nextitem')
-        test.answer_should_match('20:13:50 <not_allowed> #option add first option',
-                                  'You can not vote or change agenda. Only x, z can.')
-        test.answer_should_match('20:13:50 <x> #option add first option',
-                                  'You added new voting option: first option')
-        test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
-                                  'are:\n0. first option')
-
-    def test_agenda_option_removing(self):
-        test = self.get_simple_agenda_test()
-        test.answer_should_match('20:13:50 <not_allowed> #option remove 1',
-                                  'You can not vote or change agenda. Only x, z can.')
-        test.answer_should_match('20:13:50 <x> #option remove 1',
-                                  'You removed voting option 1: opt2')
-        test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
-                                  'are:\n0. opt1')
+    def test_message_answer_tests(self):
+        files = ['agenda_item_changing', 'agenda_option_listing',
+                  'agenda_option_adding', 'agenda_option_removing',
+                  'close_voting_after_last_vote']
+        for file in files:
+            test = self.get_simple_agenda_test()
+            test.check_responses_from_json_file(file)
 
     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.')
-        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 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')
-        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.')
-
+        test.check_responses_from_json_file('agenda_voting')
         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': {}, 'third 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.')
 
     def test_agenda_time_limit_adding(self):
         test = self.get_simple_agenda_test()
@@ -533,6 +421,7 @@ class MeetBotTest(unittest.TestCase):
         error_msg = 'Received messages ' + str(test.log) + \
                     ' didn\'t match expected ' + str(expected_messages)
         assert messages_match, error_msg
+
     def test_command_help(self):
         test = self.get_simple_agenda_test()
         commands = ['startmeeting', 'startvote', 'vote', 'endvote',
@@ -556,4 +445,3 @@ if __name__ == '__main__':
                 MeetBotTest(methodName=testname).debug()
             else:
                 MeetBotTest(methodName='test_'+testname).debug()
-

diff --git a/bot/tests/test_meeting.py b/bot/tests/test_meeting.py
index 238ba2f..218d7d1 100644
--- a/bot/tests/test_meeting.py
+++ b/bot/tests/test_meeting.py
@@ -1,5 +1,8 @@
 import ircmeeting.meeting as meeting
 import ircmeeting.writers as writers
+import inspect
+import json
+import os
 import re
 import time
 class TestMeeting:
@@ -50,14 +53,37 @@ class TestMeeting:
           line = m.group(3).strip()
           self.M.addline(nick, "ACTION "+line, time_=time_)
 
-  def answer_should_match(self, line, answer_regexp):
+  def check_responses_from_json_file(self, file):
+    json_file_name  = file + ".json"
+    json_string     = get_test_script(json_file_name)
+    json_data       = json.loads(json_string)
+    prefix          = "(in " + file + ")"
+    for line in json_data:
+      if line.__class__ in [str, unicode]:
+        self.process(line)
+      elif (line.__class__ in [list, tuple]) and (len(line) == 2):
+        self.answer_should_match(line[0], line[1], prefix)
+      else:
+        error_msg = "In file " + file + "Each item in test case must " +\
+                    "be string, unicode string, list of length 2. Item `" +\
+                    str(line) + "` doesn't fulfill those requirements."
+        raise AssertionError(error_msg)
+
+  def answer_should_match(self, line, answer_regexp, prefix = ''):
     self.log = []
     self.process(line)
     answer = '\n'.join(self.log)
-    error_msg = "Answer for:\n\t'" + line + "'\n was \n\t'" + answer +\
+    error_msg = prefix + "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)
+
+def get_test_script(test_script_file_name):
+    this_file_path    = inspect.getfile(inspect.currentframe())
+    this_dir_path     = os.path.dirname(this_file_path)
+    test_script_path  = os.path.join(this_dir_path, 'test_scripts', test_script_file_name)
+    test_script_file  = open(test_script_path)
+    return test_script_file.read()

diff --git a/bot/tests/test_scripts/actionNickMatching.txt b/bot/tests/test_scripts/actionNickMatching.txt
new file mode 100644
index 0000000..392a503
--- /dev/null
+++ b/bot/tests/test_scripts/actionNickMatching.txt
@@ -0,0 +1,7 @@
+20:13:50 <x> #startmeeting
+20:13:50 <somenick>
+20:13:50 <someone> #action say somenickLONG
+20:13:50 <someone> #action say the somenicklong
+20:13:50 <somenick> I should not have an item assisgned to me.
+20:13:50 <somenicklong> I should have some things assigned to me.
+20:13:50 <x> #endmeeting

diff --git a/bot/tests/test_scripts/agenda_item_changing.json b/bot/tests/test_scripts/agenda_item_changing.json
new file mode 100644
index 0000000..c78e9be
--- /dev/null
+++ b/bot/tests/test_scripts/agenda_item_changing.json
@@ -0,0 +1,21 @@
+[
+["20:13:50 <x> #nextitem", "Current agenda item is second item."],
+["20:13:50 <x> #nextitem", "Current agenda item is third item."],
+["20:13:50 <x> #nextitem", "Current agenda item is third item."],
+["20:13:50 <x> #previtem", "Current agenda item is second item."],
+["20:13:50 <x> #previtem", "Current agenda item is first item."],
+["20:13:50 <x> #previtem", "Current agenda item is first item."],
+["20:13:50 <x> #changeitem 2", "Current agenda item is third item."],
+["20:13:50 <x> #changeitem 1", "Current agenda item is second item."],
+["20:13:50 <x> #changeitem 0", "Current agenda item is first item."],
+["20:13:50 <x> #changeitem 10", "Your choice was out of range!"],
+["20:13:50 <x> #changeitem puppy", "Your choice was not recognized as a number. Please retry."],
+"20:13:50 <x> #startvote",
+["20:13:50 <x> #nextitem", "Voting is currently open so I didn't change item. Please #endvote first"],
+["20:13:50 <x> #previtem", "Voting is currently open so I didn't change item. Please #endvote first"],
+["20:13:50 <x> #changeitem 2", "Voting is currently open so I didn't change item. Please #endvote first"],
+"20:13:50 <x> #endvote",
+["20:13:50 <x> #nextitem", "Current agenda item is second item."],
+["20:13:50 <x> #previtem", "Current agenda item is first item."],
+["20:13:50 <x> #changeitem 2", "Current agenda item is third item."]
+]

diff --git a/bot/tests/test_scripts/agenda_option_adding.json b/bot/tests/test_scripts/agenda_option_adding.json
new file mode 100644
index 0000000..cb3c068
--- /dev/null
+++ b/bot/tests/test_scripts/agenda_option_adding.json
@@ -0,0 +1,6 @@
+[
+"20:13:50 <x> #nextitem",
+["20:13:50 <not_allowed> #option add first option", "You can not vote or change agenda. Only x, z can."],
+["20:13:50 <x> #option add first option", "You added new voting option: first option"],
+["20:13:50 <x> #option list", "Available voting options are:\n0. first option"]
+]

diff --git a/bot/tests/test_scripts/agenda_option_listing.json b/bot/tests/test_scripts/agenda_option_listing.json
new file mode 100644
index 0000000..b7d261e
--- /dev/null
+++ b/bot/tests/test_scripts/agenda_option_listing.json
@@ -0,0 +1,7 @@
+[
+["20:13:50 <x> #option list", "Available voting options are:\n0. opt1\n1. opt2"],
+"20:13:50 <x> #nextitem",
+["20:13:50 <x> #option list", "No voting options available."],
+"20:13:50 <x> #previtem",
+["20:13:50 <x> #option list", "Available voting options are:\n0. opt1\n1. opt2"]
+]

diff --git a/bot/tests/test_scripts/agenda_option_removing.json b/bot/tests/test_scripts/agenda_option_removing.json
new file mode 100644
index 0000000..a7383bb
--- /dev/null
+++ b/bot/tests/test_scripts/agenda_option_removing.json
@@ -0,0 +1,5 @@
+[
+["20:13:50 <not_allowed> #option remove 1","You can not vote or change agenda. Only x, z can."],
+["20:13:50 <x> #option remove 1", "You removed voting option 1: opt2"],
+["20:13:50 <x> #option list", "Available voting options are:\n0. opt1"]
+]

diff --git a/bot/tests/test_scripts/agenda_voting.json b/bot/tests/test_scripts/agenda_voting.json
new file mode 100644
index 0000000..b1ee21c
--- /dev/null
+++ b/bot/tests/test_scripts/agenda_voting.json
@@ -0,0 +1,11 @@
+[
+["20:13:50 <x> #startvote", "Voting started\\. Available voting options are:\n0. opt1\n1. opt2\nVote #vote <option number>.\nEnd voting with #endvote."],
+["20:13:50 <x> #startvote", "Voting is already open. You can end it with #endvote."],
+["20:13:50 <x> #vote 10", "Your choice was out of range\\!"],
+["20:13:50 <x> #vote 0", "You voted for #0 - opt1"],
+["20:13:50 <x> #vote 1", "You voted for #1 - opt2"],
+["20:13:50 <z> #vote 0", "You voted for #0 - opt1"],
+["20:13:50 <x> #option list", "Available voting options are:\n0. opt1\n1. opt2\n"],
+["20:13:50 <x> #endvote", "Voting closed."],
+["20:13:50 <x> #endvote", "Voting is already closed. You can start it with #startvote."]
+]

diff --git a/bot/tests/test_scripts/all_commands.txt b/bot/tests/test_scripts/all_commands.txt
new file mode 100644
index 0000000..89a16c0
--- /dev/null
+++ b/bot/tests/test_scripts/all_commands.txt
@@ -0,0 +1,22 @@
+10:10:10 <x> #startmeeting
+10:10:10 <x> #topic h6k4orkac
+10:10:10 <x> #info blaoulrao
+10:10:10 <x> #idea alrkkcao4
+10:10:10 <x> #help ntoircoa5
+10:10:10 <x> #link http://bnatorkcao.net kroacaonteu
+10:10:10 <x> http://jrotjkor.net krotroun
+10:10:10 <x> #action xrceoukrc
+10:10:10 <x> #nick okbtrokr
+
+# Should not appear in non-log output
+10:10:10 <x> #idea ckmorkont
+10:10:10 <x> #undo
+
+# Assert that chairs can change the topic, and non-chairs can't.
+10:10:10 <x> #chair y
+10:10:10 <y> #topic topic_doeschange
+10:10:10 <z> #topic topic_doesntchange
+10:10:10 <x> #unchair y
+10:10:10 <y> #topic topic_doesnt2change
+
+10:10:10 <x> #endmeeting

diff --git a/bot/tests/test_scripts/close_voting_after_last_vote.json b/bot/tests/test_scripts/close_voting_after_last_vote.json
new file mode 100644
index 0000000..5c8e4ba
--- /dev/null
+++ b/bot/tests/test_scripts/close_voting_after_last_vote.json
@@ -0,0 +1,6 @@
+[
+["20:13:50 <x> #startvote", "Voting started\\. Available voting options are:\n0. opt1\n1. opt2\nVote #vote <option number>.\nEnd voting with #endvote."],
+["20:13:50 <x> #startvote", "Voting is already open. You can end it with #endvote."],
+["20:13:50 <x> #vote 0", "You voted for #0 - opt1"],
+["20:13:50 <z> #vote 0", "You voted for #0 - opt1. Voting closed."]
+]

diff --git a/bot/tests/test_scripts/urlMatching.txt b/bot/tests/test_scripts/urlMatching.txt
new file mode 100644
index 0000000..a33fa3f
--- /dev/null
+++ b/bot/tests/test_scripts/urlMatching.txt
@@ -0,0 +1,8 @@
+20:13:50 <x> #startmeeting
+20:13:50 <x> #link prefix http://site1.com suffix
+20:13:50 <x> http://site2.com suffix
+20:13:50 <x> ftp://ftpsite1.com suffix
+20:13:50 <x> #link prefix ftp://ftpsite2.com suffix
+20:13:50 <x> irc://ircsite1.com suffix
+20:13:50 <x> mailto://a@mail.com suffix
+20:13:50 <x> #endmeeting



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-03  9:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-03  9:57 [gentoo-commits] proj/council-webapp:master commit in: bot/tests/, bot/tests/test_scripts/ Petteri Räty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox