Files
neuf-www/dnscms/tests/conftest.py
T
2026-05-15 02:58:41 +02:00

79 lines
1.8 KiB
Python

import json
import factory
import pytest
import wagtail_factories
from wagtail.models import Page
from events.models import EventIndex, EventPage
from venues.models import VenueIndex, VenuePage
class EventIndexFactory(wagtail_factories.PageFactory):
title = factory.Sequence(lambda n: f"Events {n}")
class Meta:
model = EventIndex
class EventPageFactory(wagtail_factories.PageFactory):
title = factory.Sequence(lambda n: f"Event {n}")
class Meta:
model = EventPage
class VenueIndexFactory(wagtail_factories.PageFactory):
title = factory.Sequence(lambda n: f"Venues {n}")
class Meta:
model = VenueIndex
class VenuePageFactory(wagtail_factories.PageFactory):
title = factory.Sequence(lambda n: f"Venue {n}")
class Meta:
model = VenuePage
@pytest.fixture
def root_page(db):
return Page.objects.get(depth=1)
@pytest.fixture
def home_page(root_page):
# Wagtail's initial migration creates a default "Welcome" page at depth=2.
# Reuse it so we don't fight slug collisions across tests.
return root_page.get_children().first() or root_page.add_child(
instance=Page(title="Home", slug="home")
)
@pytest.fixture
def event_index(home_page):
return EventIndexFactory(parent=home_page)
@pytest.fixture
def venue(home_page):
venue_index = VenueIndexFactory(parent=home_page)
return VenuePageFactory(parent=venue_index)
@pytest.fixture
def graphql_post(client):
def _post(query, variables=None):
payload = {"query": query}
if variables is not None:
payload["variables"] = variables
response = client.post(
"/api/graphql/",
data=json.dumps(payload),
content_type="application/json",
)
return response, response.json()
return _post