From 9853d85fb70bb73a151978f80a308078e601d885 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Fri, 22 Dec 2017 21:15:06 -0800 Subject: [PATCH] bot testing: Improve checking of fixtures in mock_http_conversation. This ensures required fields are present in the fixture dict/json, improving testing & allowing file to pass mypy with strict-optional. --- zulip_bots/zulip_bots/request_test_lib.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/zulip_bots/zulip_bots/request_test_lib.py b/zulip_bots/zulip_bots/request_test_lib.py index 13ab7d5..42c99a3 100644 --- a/zulip_bots/zulip_bots/request_test_lib.py +++ b/zulip_bots/zulip_bots/request_test_lib.py @@ -43,9 +43,14 @@ def mock_http_conversation(http_data): mock_result.assert_called_with(http_request['api_url'], **args) - http_request = http_data.get('request') - http_response = http_data.get('response') - http_headers = http_data.get('response-headers') + try: + http_request = http_data['request'] + http_response = http_data['response'] + http_headers = http_data['response-headers'] + except KeyError: + print("ERROR: Failed to find 'request', 'response' or 'response-headers' fields in fixture") + raise + http_method = http_request.get('method', 'GET') if http_method == 'GET':