41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from datetime import timedelta
|
|
|
|
import pytest
|
|
from django.core.management import call_command
|
|
from django.utils import timezone
|
|
|
|
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_purge_old_comment_data_clears_personal_fields(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="summary",
|
|
body=[("rich_text", "<p>body</p>")],
|
|
)
|
|
index.add_child(instance=article)
|
|
article.save_revision().publish()
|
|
|
|
old_comment = Comment.objects.create(
|
|
article=article,
|
|
author_name="Old",
|
|
author_email="old@example.com",
|
|
body="legacy",
|
|
ip_address="127.0.0.1",
|
|
)
|
|
Comment.objects.filter(pk=old_comment.pk).update(created_at=timezone.now() - timedelta(days=800))
|
|
|
|
call_command("purge_old_comment_data")
|
|
|
|
old_comment.refresh_from_db()
|
|
assert old_comment.author_email == ""
|
|
assert old_comment.ip_address is None
|