Fix intermittent test failure on query ordering

(I suspect that) because Python dictionaries are not ordered, you can’t
rely on the order of query parameters in a URL to match the arguments
passed to `url_for`. This means the tests can intermittently fail.

This does some hacky workaround stuff to still have reasonable test, but
one that will pass whatever the order of the query parameters is.
This commit is contained in:
Chris Hill-Scott
2017-02-02 15:31:03 +00:00
parent ef1bbb5692
commit 5fa115a8bd

View File

@@ -154,9 +154,9 @@ def test_passes_user_details_through_flow(
{'feedback': 'blah', 'name': 'Fred'},
{'feedback': 'blah'},
])
@pytest.mark.parametrize('ticket_type, expected_response, expected_redirect, expected_error', [
('problem', 200, no_redirect(), element.Tag),
('question', 302, partial(url_for, 'main.thanks', anonymous=True, urgent=True), type(None)),
@pytest.mark.parametrize('ticket_type, expected_response, things_expected_in_url, expected_error', [
('problem', 200, [], element.Tag),
('question', 302, ['thanks', 'anonymous=True', 'urgent=True'], type(None)),
])
def test_email_address_required_for_problems(
client,
@@ -164,7 +164,7 @@ def test_email_address_required_for_problems(
data,
ticket_type,
expected_response,
expected_redirect,
things_expected_in_url,
expected_error
):
mocker.patch(
@@ -176,7 +176,9 @@ def test_email_address_required_for_problems(
data=data,
)
assert response.status_code == expected_response
assert response.location == expected_redirect(_external=True)
# This is to work around non-deterministic query ordering in Flask url_for
for thing in things_expected_in_url:
assert thing in response.location
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert isinstance(page.find('span', {'class': 'error-message'}), expected_error)