this tweaks the behavior of the title to always append ' - suffix' to any title (from the meta tag, or generated via request path), unless the page explicitly specifies an empty Title meta tag
119 lines
4.7 KiB
Python
119 lines
4.7 KiB
Python
"""Test page requests."""
|
|
import re
|
|
|
|
|
|
def test_page_that_exists(client):
|
|
"""Test that the app can serve a basic file at the index."""
|
|
response = client.get('/')
|
|
assert response.status_code == 200
|
|
assert b'<h1>test index</h1>' in response.data
|
|
|
|
|
|
def test_page_that_doesnt_exist(client):
|
|
"""Test that the app returns 404 for nonsense requests."""
|
|
response = client.get('/ohuesthaoeusth')
|
|
assert response.status_code == 404
|
|
|
|
|
|
def test_files_outside_pages_do_not_get_served(client):
|
|
"""Test that page pathing doesn't break out of the instance/pages/ dir."""
|
|
response = client.get('/../unreachable')
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_weird_paths_do_not_get_served(client):
|
|
"""Test that we clean up requests as desired."""
|
|
response = client.get('/../../')
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_page_with_title_metadata(client):
|
|
"""Test that a page with title metadata has its title written."""
|
|
response = client.get('/')
|
|
assert response.status_code == 200
|
|
assert b'<title>Index - incorporeal.org</title>' in response.data
|
|
|
|
|
|
def test_page_without_title_metadata(client):
|
|
"""Test that a page without title metadata gets the default title."""
|
|
response = client.get('/no-title')
|
|
assert response.status_code == 200
|
|
assert b'<title>/no-title - incorporeal.org</title>' in response.data
|
|
|
|
|
|
def test_page_in_subdir_without_title_metadata(client):
|
|
"""Test that the title-less page display is as expected."""
|
|
response = client.get('/subdir//page-no-title')
|
|
assert response.status_code == 200
|
|
assert b'<title>/subdir/page-no-title - incorporeal.org</title>' in response.data
|
|
|
|
|
|
def test_page_with_card_metadata(client):
|
|
"""Test that a page with opengraph metadata."""
|
|
response = client.get('/more-metadata')
|
|
assert response.status_code == 200
|
|
assert b'<meta property="og:title" content="title for the page - incorporeal.org">' in response.data
|
|
assert b'<meta property="og:description" content="description of this page made even longer">' in response.data
|
|
assert b'<meta property="og:image" content="http://buh.com/test.img">' in response.data
|
|
|
|
|
|
def test_page_with_card_title_even_when_no_metadata(client):
|
|
"""Test that a page without metadata still has a card with the derived title."""
|
|
response = client.get('/no-title')
|
|
assert response.status_code == 200
|
|
assert b'<meta property="og:title" content="/no-title - incorporeal.org">' in response.data
|
|
assert b'<meta property="og:description"' not in response.data
|
|
assert b'<meta property="og:image"' not in response.data
|
|
|
|
|
|
def test_page_with_forced_empty_title_just_shows_suffix(client):
|
|
"""Test that if a page specifies a blank Title meta tag explicitly, only the suffix is used in the title."""
|
|
response = client.get('/forced-no-title')
|
|
assert response.status_code == 200
|
|
assert b'<title>incorporeal.org</title>' in response.data
|
|
|
|
|
|
def test_page_has_modified_timestamp(client):
|
|
"""Test that pages have modified timestamps in them."""
|
|
response = client.get('/')
|
|
assert response.status_code == 200
|
|
assert re.search(r'Last modified: ....-..-.. ..:..:.. ...', response.data.decode()) is not None
|
|
|
|
|
|
def test_that_page_request_redirects_to_directory(client):
|
|
"""Test that a request to /foo reirects to /foo/, if foo is a directory.
|
|
|
|
This might be useful in cases where a formerly page-only page has been
|
|
converted to a directory with subpages.
|
|
"""
|
|
response = client.get('/subdir')
|
|
assert response.status_code == 301
|
|
|
|
|
|
def test_that_dir_request_does_not_redirect(client):
|
|
"""Test that a request to /foo/ serves the index page, if foo is a directory."""
|
|
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'
|