From 3906b31929273a55a3cc913ee4874f5be07c5981 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 26 Sep 2017 14:04:51 +0100 Subject: [PATCH] Optionally let client_request test for redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/conftest.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index c549519c6..e5ca3fdd5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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