import pytest from django.core.exceptions import ValidationError from apps.blog.models import ArticleIndexPage, ArticlePage from apps.blog.tests.factories import AuthorFactory from apps.comments.models import Comment def create_article(home): index = ArticleIndexPage(title="Articles", slug="articles") home.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() return article @pytest.mark.django_db def test_comment_defaults_and_absolute_url(home_page): article = create_article(home_page) comment = Comment.objects.create(article=article, author_name="N", author_email="n@example.com", body="hello") assert comment.is_approved is False assert comment.get_absolute_url().endswith(f"#comment-{comment.id}") @pytest.mark.django_db def test_reply_depth_validation(home_page): article = create_article(home_page) parent = Comment.objects.create(article=article, author_name="P", author_email="p@example.com", body="p") child = Comment.objects.create( article=article, author_name="C", author_email="c@example.com", body="c", parent=parent, ) nested = Comment(article=article, author_name="X", author_email="x@example.com", body="x", parent=child) with pytest.raises(ValidationError): nested.clean()