fix: nav/footer wireframe, honeypot CSP, explore topics, comment E2E coverage
- Replace nav inline newsletter form with Subscribe CTA link per wireframe - Remove newsletter form from footer; add Connect section with social/RSS links - Fix honeypot inputs using hidden attribute (inline style blocked by CSP) - Add available_tags to HomePage.get_context for Explore Topics section - Add data-comment-form attribute to main comment form for reliable locating - Seed approved comment in E2E content for reply flow testing - Expand test_comments.py: moderation message, not-immediately-visible, missing fields, reply form visible, reply submission - Make COMMENT_RATE_LIMIT_PER_MINUTE configurable; set 100 in dev to prevent E2E test exhaustion; update rate limit unit test with override_settings - Update newsletter/home E2E tests to reflect nav form removal - Update unit test to assert no nav/footer newsletter forms Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -42,6 +42,11 @@ class HomePage(Page):
|
||||
ctx["featured_article"] = self.featured_article
|
||||
ctx["latest_articles"] = articles
|
||||
ctx["more_articles"] = articles[:3]
|
||||
ctx["available_tags"] = (
|
||||
Tag.objects.filter(
|
||||
id__in=ArticlePage.objects.live().public().values_list("tags__id", flat=True)
|
||||
).distinct().order_by("name")
|
||||
)
|
||||
return ctx
|
||||
|
||||
|
||||
|
||||
@@ -69,8 +69,12 @@ def test_newsletter_forms_render_in_nav_and_footer(client, home_page):
|
||||
resp = client.get("/")
|
||||
html = resp.content.decode()
|
||||
assert resp.status_code == 200
|
||||
assert 'name="source" value="nav"' in html
|
||||
assert 'name="source" value="footer"' in html
|
||||
# Nav has a Subscribe CTA link (no inline form — wireframe spec)
|
||||
assert 'href="#newsletter"' in html
|
||||
# Footer has Connect section with social/RSS links (no newsletter form)
|
||||
assert "Connect" in html
|
||||
assert 'name="source" value="nav"' not in html
|
||||
assert 'name="source" value="footer"' not in html
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
from django.core.cache import cache
|
||||
from django.test import override_settings
|
||||
|
||||
from apps.comments.forms import CommentForm
|
||||
|
||||
@@ -11,6 +12,7 @@ def test_comment_form_rejects_blank_body():
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@override_settings(COMMENT_RATE_LIMIT_PER_MINUTE=3)
|
||||
def test_comment_rate_limit(client, article_page):
|
||||
cache.clear()
|
||||
payload = {
|
||||
|
||||
@@ -33,7 +33,8 @@ class CommentCreateView(View):
|
||||
ip = client_ip_from_request(request)
|
||||
key = f"comment-rate:{ip}"
|
||||
count = cache.get(key, 0)
|
||||
if count >= 3:
|
||||
rate_limit = getattr(settings, "COMMENT_RATE_LIMIT_PER_MINUTE", 3)
|
||||
if count >= rate_limit:
|
||||
return HttpResponse(status=429)
|
||||
cache.set(key, count + 1, timeout=60)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from wagtail.models import Page, Site
|
||||
|
||||
from apps.authors.models import Author
|
||||
from apps.blog.models import AboutPage, ArticleIndexPage, ArticlePage, HomePage, TagMetadata
|
||||
from apps.comments.models import Comment
|
||||
from apps.legal.models import LegalIndexPage, LegalPage
|
||||
|
||||
|
||||
@@ -51,7 +52,17 @@ class Command(BaseCommand):
|
||||
article_index.add_child(instance=article)
|
||||
article.save_revision().publish()
|
||||
|
||||
# Tagged article — used by tag-filter E2E tests
|
||||
# Seed one approved top-level comment on the primary article for reply E2E tests
|
||||
if not Comment.objects.filter(article=article, author_name="E2E Approved Commenter").exists():
|
||||
Comment.objects.create(
|
||||
article=article,
|
||||
author_name="E2E Approved Commenter",
|
||||
author_email="approved@example.com",
|
||||
body="This is a seeded approved comment for reply testing.",
|
||||
is_approved=True,
|
||||
)
|
||||
|
||||
|
||||
tag, _ = Tag.objects.get_or_create(name="AI Tools", slug="ai-tools")
|
||||
TagMetadata.objects.get_or_create(tag=tag, defaults={"colour": "cyan"})
|
||||
tagged_article = ArticlePage.objects.child_of(article_index).filter(slug="e2e-tagged-article").first()
|
||||
|
||||
Reference in New Issue
Block a user