Mirror test layout, domcontentloaded waits, backup DB writes outside threads
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
@@ -0,0 +1 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
@@ -22,14 +22,3 @@ def test_admin_redirects_anonymous(anon):
|
||||
response = anon.get("/admin")
|
||||
assert response.status_code in (302, 303)
|
||||
assert "/auth/login" in response.headers["location"]
|
||||
|
||||
|
||||
def test_api_key_header(admin, anon):
|
||||
key = admin.get("/profile/api-key", headers={"Accept": "application/json"}).json()["api_key"]
|
||||
assert anon.get("/admin", headers={"X-API-KEY": key, "Accept": "application/json"}).status_code == 200
|
||||
assert anon.get("/admin", headers={"Authorization": f"Bearer {key}", "Accept": "application/json"}).status_code == 200
|
||||
|
||||
|
||||
def test_no_jwt_anywhere(admin):
|
||||
response = admin.get("/profile/api-key", headers={"Accept": "application/json"})
|
||||
assert response.json()["api_key"].count(".") == 0
|
||||
@@ -0,0 +1 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
@@ -17,7 +17,10 @@ def _call(client, item):
|
||||
@pytest.mark.parametrize("item", ENDPOINTS, ids=lambda item: f"{item['method']} {item['path']}")
|
||||
def test_documented_auth_matches_reality(item, anon, member, admin):
|
||||
anon_status = _call(anon, item).status_code
|
||||
member_status = _call(member, item).status_code
|
||||
member_response = _call(member, item)
|
||||
member_status = member_response.status_code
|
||||
if member_status == 403 and member_response.headers.get("content-type", "").startswith("application/json"):
|
||||
assert member_response.json().get("error", {}).get("code") != "terms_required"
|
||||
admin_status = _call(admin, item).status_code
|
||||
if item["auth"] == "public":
|
||||
assert anon_status not in (401, 403)
|
||||
@@ -0,0 +1,7 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
|
||||
def test_galleries_have_images(anon):
|
||||
for path, minimum in (("/flyers", 4), ("/memes", 10)):
|
||||
html = anon.get(path).text
|
||||
assert html.count("data-lightbox") >= minimum, path
|
||||
@@ -0,0 +1,5 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
|
||||
def test_health(anon):
|
||||
assert anon.get("/health").json()["status"] == "ok"
|
||||
@@ -0,0 +1,15 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
|
||||
def test_home_is_molodetz(anon):
|
||||
html = anon.get("/").text
|
||||
assert "Molodetz" in html
|
||||
for label in ("Rol", "Standaard", "Flyers", "Memes", "Mensen", "Binnen"):
|
||||
assert f">{label}</a>" in html
|
||||
assert "wa.me" not in html and "whatsapp" not in html.lower()
|
||||
|
||||
|
||||
def test_unknown_page_is_404(anon):
|
||||
response = anon.get("/bestaat-niet-xyz")
|
||||
assert response.status_code == 404
|
||||
assert anon.get("/bestaat-niet-xyz", headers={"Accept": "application/json"}).json()["error"]
|
||||
@@ -0,0 +1,8 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
|
||||
def test_mensen_lists_real_accounts_only(anon):
|
||||
people = anon.get("/mensen", headers={"Accept": "application/json"}).json()
|
||||
names = [person["username"] for person in people.get("people", [])]
|
||||
assert names[0] == "retoor"
|
||||
assert set(names) <= {"retoor", "lezer"}
|
||||
@@ -0,0 +1,9 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
|
||||
def test_post_page(anon):
|
||||
posts = anon.get("/rol", headers={"Accept": "application/json"}).json()["posts"]
|
||||
post = next(post for post in posts if post["title"] == "Geen cursus.")
|
||||
response = anon.get(f"/posts/{post['slug']}")
|
||||
assert response.status_code == 200
|
||||
assert "Placeholder" in response.text
|
||||
@@ -0,0 +1 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
@@ -0,0 +1,12 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
|
||||
def test_api_key_header(admin, anon):
|
||||
key = admin.get("/profile/api-key", headers={"Accept": "application/json"}).json()["api_key"]
|
||||
assert anon.get("/admin", headers={"X-API-KEY": key, "Accept": "application/json"}).status_code == 200
|
||||
assert anon.get("/admin", headers={"Authorization": f"Bearer {key}", "Accept": "application/json"}).status_code == 200
|
||||
|
||||
|
||||
def test_no_jwt_anywhere(admin):
|
||||
response = admin.get("/profile/api-key", headers={"Accept": "application/json"})
|
||||
assert response.json()["api_key"].count(".") == 0
|
||||
@@ -0,0 +1,11 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
|
||||
def test_seeded_posts_and_placeholders(anon):
|
||||
rol = anon.get("/rol", headers={"Accept": "application/json"}).json()["posts"]
|
||||
seeds = {"Een zes is geen ambitie.", "Af is een eigenschap.", "De assistent is geen senior.", "Geen cursus."}
|
||||
assert seeds <= {post["title"] for post in rol}
|
||||
assert all(post["is_placeholder"] for post in rol if post["title"] in seeds)
|
||||
standaard = anon.get("/standaard", headers={"Accept": "application/json"}).json()["posts"]
|
||||
keuzes = next(post for post in standaard if post["title"] == "Eenendertig keuzes. Jij hebt er nul.")
|
||||
assert keuzes["is_placeholder"] is False
|
||||
@@ -0,0 +1,10 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
from defusedxml import ElementTree
|
||||
|
||||
|
||||
def test_robots_and_sitemap(anon):
|
||||
assert "Sitemap:" in anon.get("/robots.txt").text
|
||||
sitemap = anon.get("/sitemap.xml")
|
||||
root = ElementTree.fromstring(sitemap.content)
|
||||
assert root.tag.endswith("urlset")
|
||||
assert len(list(root)) >= 5
|
||||
@@ -0,0 +1,35 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
PUBLIC_PAGES = ["/", "/rol", "/standaard", "/flyers", "/memes", "/mensen", "/mensen/retoor", "/binnen", "/docs", "/docs/welkom", "/docs/api/inhoud", "/docs/search?q=markdown", "/voorwaarden", "/privacy", "/auth/login"]
|
||||
JSON_PAGES = ["/", "/rol", "/standaard", "/flyers", "/memes", "/mensen", "/binnen"]
|
||||
|
||||
|
||||
@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", "/rol"):
|
||||
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
|
||||
@@ -1,93 +0,0 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
import re
|
||||
|
||||
import pytest
|
||||
from defusedxml import ElementTree
|
||||
|
||||
PUBLIC_PAGES = ["/", "/rol", "/standaard", "/flyers", "/memes", "/mensen", "/mensen/retoor", "/binnen", "/docs", "/docs/welkom", "/docs/api/inhoud", "/docs/search?q=markdown", "/voorwaarden", "/privacy", "/auth/login"]
|
||||
JSON_PAGES = ["/", "/rol", "/standaard", "/flyers", "/memes", "/mensen", "/binnen"]
|
||||
|
||||
|
||||
@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_home_is_molodetz(anon):
|
||||
html = anon.get("/").text
|
||||
assert "Molodetz" in html
|
||||
for label in ("Rol", "Standaard", "Flyers", "Memes", "Mensen", "Binnen"):
|
||||
assert f">{label}</a>" in html
|
||||
assert "wa.me" not in html and "whatsapp" not in html.lower()
|
||||
|
||||
|
||||
def test_no_bare_static_urls_in_rendered_html(anon):
|
||||
for path in ("/", "/flyers", "/memes", "/rol"):
|
||||
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
|
||||
|
||||
|
||||
def test_seeded_posts_and_placeholders(anon):
|
||||
rol = anon.get("/rol", headers={"Accept": "application/json"}).json()["posts"]
|
||||
seeds = {"Een zes is geen ambitie.", "Af is een eigenschap.", "De assistent is geen senior.", "Geen cursus."}
|
||||
assert seeds <= {post["title"] for post in rol}
|
||||
assert all(post["is_placeholder"] for post in rol if post["title"] in seeds)
|
||||
standaard = anon.get("/standaard", headers={"Accept": "application/json"}).json()["posts"]
|
||||
keuzes = next(post for post in standaard if post["title"] == "Eenendertig keuzes. Jij hebt er nul.")
|
||||
assert keuzes["is_placeholder"] is False
|
||||
|
||||
|
||||
def test_post_page(anon):
|
||||
posts = anon.get("/rol", headers={"Accept": "application/json"}).json()["posts"]
|
||||
post = next(post for post in posts if post["title"] == "Geen cursus.")
|
||||
response = anon.get(f"/posts/{post['slug']}")
|
||||
assert response.status_code == 200
|
||||
assert "Placeholder" in response.text
|
||||
|
||||
|
||||
def test_galleries_have_images(anon):
|
||||
for path, minimum in (("/flyers", 4), ("/memes", 10)):
|
||||
html = anon.get(path).text
|
||||
assert html.count("data-lightbox") >= minimum, path
|
||||
|
||||
|
||||
def test_mensen_lists_real_accounts_only(anon):
|
||||
people = anon.get("/mensen", headers={"Accept": "application/json"}).json()
|
||||
names = [person["username"] for person in people.get("people", [])]
|
||||
assert names[0] == "retoor"
|
||||
assert set(names) <= {"retoor", "lezer"}
|
||||
|
||||
|
||||
def test_unknown_page_is_404(anon):
|
||||
response = anon.get("/bestaat-niet-xyz")
|
||||
assert response.status_code == 404
|
||||
assert anon.get("/bestaat-niet-xyz", headers={"Accept": "application/json"}).json()["error"]
|
||||
|
||||
|
||||
def test_robots_and_sitemap(anon):
|
||||
assert "Sitemap:" in anon.get("/robots.txt").text
|
||||
sitemap = anon.get("/sitemap.xml")
|
||||
root = ElementTree.fromstring(sitemap.content)
|
||||
assert root.tag.endswith("urlset")
|
||||
assert len(list(root)) >= 5
|
||||
|
||||
|
||||
def test_health(anon):
|
||||
assert anon.get("/health").json()["status"] == "ok"
|
||||
Reference in New Issue
Block a user