mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-16 19:30:13 -04:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user