Files
main-site/apps/blog/tests/factories.py
Mark 2c94040221
Some checks failed
CI / nightly-e2e (pull_request) Has been skipped
CI / deploy (pull_request) Has been skipped
CI / ci (pull_request) Failing after 9s
CI / pr-e2e (pull_request) Failing after 1m38s
feat: improve Wagtail admin editor experience for articles
- Add published_date field to ArticlePage with auto-populate from
  first_published_at on first publish, plus data migration backfill
- Surface go_live_at/expire_at scheduling fields in editor panels
- Reorganise ArticlePage editor with TabbedInterface (Content,
  Metadata, Publishing, SEO tabs)
- Add Articles PageListingViewSet to admin menu with custom columns
  (author, category, published date, status) and category/author filters
- Add Articles summary dashboard panel showing drafts, scheduled,
  and recently published articles
- Update all front-end queries and RSS feeds to use published_date
- Add 10 unit tests and 4 E2E tests for new admin features

Closes #39

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-03 14:07:27 +00:00

66 lines
1.8 KiB
Python

import factory
import wagtail_factories
from django.utils import timezone
from taggit.models import Tag
from wagtail.models import Page
from apps.authors.models import Author
from apps.blog.models import ArticleIndexPage, ArticlePage, HomePage, TagMetadata
from apps.legal.models import LegalIndexPage, LegalPage
class AuthorFactory(factory.django.DjangoModelFactory):
class Meta:
model = Author
name = factory.Sequence(lambda n: f"Author {n}")
slug = factory.Sequence(lambda n: f"author-{n}")
class HomePageFactory(wagtail_factories.PageFactory):
class Meta:
model = HomePage
class ArticleIndexPageFactory(wagtail_factories.PageFactory):
class Meta:
model = ArticleIndexPage
class ArticlePageFactory(wagtail_factories.PageFactory):
class Meta:
model = ArticlePage
title = factory.Sequence(lambda n: f"Article {n}")
slug = factory.Sequence(lambda n: f"article-{n}")
author = factory.SubFactory(AuthorFactory)
summary = "Summary"
body = [("rich_text", "<p>Hello world</p>")]
first_published_at = factory.LazyFunction(timezone.now)
published_date = factory.LazyFunction(timezone.now)
class LegalIndexPageFactory(wagtail_factories.PageFactory):
class Meta:
model = LegalIndexPage
class LegalPageFactory(wagtail_factories.PageFactory):
class Meta:
model = LegalPage
title = factory.Sequence(lambda n: f"Legal {n}")
slug = factory.Sequence(lambda n: f"legal-{n}")
body = "<p>Body</p>"
last_updated = factory.Faker("date_object")
def root_page():
return Page.get_first_root_node()
def create_tag_with_meta(name: str, colour: str = "neutral"):
tag, _ = Tag.objects.get_or_create(name=name, slug=name)
TagMetadata.objects.get_or_create(tag=tag, defaults={"colour": colour})
return tag