fix: resolve ruff/mypy lint errors and fix E2E test failures
- Use datetime.timedelta instead of timezone.timedelta (mypy) - Fix import ordering (ruff I001) - Fix admin sidebar E2E selector: use #wagtail-sidebar (Wagtail 7) - Set deterministic published_date on seeded E2E articles for stable ordering - Fix nightly test strict-mode violation: exact=True for Comments heading Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,8 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
import datetime
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
root = Page.get_first_root_node()
|
||||
|
||||
home = HomePage.objects.child_of(root).first()
|
||||
@@ -43,6 +45,9 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
# Primary article — comments enabled, used by nightly journey test
|
||||
# published_date is set explicitly to ensure deterministic ordering
|
||||
# (most recent first) so this article appears at the top of listings.
|
||||
now = timezone.now()
|
||||
article = ArticlePage.objects.child_of(article_index).filter(slug="nightly-playwright-journey").first()
|
||||
if article is None:
|
||||
article = ArticlePage(
|
||||
@@ -52,9 +57,12 @@ class Command(BaseCommand):
|
||||
summary="Seeded article for nightly browser journey.",
|
||||
body=[("rich_text", "<p>Seeded article body for nightly browser checks.</p>")],
|
||||
comments_enabled=True,
|
||||
published_date=now,
|
||||
)
|
||||
article_index.add_child(instance=article)
|
||||
article.save_revision().publish()
|
||||
# Ensure deterministic ordering — primary article always newest
|
||||
ArticlePage.objects.filter(pk=article.pk).update(published_date=now)
|
||||
|
||||
# Seed one approved top-level comment on the primary article for reply E2E tests
|
||||
if not Comment.objects.filter(article=article, author_name="E2E Approved Commenter").exists():
|
||||
@@ -78,9 +86,13 @@ class Command(BaseCommand):
|
||||
summary="An article with tags for E2E filter tests.",
|
||||
body=[("rich_text", "<p>This article is tagged with AI Tools.</p>")],
|
||||
comments_enabled=True,
|
||||
published_date=now - datetime.timedelta(hours=1),
|
||||
)
|
||||
article_index.add_child(instance=tagged_article)
|
||||
tagged_article.save_revision().publish()
|
||||
ArticlePage.objects.filter(pk=tagged_article.pk).update(
|
||||
published_date=now - datetime.timedelta(hours=1)
|
||||
)
|
||||
tagged_article.tags.add(tag)
|
||||
tagged_article.save()
|
||||
|
||||
@@ -94,6 +106,7 @@ class Command(BaseCommand):
|
||||
summary="An article with comments disabled.",
|
||||
body=[("rich_text", "<p>Comments are disabled on this one.</p>")],
|
||||
comments_enabled=False,
|
||||
published_date=now - datetime.timedelta(hours=2),
|
||||
)
|
||||
article_index.add_child(instance=no_comments_article)
|
||||
# Explicitly persist False after add_child (which internally calls save())
|
||||
@@ -101,6 +114,9 @@ class Command(BaseCommand):
|
||||
ArticlePage.objects.filter(pk=no_comments_article.pk).update(comments_enabled=False)
|
||||
no_comments_article.comments_enabled = False
|
||||
no_comments_article.save_revision().publish()
|
||||
ArticlePage.objects.filter(pk=no_comments_article.pk).update(
|
||||
published_date=now - datetime.timedelta(hours=2)
|
||||
)
|
||||
|
||||
# About page
|
||||
if not AboutPage.objects.child_of(home).filter(slug="about").exists():
|
||||
|
||||
Reference in New Issue
Block a user