Implement newsletter double opt-in email flow and CSP nonce headers
This commit is contained in:
@@ -12,6 +12,24 @@ def test_subscribe_ok(client):
|
||||
assert NewsletterSubscription.objects.filter(email="a@example.com").exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_subscribe_sends_confirmation_email(client, mailoutbox):
|
||||
resp = client.post("/newsletter/subscribe/", {"email": "new@example.com", "source": "nav"})
|
||||
assert resp.status_code == 200
|
||||
assert len(mailoutbox) == 1
|
||||
assert "Confirm your No Hype AI newsletter subscription" in mailoutbox[0].subject
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_duplicate_subscribe_returns_ok_without_extra_email(client, mailoutbox):
|
||||
client.post("/newsletter/subscribe/", {"email": "dupe@example.com", "source": "nav"})
|
||||
assert len(mailoutbox) == 1
|
||||
resp = client.post("/newsletter/subscribe/", {"email": "dupe@example.com", "source": "footer"})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == "ok"
|
||||
assert len(mailoutbox) == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_subscribe_invalid(client):
|
||||
resp = client.post("/newsletter/subscribe/", {"email": "bad"})
|
||||
|
||||
Reference in New Issue
Block a user