Fix broken ircsock tests
This commit is contained in:
parent
7085d526ca
commit
694c868a13
@ -82,19 +82,19 @@ class TestProcessNewcomers(unittest.TestCase):
|
|||||||
newbot.NewComer('Hermione', self.bot)
|
newbot.NewComer('Hermione', self.bot)
|
||||||
time.sleep(.15)
|
time.sleep(.15)
|
||||||
newbot.NewComer('Ron', self.bot)
|
newbot.NewComer('Ron', self.bot)
|
||||||
|
self.ircsock = newbot.fake_irc_start()
|
||||||
|
|
||||||
def test_check_new_newcomers(self):
|
def test_check_new_newcomers(self):
|
||||||
newbot.process_newcomers(self.bot, [i for i in self.bot.newcomers if i.around_for() > self.bot.wait_time], welcome=0)
|
newbot.process_newcomers(self.bot, [i for i in self.bot.newcomers if i.around_for() > self.bot.wait_time], ircsock=self.ircsock, welcome=0)
|
||||||
self.assertEqual(len(self.bot.newcomers), 1)
|
self.assertEqual(len(self.bot.newcomers), 1)
|
||||||
|
|
||||||
def test_check_new_known_nicks(self):
|
def test_check_new_known_nicks(self):
|
||||||
newbot.process_newcomers(self.bot, [i for i in self.bot.newcomers if i.around_for() > self.bot.wait_time], welcome=0)
|
newbot.process_newcomers(self.bot, [i for i in self.bot.newcomers if i.around_for() > self.bot.wait_time], ircsock=self.ircsock, welcome=0)
|
||||||
self.assertEqual(self.bot.known_nicks,[['Alice'],['Bob'],['Harry'],['Hermione']])
|
self.assertEqual(self.bot.known_nicks,[['Alice'],['Bob'],['Harry'],['Hermione']])
|
||||||
|
|
||||||
def test_welcome_nick(self):
|
def test_welcome_nick(self):
|
||||||
ircsock = newbot.fake_irc_start()
|
newbot.process_newcomers(bot=self.bot, newcomerlist=[i for i in self.bot.newcomers if i.around_for() > self.bot.wait_time], ircsock=self.ircsock, welcome=1)
|
||||||
newbot.process_newcomers(bot=self.bot, newcomerlist=[i for i in self.bot.newcomers if i.around_for() > self.bot.wait_time], ircsock=ircsock, welcome=1)
|
self.assertEqual(self.ircsock.sent_message, "PRIVMSG #openhatch-bots :Welcome Hermione! The channel is pretty quiet right now, so I though I'd say hello, and ping some people (like shauna) that you're here. If no one responds for a while, try emailing us at hello@openhatch.org or just try coming back later. FYI, you're now on my list of known nicknames, so I won't bother you again.\n")
|
||||||
self.assertEqual(newbot.ircsock.sent_message, "PRIVMSG #openhatch-bots :Welcome Hermione! The channel is pretty quiet right now, so I though I'd say hello, and ping some people (like shauna) that you're here. If no one responds for a while, try emailing us at hello@openhatch.org or just try coming back later. FYI, you're now on my list of known nicknames, so I won't bother you again.\n")
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
with open('test_nicks.csv', 'w') as csv_file:
|
with open('test_nicks.csv', 'w') as csv_file:
|
||||||
@ -115,58 +115,55 @@ class TestMessageResponse(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.bot = newbot.Bot('test_nicks.csv')
|
self.bot = newbot.Bot('test_nicks.csv')
|
||||||
newbot.NewComer('Chappe', self.bot)
|
newbot.NewComer('Chappe', self.bot)
|
||||||
|
self.ircsock = newbot.fake_irc_start()
|
||||||
|
|
||||||
def test_newcomer_speaking(self):
|
def test_newcomer_speaking(self):
|
||||||
newbot.message_response(self.bot,"~q@r.m.us PRIVMSG #openhatch-bots :hah","Chappe") # Standard message by newcomer
|
newbot.message_response(self.bot,"~q@r.m.us PRIVMSG #openhatch-bots :hah","Chappe", ircsock=self.ircsock) # Standard message by newcomer
|
||||||
nicklist = [i.nick for i in self.bot.newcomers] # Makes a list of newcomers nicks for easy asserting
|
nicklist = [i.nick for i in self.bot.newcomers] # Makes a list of newcomers nicks for easy asserting
|
||||||
self.assertEqual(nicklist, ['Chappe'])
|
self.assertEqual(nicklist, ['Chappe'])
|
||||||
|
|
||||||
def test_oldtimer_speaking(self):
|
def test_oldtimer_speaking(self):
|
||||||
newbot.message_response(self.bot,"~q@r.m.us PRIVMSG #openhatch-bots :hah","Alice") # Standard message by oldtimer
|
newbot.message_response(self.bot,"~q@r.m.us PRIVMSG #openhatch-bots :hah","Alice", ircsock=self.ircsock) # Standard message by oldtimer
|
||||||
nicklist = [i.nick for i in self.bot.newcomers] # Makes a list of newcomers nicks for easy asserting
|
nicklist = [i.nick for i in self.bot.newcomers] # Makes a list of newcomers nicks for easy asserting
|
||||||
self.assertEqual(nicklist, [])
|
self.assertEqual(nicklist, [])
|
||||||
|
|
||||||
def test_join(self):
|
def test_join(self):
|
||||||
newbot.message_response(self.bot,"JOIN #openhatch-bots right now!","Shauna") # Replace with actual ping message ALSO argh the channel variable might mess things up if folks change it, which they very well might :/ (Also true for tests below.) I think maybe use the format.() style that is used for wait_change etc
|
newbot.message_response(self.bot,"JOIN #openhatch-bots right now!","Shauna", ircsock=self.ircsock) # Replace with actual ping message ALSO argh the channel variable might mess things up if folks change it, which they very well might :/ (Also true for tests below.) I think maybe use the format.() style that is used for wait_change etc
|
||||||
self.assertEqual(self.bot.newcomers[1].nick,'Shauna')
|
self.assertEqual(self.bot.newcomers[1].nick,'Shauna')
|
||||||
|
|
||||||
def test_part(self):
|
def test_part(self):
|
||||||
newbot.message_response(self.bot,"JOIN #openhatch-bots right now!","Shauna") # Replace with actual ping message ALSO argh the channel variable might mess things up if folks change it, which they very well might :/ (Also true for tests below.)
|
newbot.message_response(self.bot,"JOIN #openhatch-bots right now!","Shauna", ircsock=self.ircsock) # Replace with actual ping message ALSO argh the channel variable might mess things up if folks change it, which they very well might :/ (Also true for tests below.)
|
||||||
self.assertEqual(len(self.bot.newcomers), 2)
|
self.assertEqual(len(self.bot.newcomers), 2)
|
||||||
newbot.message_response(self.bot,"PART #openhatch-bots","Shauna") # Replace with actual ping message ALSO argh the channel variable might mess things up :/
|
newbot.message_response(self.bot,"PART #openhatch-bots","Shauna", ircsock=self.ircsock) # Replace with actual ping message ALSO argh the channel variable might mess things up :/
|
||||||
self.assertEqual(len(self.bot.newcomers), 1)
|
self.assertEqual(len(self.bot.newcomers), 1)
|
||||||
|
|
||||||
def test_hello(self):
|
def test_hello(self):
|
||||||
newbot.fake_irc_start()
|
newbot.message_response(self.bot,"PRIVMSG sup WelcomeBot2","Shauna", ircsock=self.ircsock) # The botnick may also be changed. :(
|
||||||
newbot.message_response(self.bot,"PRIVMSG sup WelcomeBot2","Shauna") # The botnick may also be changed. :(
|
self.assertTrue(hasattr(self.ircsock, 'sent_message')) # Fails because sent_message is never actually created
|
||||||
self.assertTrue(hasattr(newbot.ircsock, 'sent_message')) # Fails because sent_message is never actually created
|
self.assertIn(self.ircsock.sent_message, ["PRIVMSG #openhatch-bots :hello Shauna\n", "PRIVMSG #openhatch-bots :hi Shauna\n", "PRIVMSG #openhatch-bots :hey Shauna\n", "PRIVMSG #openhatch-bots :yo Shauna\n", "PRIVMSG #openhatch-bots :sup Shauna\n"])
|
||||||
self.assertIn(newbot.ircsock.sent_message, ["PRIVMSG #openhatch-bots :hello Shauna\n", "PRIVMSG #openhatch-bots :hi Shauna\n", "PRIVMSG #openhatch-bots :hey Shauna\n", "PRIVMSG #openhatch-bots :yo Shauna\n", "PRIVMSG #openhatch-bots :sup Shauna\n"])
|
|
||||||
|
|
||||||
def test_help(self):
|
def test_help(self):
|
||||||
newbot.fake_irc_start()
|
newbot.message_response(self.bot,"PRIVMSG info WelcomeBot2","Shauna", ircsock=self.ircsock) # The botnick may also be changed. :(
|
||||||
newbot.message_response(self.bot,"PRIVMSG info WelcomeBot2","Shauna") # The botnick may also be changed. :(
|
self.assertTrue(hasattr(self.ircsock, 'sent_message')) # Fails because sent_message is never actually created
|
||||||
self.assertTrue(hasattr(newbot.ircsock, 'sent_message')) # Fails because sent_message is never actually created
|
self.assertEqual(self.ircsock.sent_message, "PRIVMSG #openhatch-bots :I'm a bot! I'm from here <https://github.com/shaunagm/oh-irc-bot>. You can change my behavior by submitting a pull request or by talking to shauna.\n")
|
||||||
self.assertEqual(newbot.ircsock.sent_message, "PRIVMSG #openhatch-bots :I'm a bot! I'm from here <https://github.com/shaunagm/oh-irc-bot>. You can change my behavior by submitting a pull request or by talking to shauna.\n")
|
|
||||||
|
|
||||||
def test_wait_time_from_admin(self):
|
def test_wait_time_from_admin(self):
|
||||||
newbot.fake_irc_start()
|
newbot.message_response(self.bot,"WelcomeBot2 --wait-time 40","shauna",ircsock=self.ircsock) # Channel-greeters may also be changed. :(
|
||||||
newbot.message_response(self.bot,"WelcomeBot2 --wait-time 40","shauna") # Channel-greeters may also be changed. :(
|
self.assertEqual(self.ircsock.sent_message, "PRIVMSG #openhatch-bots :shauna the wait time is changing to 40 seconds.\n")
|
||||||
self.assertEqual(newbot.ircsock.sent_message, "PRIVMSG #openhatch-bots :shauna the wait time is changing to 40 seconds.\n")
|
|
||||||
|
|
||||||
def test_wait_time_from_non_admin(self):
|
def test_wait_time_from_non_admin(self):
|
||||||
newbot.fake_irc_start()
|
newbot.message_response(self.bot,"WelcomeBot2 --wait-time 40","Impostor",ircsock=self.ircsock) # Channel-greeters may also be changed. :(
|
||||||
newbot.message_response(self.bot,"WelcomeBot2 --wait-time 40","Impostor") # Channel-greeters may also be changed. :(
|
self.assertEqual(self.ircsock.sent_message, "PRIVMSG #openhatch-bots :Impostor you are not authorized to make that change. Please contact one of the channel greeters, like shauna, for assistance.\n")
|
||||||
self.assertEqual(newbot.ircsock.sent_message, "PRIVMSG #openhatch-bots :Impostor you are not authorized to make that change. Please contact one of the channel greeters, like shauna, for assistance.\n")
|
|
||||||
|
|
||||||
def test_pong(self):
|
def test_pong(self):
|
||||||
newbot.fake_irc_start()
|
newbot.fake_irc_start()
|
||||||
newbot.message_response(self.bot,"PING :","Shauna") # Replace this with actual ping message
|
newbot.message_response(self.bot,"PING :","Shauna",ircsock=self.ircsock) # Replace this with actual ping message
|
||||||
self.assertEqual(newbot.ircsock.sent_message,"PONG :pingis\n")
|
self.assertEqual(self.ircsock.sent_message,"PONG :pingis\n")
|
||||||
|
|
||||||
def test_bad_pong(self):
|
def test_bad_pong(self):
|
||||||
newbot.fake_irc_start()
|
newbot.fake_irc_start()
|
||||||
newbot.message_response(self.bot,"PING!!! :","Shauna") # Replace this with actual ping message
|
newbot.message_response(self.bot,"PING!!! :","Shauna",ircsock=self.ircsock) # Replace this with actual ping message
|
||||||
self.assertFalse(hasattr(newbot.ircsock, 'sent_message')) # Fails because sent_message is never actually created
|
self.assertFalse(hasattr(self.ircsock, 'sent_message')) # Fails because sent_message is never actually created
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
with open('test_nicks.csv', 'w') as csv_file:
|
with open('test_nicks.csv', 'w') as csv_file:
|
||||||
|
Loading…
Reference in New Issue
Block a user