Make client_request understand POST-redirect-GET

When we do a `POST` we almost always do a redirect straight afterwards.
`client_request` understands this, and expects a `302` by default.

However, if the `_follow_redirects` flag is set the status code returned
is that of the subsequent request – normally a `GET`, itself returning
`200`. Therefore the default expected response code would need to be
overridden.

Overriding this repeatedly would get pretty boring. Better to do it once
inside the fixture.
This commit is contained in:
Chris Hill-Scott
2017-06-26 21:14:49 +01:00
parent 4b89ee5d1d
commit 1dbd6a122d

View File

@@ -1716,7 +1716,9 @@ def client_request(logged_in_client):
return BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
@staticmethod
def post(endpoint, _data=None, _expected_status=302, _follow_redirects=False, **endpoint_kwargs):
def post(endpoint, _data=None, _expected_status=None, _follow_redirects=False, **endpoint_kwargs):
if _expected_status is None:
_expected_status = 200 if _follow_redirects else 302
resp = logged_in_client.post(
url_for(endpoint, **(endpoint_kwargs or {})),
data=_data,