From 2bd81eaff1751e79996314a325e9250e9f354b6d Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Thu, 27 Jul 2017 17:45:56 -0700 Subject: [PATCH] bot testing: Allow check_expected_responses to take Sequence[Tuple]. Ordered data is required for logical testing of stateful bots, as compared to the previous use of a dict. --- zulip_bots/zulip_bots/test_lib.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index 648263b..dd43801 100755 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -56,12 +56,16 @@ class BotTestCase(TestCase): email="foo_sender@zulip.com", recipient="foo", subject="foo", sender_id=0, sender_full_name="Foo Bar", type="all", state_handler=None): - # type: (Dict[str, Any], str, str, str, str, int, str, str, Optional[StateHandler]) -> None + # type: (Union[Sequence[Tuple[str, Any]], Dict[str, Any]], str, str, str, str, int, str, str, Optional[StateHandler]) -> None # To test send_message, Any would be a Dict type, # to test send_reply, Any would be a str type. if type not in ["private", "stream", "all"]: logging.exception("check_expected_response expects type to be 'private', 'stream' or 'all'") - for m, r in expectations.items(): + if isinstance(expectations, dict): + expected = [(k, v) for k, v in expectations.items()] + else: + expected = expectations + for m, r in expected: # For calls with send_reply, r is a string (the content of a message), # so we need to add it to a Dict as the value of 'content'. # For calls with send_message, r is already a Dict.