From e6cc3a1c588af4bb22c15322935bf1d7cdce3c39 Mon Sep 17 00:00:00 2001 From: SergeyKogan Date: Mon, 18 May 2020 09:41:14 +0300 Subject: [PATCH 1/2] Added the ability to provide custom response reason --- mockserver_friendly/__init__.py | 3 ++- test/test_basic_responses.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mockserver_friendly/__init__.py b/mockserver_friendly/__init__.py index 403470b..732ae43 100644 --- a/mockserver_friendly/__init__.py +++ b/mockserver_friendly/__init__.py @@ -51,9 +51,10 @@ def request(method=None, path=None, querystring=None, body=None, headers=None, c ) -def response(code=None, body=None, headers=None, cookies=None, delay=None): +def response(code=None, reason=None, body=None, headers=None, cookies=None, delay=None): return _non_null_options_to_dict( _Option("statusCode", code), + _Option("reasonPhrase", reason), _Option("body", body), _Option("headers", headers, formatter=_to_named_values_list), _Option("delay", delay, formatter=_to_delay), diff --git a/test/test_basic_responses.py b/test/test_basic_responses.py index 097675a..11cb947 100644 --- a/test/test_basic_responses.py +++ b/test/test_basic_responses.py @@ -15,6 +15,16 @@ def test_code_response(self): result = requests.get(MOCK_SERVER_URL) self.assertEqual(result.status_code, 418) + def test_reason_phrase_response(self): + reason_phrase = "Custom reasonPhrase" + self.client.stub( + request(), + response(reason=reason_phrase) + ) + + result = requests.get(MOCK_SERVER_URL) + self.assertEqual(result.reason, reason_phrase) + def test_body_response(self): self.client.stub( request(), From d89d8c2ff33f53852a3c45793b29f39563b3820c Mon Sep 17 00:00:00 2001 From: SergeyKogan Date: Wed, 20 May 2020 18:09:25 +0300 Subject: [PATCH 2/2] Moved the reason to the last parameter --- mockserver_friendly/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockserver_friendly/__init__.py b/mockserver_friendly/__init__.py index 732ae43..ed61a23 100644 --- a/mockserver_friendly/__init__.py +++ b/mockserver_friendly/__init__.py @@ -51,7 +51,7 @@ def request(method=None, path=None, querystring=None, body=None, headers=None, c ) -def response(code=None, reason=None, body=None, headers=None, cookies=None, delay=None): +def response(code=None, body=None, headers=None, cookies=None, delay=None, reason=None): return _non_null_options_to_dict( _Option("statusCode", code), _Option("reasonPhrase", reason),