contrib_bots: Add check_expected_responses() test helper and use it.

This further simplifies the logic for testing a contrib_bots bot to
require very little code per test in the common case.
This commit is contained in:
neiljp 2017-05-29 14:14:11 -07:00 committed by Tim Abbott
parent 536ab436ed
commit 1991e0128b
8 changed files with 63 additions and 97 deletions

View file

@ -16,24 +16,14 @@ class TestConverterBot(BotTestCase):
bot_name = "converter"
def test_bot(self):
self.assert_bot_output(
{'content': "2 m cm", 'type': "private", 'sender_email': "foo@gmail.com"},
"2.0 m = 200.0 cm\n"
)
self.assert_bot_output(
{'content': "12 celsius fahrenheit", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
"12.0 celsius = 53.600054 fahrenheit\n"
)
self.assert_bot_output(
{'content': "0.002 kilometer millimile", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
"0.002 kilometer = 1.2427424 millimile\n"
)
self.assert_bot_output(
{'content': "3 megabyte kilobit", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
"3.0 megabyte = 24576.0 kilobit\n"
)
self.assert_bot_output(
{'content': "foo bar", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
('Too few arguments given. Enter `@convert help` '
'for help on using the converter.\n')
)
expected = {
"": ('Too few arguments given. Enter `@convert help` '
'for help on using the converter.\n'),
"foo bar": ('Too few arguments given. Enter `@convert help` '
'for help on using the converter.\n'),
"2 m cm": "2.0 m = 200.0 cm\n",
"12.0 celsius fahrenheit": "12.0 celsius = 53.600054 fahrenheit\n",
"0.002 kilometer millimile": "0.002 kilometer = 1.2427424 millimile\n",
"3 megabyte kilobit": "3.0 megabyte = 24576.0 kilobit\n",
}
self.check_expected_responses(expected)