From 8761e47893b6f4fa06c9adbdbea22bb0a907f5fb Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Tue, 24 Oct 2017 11:14:09 +0200 Subject: [PATCH] zulip_bots: Store testing conversations in lists. This enforces the use of a list of tuples for conversations, as opposed to dicts. --- .../bots/converter/test_converter.py | 16 +++++----- .../zulip_bots/bots/encrypt/test_encrypt.py | 14 ++++---- .../zulip_bots/bots/followup/test_followup.py | 32 +++++++++---------- .../bots/helloworld/test_helloworld.py | 2 +- zulip_bots/zulip_bots/bots/help/test_help.py | 2 +- zulip_bots/zulip_bots/test_lib.py | 5 --- 6 files changed, 32 insertions(+), 39 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/converter/test_converter.py b/zulip_bots/zulip_bots/bots/converter/test_converter.py index 75b2f93..2302e1f 100755 --- a/zulip_bots/zulip_bots/bots/converter/test_converter.py +++ b/zulip_bots/zulip_bots/bots/converter/test_converter.py @@ -9,14 +9,14 @@ class TestConverterBot(BotTestCase): bot_name = "converter" def test_bot(self): - expected = { - "": ('Too few arguments given. Enter `@convert help` ' + expected = [ + ("", 'Too few arguments given. Enter `@convert help` ' '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'), - "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", - } + ("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) diff --git a/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py b/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py index 1cd2386..e03f0e3 100755 --- a/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py +++ b/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py @@ -9,11 +9,11 @@ class TestEncryptBot(BotTestCase): bot_name = "encrypt" def test_bot(self): - expected = { - "": "Encrypted/Decrypted text: ", - "Let\'s Do It": "Encrypted/Decrypted text: Yrg\'f Qb Vg", - "me&mom together..!!": "Encrypted/Decrypted text: zr&zbz gbtrgure..!!", - "foo bar": "Encrypted/Decrypted text: sbb one", - "Please encrypt this": "Encrypted/Decrypted text: Cyrnfr rapelcg guvf", - } + expected = [ + ("", "Encrypted/Decrypted text: "), + ("Let\'s Do It", "Encrypted/Decrypted text: Yrg\'f Qb Vg"), + ("me&mom together..!!", "Encrypted/Decrypted text: zr&zbz gbtrgure..!!"), + ("foo bar", "Encrypted/Decrypted text: sbb one"), + ("Please encrypt this", "Encrypted/Decrypted text: Cyrnfr rapelcg guvf"), + ] self.check_expected_responses(expected) diff --git a/zulip_bots/zulip_bots/bots/followup/test_followup.py b/zulip_bots/zulip_bots/bots/followup/test_followup.py index b28e159..f1e2216 100755 --- a/zulip_bots/zulip_bots/bots/followup/test_followup.py +++ b/zulip_bots/zulip_bots/bots/followup/test_followup.py @@ -9,23 +9,21 @@ class TestFollowUpBot(BotTestCase): bot_name = "followup" def test_bot(self): - expected_send_reply = { - "": 'Please specify the message you want to send to followup stream after @mention-bot' - } + expected_send_reply = [ + ("", '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') - expected_send_message = { - "foo": { - 'type': 'stream', - 'to': 'followup', - 'subject': 'foo_sender@zulip.com', - 'content': 'from foo_sender@zulip.com: foo', - }, - "I have completed my task": { - 'type': 'stream', - 'to': 'followup', - 'subject': 'foo_sender@zulip.com', - 'content': 'from foo_sender@zulip.com: I have completed my task', - }, - } + expected_send_message = [ + ("foo", + {'type': 'stream', + 'to': 'followup', + 'subject': 'foo_sender@zulip.com', + 'content': 'from foo_sender@zulip.com: foo'}), + ("I have completed my task", + {'type': 'stream', + 'to': 'followup', + 'subject': 'foo_sender@zulip.com', + 'content': 'from foo_sender@zulip.com: I have completed my task'}), + ] self.check_expected_responses(expected_send_message, expected_method='send_message') diff --git a/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py b/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py index d53f735..54ef547 100755 --- a/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py +++ b/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py @@ -13,4 +13,4 @@ class TestHelloWorldBot(BotTestCase): def test_bot(self): txt = "beep boop" 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]))) diff --git a/zulip_bots/zulip_bots/bots/help/test_help.py b/zulip_bots/zulip_bots/bots/help/test_help.py index 60c8ea3..ef737bc 100755 --- a/zulip_bots/zulip_bots/bots/help/test_help.py +++ b/zulip_bots/zulip_bots/bots/help/test_help.py @@ -13,4 +13,4 @@ class TestHelpBot(BotTestCase): def test_bot(self): txt = "Info on Zulip can be found here:\nhttps://github.com/zulip/zulip" 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]))) diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index 78e73c4..942d97e 100755 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -61,11 +61,6 @@ class BotTestCase(TestCase): # 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_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"]: logging.exception("check_expected_response expects type to be 'private', 'stream' or 'all'")