Fix Wagtail article publish regressions
All checks were successful
CI / nightly-e2e (pull_request) Has been skipped
CI / deploy (pull_request) Has been skipped
CI / ci (pull_request) Successful in 1m17s
CI / pr-e2e (pull_request) Successful in 1m46s

This commit is contained in:
2026-03-15 16:53:49 +00:00
parent 15ef35e249
commit 1a0617fbd0
8 changed files with 161 additions and 34 deletions

View File

@@ -1,3 +1,5 @@
from unittest.mock import patch
import pytest
from django.core.cache import cache
from django.test import override_settings
@@ -28,10 +30,64 @@ def test_comment_post_flow(client, home_page):
},
)
assert resp.status_code == 302
assert resp["Location"].endswith("?commented=1")
assert resp["Location"].endswith("?commented=pending")
assert Comment.objects.count() == 1
@pytest.mark.django_db
def test_comment_post_redirect_banner_renders_on_article_page(client, home_page):
cache.clear()
index = ArticleIndexPage(title="Articles", slug="articles")
home_page.add_child(instance=index)
author = AuthorFactory()
article = ArticlePage(title="A", slug="a", author=author, summary="s", body=[("rich_text", "<p>body</p>")])
index.add_child(instance=article)
article.save_revision().publish()
resp = client.post(
"/comments/post/",
{
"article_id": article.id,
"author_name": "Test",
"author_email": "test@example.com",
"body": "Hello",
"honeypot": "",
},
follow=True,
)
assert resp.status_code == 200
assert b"Your comment has been posted and is awaiting moderation." in resp.content
@pytest.mark.django_db
@override_settings(TURNSTILE_SECRET_KEY="test-secret")
def test_comment_post_redirect_banner_renders_approved_state(client, home_page):
cache.clear()
index = ArticleIndexPage(title="Articles", slug="articles")
home_page.add_child(instance=index)
author = AuthorFactory()
article = ArticlePage(title="A", slug="a", author=author, summary="s", body=[("rich_text", "<p>body</p>")])
index.add_child(instance=article)
article.save_revision().publish()
with patch("apps.comments.views._verify_turnstile", return_value=True):
resp = client.post(
"/comments/post/",
{
"article_id": article.id,
"author_name": "Test",
"author_email": "test@example.com",
"body": "Hello",
"honeypot": "",
"cf-turnstile-response": "tok",
},
follow=True,
)
assert resp.status_code == 200
assert b"Comment posted!" in resp.content
@pytest.mark.django_db
def test_comment_post_rejected_when_comments_disabled(client, home_page):
cache.clear()