zulip_bots: Store testing conversations in lists.
This enforces the use of a list of tuples for conversations, as opposed to dicts.
This commit is contained in:
parent
8179b30873
commit
8761e47893
|
@ -9,14 +9,14 @@ class TestConverterBot(BotTestCase):
|
||||||
bot_name = "converter"
|
bot_name = "converter"
|
||||||
|
|
||||||
def test_bot(self):
|
def test_bot(self):
|
||||||
expected = {
|
expected = [
|
||||||
"": ('Too few arguments given. Enter `@convert help` '
|
("", 'Too few arguments given. Enter `@convert help` '
|
||||||
'for help on using the converter.\n'),
|
'for help on using the converter.\n'),
|
||||||
"foo bar": ('Too few arguments given. Enter `@convert help` '
|
("foo bar", 'Too few arguments given. Enter `@convert help` '
|
||||||
'for help on using the converter.\n'),
|
'for help on using the converter.\n'),
|
||||||
"2 m cm": "2.0 m = 200.0 cm\n",
|
("2 m cm", "2.0 m = 200.0 cm\n"),
|
||||||
"12.0 celsius fahrenheit": "12.0 celsius = 53.600054 fahrenheit\n",
|
("12.0 celsius fahrenheit", "12.0 celsius = 53.600054 fahrenheit\n"),
|
||||||
"0.002 kilometer millimile": "0.002 kilometer = 1.2427424 millimile\n",
|
("0.002 kilometer millimile", "0.002 kilometer = 1.2427424 millimile\n"),
|
||||||
"3 megabyte kilobit": "3.0 megabyte = 24576.0 kilobit\n",
|
("3 megabyte kilobit", "3.0 megabyte = 24576.0 kilobit\n"),
|
||||||
}
|
]
|
||||||
self.check_expected_responses(expected)
|
self.check_expected_responses(expected)
|
||||||
|
|
|
@ -9,11 +9,11 @@ class TestEncryptBot(BotTestCase):
|
||||||
bot_name = "encrypt"
|
bot_name = "encrypt"
|
||||||
|
|
||||||
def test_bot(self):
|
def test_bot(self):
|
||||||
expected = {
|
expected = [
|
||||||
"": "Encrypted/Decrypted text: ",
|
("", "Encrypted/Decrypted text: "),
|
||||||
"Let\'s Do It": "Encrypted/Decrypted text: Yrg\'f Qb Vg",
|
("Let\'s Do It", "Encrypted/Decrypted text: Yrg\'f Qb Vg"),
|
||||||
"me&mom together..!!": "Encrypted/Decrypted text: zr&zbz gbtrgure..!!",
|
("me&mom together..!!", "Encrypted/Decrypted text: zr&zbz gbtrgure..!!"),
|
||||||
"foo bar": "Encrypted/Decrypted text: sbb one",
|
("foo bar", "Encrypted/Decrypted text: sbb one"),
|
||||||
"Please encrypt this": "Encrypted/Decrypted text: Cyrnfr rapelcg guvf",
|
("Please encrypt this", "Encrypted/Decrypted text: Cyrnfr rapelcg guvf"),
|
||||||
}
|
]
|
||||||
self.check_expected_responses(expected)
|
self.check_expected_responses(expected)
|
||||||
|
|
|
@ -9,23 +9,21 @@ class TestFollowUpBot(BotTestCase):
|
||||||
bot_name = "followup"
|
bot_name = "followup"
|
||||||
|
|
||||||
def test_bot(self):
|
def test_bot(self):
|
||||||
expected_send_reply = {
|
expected_send_reply = [
|
||||||
"": 'Please specify the message you want to send to followup stream after @mention-bot'
|
("", 'Please specify the message you want to send to followup stream after @mention-bot')
|
||||||
}
|
]
|
||||||
self.check_expected_responses(expected_send_reply, expected_method='send_reply')
|
self.check_expected_responses(expected_send_reply, expected_method='send_reply')
|
||||||
|
|
||||||
expected_send_message = {
|
expected_send_message = [
|
||||||
"foo": {
|
("foo",
|
||||||
'type': 'stream',
|
{'type': 'stream',
|
||||||
'to': 'followup',
|
'to': 'followup',
|
||||||
'subject': 'foo_sender@zulip.com',
|
'subject': 'foo_sender@zulip.com',
|
||||||
'content': 'from foo_sender@zulip.com: foo',
|
'content': 'from foo_sender@zulip.com: foo'}),
|
||||||
},
|
("I have completed my task",
|
||||||
"I have completed my task": {
|
{'type': 'stream',
|
||||||
'type': 'stream',
|
|
||||||
'to': 'followup',
|
'to': 'followup',
|
||||||
'subject': 'foo_sender@zulip.com',
|
'subject': 'foo_sender@zulip.com',
|
||||||
'content': 'from foo_sender@zulip.com: I have completed my task',
|
'content': 'from foo_sender@zulip.com: I have completed my task'}),
|
||||||
},
|
]
|
||||||
}
|
|
||||||
self.check_expected_responses(expected_send_message, expected_method='send_message')
|
self.check_expected_responses(expected_send_message, expected_method='send_message')
|
||||||
|
|
|
@ -13,4 +13,4 @@ class TestHelloWorldBot(BotTestCase):
|
||||||
def test_bot(self):
|
def test_bot(self):
|
||||||
txt = "beep boop"
|
txt = "beep boop"
|
||||||
messages = ["", "foo", "Hi, my name is abc"]
|
messages = ["", "foo", "Hi, my name is abc"]
|
||||||
self.check_expected_responses(dict(list(zip(messages, len(messages)*[txt]))))
|
self.check_expected_responses(list(zip(messages, len(messages)*[txt])))
|
||||||
|
|
|
@ -13,4 +13,4 @@ class TestHelpBot(BotTestCase):
|
||||||
def test_bot(self):
|
def test_bot(self):
|
||||||
txt = "Info on Zulip can be found here:\nhttps://github.com/zulip/zulip"
|
txt = "Info on Zulip can be found here:\nhttps://github.com/zulip/zulip"
|
||||||
messages = ["", "help", "Hi, my name is abc"]
|
messages = ["", "help", "Hi, my name is abc"]
|
||||||
self.check_expected_responses(dict(list(zip(messages, len(messages)*[txt]))))
|
self.check_expected_responses(list(zip(messages, len(messages)*[txt])))
|
||||||
|
|
|
@ -61,11 +61,6 @@ class BotTestCase(TestCase):
|
||||||
# type: (Union[Sequence[Tuple[str, Any]], Dict[str, Any]], str, str, str, str, int, str, str) -> None
|
# type: (Union[Sequence[Tuple[str, Any]], Dict[str, Any]], str, str, str, str, int, str, str) -> None
|
||||||
# To test send_message, Any would be a Dict type,
|
# To test send_message, Any would be a Dict type,
|
||||||
# to test send_reply, Any would be a str type.
|
# to test send_reply, Any would be a str type.
|
||||||
if isinstance(expectations, dict):
|
|
||||||
expected = [(k, v) for k, v in expectations.items()]
|
|
||||||
else:
|
|
||||||
expected = expectations
|
|
||||||
|
|
||||||
if type not in ["private", "stream", "all"]:
|
if type not in ["private", "stream", "all"]:
|
||||||
logging.exception("check_expected_response expects type to be 'private', 'stream' or 'all'")
|
logging.exception("check_expected_response expects type to be 'private', 'stream' or 'all'")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue