add a test to ensure style selection works

This commit is contained in:
Brian S. Stephan 2020-12-08 17:12:35 -06:00
parent d2c1c2e3ce
commit dcf173ab61
1 changed files with 21 additions and 0 deletions

View File

@ -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'