59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
import pytest
|
|
from django.core.management import call_command
|
|
from django.core.management.base import CommandError
|
|
|
|
from apps.blog.models import AboutPage, ArticleIndexPage, ArticlePage
|
|
from apps.blog.tests.factories import AuthorFactory
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_check_content_integrity_passes_when_requirements_met(home_page):
|
|
call_command("check_content_integrity")
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_check_content_integrity_fails_for_blank_summary(home_page):
|
|
index = ArticleIndexPage(title="Articles", slug="articles")
|
|
home_page.add_child(instance=index)
|
|
author = AuthorFactory()
|
|
article = ArticlePage(
|
|
title="Article",
|
|
slug="article",
|
|
author=author,
|
|
summary=" ",
|
|
body=[("rich_text", "<p>body</p>")],
|
|
)
|
|
index.add_child(instance=article)
|
|
article.save_revision().publish()
|
|
# Simulate legacy/bad data by bypassing model save() auto-summary fallback.
|
|
ArticlePage.objects.filter(pk=article.pk).update(summary=" ")
|
|
|
|
with pytest.raises(CommandError, match="empty summary"):
|
|
call_command("check_content_integrity")
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_seed_e2e_content_creates_expected_pages():
|
|
call_command("seed_e2e_content")
|
|
|
|
assert ArticlePage.objects.filter(slug="nightly-playwright-journey").exists()
|
|
assert ArticlePage.objects.filter(slug="e2e-tagged-article").exists()
|
|
assert ArticlePage.objects.filter(slug="e2e-no-comments").exists()
|
|
assert AboutPage.objects.filter(slug="about").exists()
|
|
|
|
# Tagged article must carry the seeded tag
|
|
tagged = ArticlePage.objects.get(slug="e2e-tagged-article")
|
|
assert tagged.tags.filter(slug="ai-tools").exists()
|
|
|
|
# No-comments article must have comments disabled
|
|
no_comments = ArticlePage.objects.get(slug="e2e-no-comments")
|
|
assert no_comments.comments_enabled is False
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_seed_e2e_content_is_idempotent():
|
|
"""Running the command twice must not raise or create duplicates."""
|
|
call_command("seed_e2e_content")
|
|
call_command("seed_e2e_content")
|
|
assert ArticlePage.objects.filter(slug="nightly-playwright-journey").count() == 1
|