From dcf173ab616928e6a90a110b30a4eb566e26d052 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Tue, 8 Dec 2020 17:12:35 -0600 Subject: [PATCH] add a test to ensure style selection works --- tests/functional_tests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/functional_tests.py b/tests/functional_tests.py index b8a26d0..c547cb7 100644 --- a/tests/functional_tests.py +++ b/tests/functional_tests.py @@ -52,3 +52,24 @@ def test_that_dir_request_does_not_redirect(client): response = client.get('/subdir/') assert response.status_code == 200 assert b'another page' in response.data + + +def test_setting_selected_style_includes_cookie(client): + """Test that a request with style=foo sets the cookie and renders appropriately.""" + response = client.get('/') + style_cookie = next((cookie for cookie in client.cookie_jar if cookie.name == 'user-style'), None) + assert style_cookie is None + + response = client.get('/?style=light') + style_cookie = next((cookie for cookie in client.cookie_jar if cookie.name == 'user-style'), None) + assert response.status_code == 200 + assert b'light.css' in response.data + assert b'dark.css' not in response.data + assert style_cookie.value == 'light' + + response = client.get('/?style=dark') + style_cookie = next((cookie for cookie in client.cookie_jar if cookie.name == 'user-style'), None) + assert response.status_code == 200 + assert b'dark.css' in response.data + assert b'light.css' not in response.data + assert style_cookie.value == 'dark'