From 5fa115a8bd0e39a9d8c52111d92d62b35ffaf1b4 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 2 Feb 2017 15:31:03 +0000 Subject: [PATCH] Fix intermittent test failure on query ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (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. --- tests/app/main/views/test_feedback.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/app/main/views/test_feedback.py b/tests/app/main/views/test_feedback.py index 60b496d55..56da05a83 100644 --- a/tests/app/main/views/test_feedback.py +++ b/tests/app/main/views/test_feedback.py @@ -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)