Optionally let client_request test for redirect

A common pattern we employ is `POST`-redirect-`GET`. To write tests for
this we often check that the URL of the redirect is what we’re
expecting.

With the way `client_request` is currently set up, there’s no way to do
this because the response isn’t exposed to the test.

So this commit adds an extra parameter which will let us test for
redirects.
This commit is contained in:
Chris Hill-Scott
2017-09-26 14:04:51 +01:00
parent 4b96e7ba1b
commit 3906b31929

View File

@@ -1956,7 +1956,14 @@ def client_request(logged_in_client):
return page
@staticmethod
def post(endpoint, _data=None, _expected_status=None, _follow_redirects=False, **endpoint_kwargs):
def post(
endpoint,
_data=None,
_expected_status=None,
_follow_redirects=False,
_expected_redirect=None,
**endpoint_kwargs
):
if _expected_status is None:
_expected_status = 200 if _follow_redirects else 302
resp = logged_in_client.post(
@@ -1965,6 +1972,8 @@ def client_request(logged_in_client):
follow_redirects=_follow_redirects,
)
assert resp.status_code == _expected_status
if _expected_redirect:
assert resp.location == _expected_redirect
return BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
return ClientRequest