mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-23 08:51:09 -05:00
Add standardized HTMX conventions, interaction patterns, and migration guide for ThrillWiki UX
This commit is contained in:
@@ -1,14 +1,42 @@
|
||||
import pytest
|
||||
from playwright.sync_api import Page
|
||||
import subprocess
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_test_data():
|
||||
"""Setup test data before each test session"""
|
||||
subprocess.run(["uv", "run", "manage.py", "create_test_users"], check=True)
|
||||
@pytest.fixture(scope="session")
|
||||
def setup_test_data(django_db_setup, django_db_blocker):
|
||||
"""
|
||||
Setup test data before the test session using factories.
|
||||
|
||||
This fixture:
|
||||
- Uses factories instead of shelling out to management commands
|
||||
- Is scoped to session (not autouse per test) to reduce overhead
|
||||
- Uses django_db_blocker to allow database access in session-scoped fixture
|
||||
"""
|
||||
with django_db_blocker.unblock():
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
# Create test users if they don't exist
|
||||
test_users = [
|
||||
{"username": "testuser", "email": "testuser@example.com", "password": "testpass123"},
|
||||
{"username": "moderator", "email": "moderator@example.com", "password": "modpass123", "is_staff": True},
|
||||
{"username": "admin", "email": "admin@example.com", "password": "adminpass123", "is_staff": True, "is_superuser": True},
|
||||
]
|
||||
|
||||
for user_data in test_users:
|
||||
password = user_data.pop("password")
|
||||
user, created = User.objects.get_or_create(
|
||||
username=user_data["username"],
|
||||
defaults=user_data
|
||||
)
|
||||
if created:
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
|
||||
yield
|
||||
subprocess.run(["uv", "run", "manage.py", "cleanup_test_data"], check=True)
|
||||
|
||||
# Cleanup is handled automatically by pytest-django's transactional database
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -34,7 +62,7 @@ def setup_page(page: Page):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_page(page: Page, live_server):
|
||||
def auth_page(page: Page, live_server, setup_test_data):
|
||||
"""Fixture for authenticated page"""
|
||||
# Login using live_server URL
|
||||
page.goto(f"{live_server.url}/accounts/login/")
|
||||
@@ -46,7 +74,7 @@ def auth_page(page: Page, live_server):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mod_page(page: Page, live_server):
|
||||
def mod_page(page: Page, live_server, setup_test_data):
|
||||
"""Fixture for moderator page"""
|
||||
# Login as moderator using live_server URL
|
||||
page.goto(f"{live_server.url}/accounts/login/")
|
||||
@@ -107,7 +135,7 @@ def test_review(test_park: Page, live_server):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_page(page: Page, live_server):
|
||||
def admin_page(page: Page, live_server, setup_test_data):
|
||||
"""Fixture for admin/superuser page"""
|
||||
# Login as admin using live_server URL
|
||||
page.goto(f"{live_server.url}/accounts/login/")
|
||||
@@ -406,3 +434,39 @@ def regular_user(db):
|
||||
user.save()
|
||||
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parks_data(db):
|
||||
"""Create test parks for E2E testing."""
|
||||
from tests.factories import ParkFactory
|
||||
|
||||
parks = [
|
||||
ParkFactory(
|
||||
name=f"E2E Test Park {i}",
|
||||
slug=f"e2e-test-park-{i}",
|
||||
status="OPERATING"
|
||||
)
|
||||
for i in range(3)
|
||||
]
|
||||
|
||||
return parks
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def rides_data(db, parks_data):
|
||||
"""Create test rides for E2E testing."""
|
||||
from tests.factories import RideFactory
|
||||
|
||||
rides = []
|
||||
for park in parks_data:
|
||||
for i in range(2):
|
||||
ride = RideFactory(
|
||||
name=f"E2E Test Ride {park.name} {i}",
|
||||
slug=f"e2e-test-ride-{park.slug}-{i}",
|
||||
park=park,
|
||||
status="OPERATING"
|
||||
)
|
||||
rides.append(ride)
|
||||
|
||||
return rides
|
||||
|
||||
Reference in New Issue
Block a user