Corrective implementation of implementation.md (containerized Django/Wagtail) #3

Merged
mark merged 26 commits from codex_b/implementation-e2e into main 2026-02-28 17:55:14 +00:00
2 changed files with 59 additions and 0 deletions
Showing only changes of commit eb2cdfc5f2 - Show all commits

View File

@@ -21,3 +21,47 @@ def test_consent_post_view(client):
resp = client.post("/consent/", {"accept_all": "1"}, follow=False) resp = client.post("/consent/", {"accept_all": "1"}, follow=False)
assert resp.status_code == 302 assert resp.status_code == 302
assert CONSENT_COOKIE_NAME in resp.cookies assert CONSENT_COOKIE_NAME in resp.cookies
@pytest.mark.django_db
def test_consent_get_without_cookie_defaults_false():
request = HttpRequest()
state = ConsentService.get_consent(request)
assert state.analytics is False
assert state.advertising is False
assert state.requires_prompt is True
@pytest.mark.django_db
def test_consent_malformed_cookie_returns_safe_default():
request = HttpRequest()
request.COOKIES[CONSENT_COOKIE_NAME] = "not=a=valid%%%cookie"
state = ConsentService.get_consent(request)
assert state.analytics is False
assert state.advertising is False
@pytest.mark.django_db
def test_consent_post_preferences(client):
resp = client.post("/consent/", {"analytics": "1", "advertising": ""})
assert resp.status_code == 302
value = resp.cookies[CONSENT_COOKIE_NAME].value
assert "a=1" in value
assert "d=0" in value
@pytest.mark.django_db
def test_consent_get_method_not_allowed(client):
resp = client.get("/consent/")
assert resp.status_code == 405
@pytest.mark.django_db
def test_cookie_banner_hides_after_consent(client, home_page):
first = client.get("/")
assert "id=\"cookie-banner\"" in first.content.decode()
consented = client.post("/consent/", {"accept_all": "1"})
cookie_value = consented.cookies[CONSENT_COOKIE_NAME].value
client.cookies[CONSENT_COOKIE_NAME] = cookie_value
second = client.get("/")
assert "id=\"cookie-banner\"" not in second.content.decode()

View File

@@ -5,6 +5,21 @@
<button type="submit" name="accept_all" value="1">Accept all</button> <button type="submit" name="accept_all" value="1">Accept all</button>
<button type="submit" name="reject_all" value="1">Reject all</button> <button type="submit" name="reject_all" value="1">Reject all</button>
</form> </form>
<details>
<summary>Manage preferences</summary>
<form method="post" action="{% url 'consent' %}">
{% csrf_token %}
<label>
<input type="checkbox" name="analytics" value="1" />
Analytics cookies
</label>
<label>
<input type="checkbox" name="advertising" value="1" />
Advertising cookies
</label>
<button type="submit">Save preferences</button>
</form>
</details>
{% if site_settings and site_settings.privacy_policy_page %} {% if site_settings and site_settings.privacy_policy_page %}
<a href="{{ site_settings.privacy_policy_page.url }}">Privacy Policy</a> <a href="{{ site_settings.privacy_policy_page.url }}">Privacy Policy</a>
{% endif %} {% endif %}