53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
import pytest
|
|
from wagtail.models import Page, Site
|
|
|
|
from apps.blog.models import ArticleIndexPage, ArticlePage, HomePage
|
|
from apps.blog.tests.factories import AuthorFactory
|
|
|
|
|
|
@pytest.fixture
|
|
def home_page(db):
|
|
root = Page.get_first_root_node()
|
|
home = HomePage(title="Home", slug=f"home-{HomePage.objects.count() + 1}")
|
|
root.add_child(instance=home)
|
|
home.save_revision().publish()
|
|
site = Site.objects.filter(is_default_site=True).first()
|
|
if site:
|
|
site.root_page = home
|
|
site.hostname = "localhost"
|
|
site.port = 80
|
|
site.site_name = "No Hype AI"
|
|
site.save()
|
|
else:
|
|
Site.objects.create(
|
|
hostname="localhost",
|
|
root_page=home,
|
|
is_default_site=True,
|
|
site_name="No Hype AI",
|
|
port=80,
|
|
)
|
|
return home
|
|
|
|
|
|
@pytest.fixture
|
|
def article_index(home_page):
|
|
index = ArticleIndexPage(title="Articles", slug=f"articles-{ArticleIndexPage.objects.count() + 1}")
|
|
home_page.add_child(instance=index)
|
|
index.save_revision().publish()
|
|
return index
|
|
|
|
|
|
@pytest.fixture
|
|
def article_page(article_index):
|
|
author = AuthorFactory()
|
|
article = ArticlePage(
|
|
title=f"Article {ArticlePage.objects.count() + 1}",
|
|
slug=f"article-{ArticlePage.objects.count() + 1}",
|
|
author=author,
|
|
summary="summary",
|
|
body=[("rich_text", "<p>body words</p>")],
|
|
)
|
|
article_index.add_child(instance=article)
|
|
article.save_revision().publish()
|
|
return article
|