import pytest from django.core.cache import cache from apps.blog.models import ArticleIndexPage, ArticlePage from apps.blog.tests.factories import AuthorFactory from apps.comments.models import Comment @pytest.mark.django_db def test_comment_post_flow(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", "
body
")]) 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": "", }, ) assert resp.status_code == 302 assert Comment.objects.count() == 1 @pytest.mark.django_db def test_comment_post_rejected_when_comments_disabled(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", "body
")], comments_enabled=False, ) 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": "", }, ) assert resp.status_code == 404 assert Comment.objects.count() == 0