From 1dbd6a122d2e34a12ca30a47d779b59eb51295dd Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 26 Jun 2017 21:14:49 +0100 Subject: [PATCH] Make client_request understand POST-redirect-GET MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8878371ca..324038f27 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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,