Files
ad/tests/api/static.py
T

36 lines
1.3 KiB
Python

# retoor <retoor@molodetz.nl>
import re
import pytest
PUBLIC_PAGES = ["/", "/roll", "/standard", "/flyers", "/memes", "/people", "/people/retoor", "/join", "/docs", "/docs/welcome", "/docs/api/content", "/docs/search?q=markdown", "/terms", "/privacy", "/auth/login"]
JSON_PAGES = ["/", "/roll", "/standard", "/flyers", "/memes", "/people", "/join"]
@pytest.mark.parametrize("path", PUBLIC_PAGES)
def test_public_pages_return_200(anon, path):
response = anon.get(path)
assert response.status_code == 200, path
assert "text/html" in response.headers["content-type"]
@pytest.mark.parametrize("path", JSON_PAGES)
def test_json_faces(anon, path):
response = anon.get(path, headers={"Accept": "application/json"})
assert response.status_code == 200
assert response.headers["content-type"].startswith("application/json")
assert isinstance(response.json(), dict)
def test_no_bare_static_urls_in_rendered_html(anon):
for path in ("/", "/flyers", "/memes", "/roll"):
html = anon.get(path).text
assert not re.search(r"""(src|href)="/static/(?!v|uploads/)""", html), path
def test_versioned_static_asset(anon):
html = anon.get("/").text
match = re.search(r'href="(/static/v[^"]+/css/base\.css)"', html)
assert match
assert anon.get(match.group(1)).status_code == 200