From 4301a8f3ac69f2f54916e73cc90fcf216a9a3746 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 12 May 2018 19:49:37 -0300 Subject: [PATCH] Case insensitive querystring comparison, fix Python 3.5 --- tests/test_html.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_html.py b/tests/test_html.py index 67696963..1b30fa95 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -99,8 +99,9 @@ def test_existing_filter_redirects(app_client): path = path_base + '?' + urllib.parse.urlencode(filter_args) response = app_client.get(path, allow_redirects=False, gather_request=False) assert response.status == 302 - assert response.headers['Location'].endswith( - '?name__contains=hello&age__gte=22&age__lt=30&name__contains=world' + assert_querystring_equal( + 'name__contains=hello&age__gte=22&age__lt=30&name__contains=world', + response.headers['Location'].split('?')[1], ) # Setting _filter_column_3 to empty string should remove *_3 entirely @@ -108,8 +109,9 @@ def test_existing_filter_redirects(app_client): path = path_base + '?' + urllib.parse.urlencode(filter_args) response = app_client.get(path, allow_redirects=False, gather_request=False) assert response.status == 302 - assert response.headers['Location'].endswith( - '?name__contains=hello&age__gte=22&name__contains=world' + assert_querystring_equal( + 'name__contains=hello&age__gte=22&name__contains=world', + response.headers['Location'].split('?')[1], ) # ?_filter_op=exact should be removed if unaccompanied by _fiter_column @@ -399,6 +401,10 @@ def test_table_metadata(app_client): assert_footer_links(soup) +def assert_querystring_equal(expected, actual): + assert sorted(expected.split('&')) == sorted(actual.split('&')) + + def assert_footer_links(soup): footer_links = soup.find('div', {'class': 'ft'}).findAll('a') assert 3 == len(footer_links)