Skip to content

Commit

Permalink
Merge pull request #24 from sergeyKogan/master
Browse files Browse the repository at this point in the history
Added the ability to provide custom response reason
  • Loading branch information
fbouliane authored Jun 19, 2020
2 parents 900f5ab + d89d8c2 commit 9af761d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mockserver_friendly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, body=None, headers=None, cookies=None, delay=None, reason=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),
Expand Down
10 changes: 10 additions & 0 deletions test/test_basic_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 9af761d

Please sign in to comment.