mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 13:31:08 -05:00
- Add complete backend/ directory with full Django application - Add frontend/ directory with Vite + TypeScript setup ready for Next.js - Add comprehensive shared/ directory with: - Complete documentation and memory-bank archives - Media files and avatars (letters, park/ride images) - Deployment scripts and automation tools - Shared types and utilities - Add architecture/ directory with migration guides - Configure pnpm workspace for monorepo development - Update .gitignore to exclude .django_tailwind_cli/ build artifacts - Preserve all historical documentation in shared/docs/memory-bank/ - Set up proper structure for full-stack development with shared resources
118 lines
3.8 KiB
Python
118 lines
3.8 KiB
Python
from django.test import TestCase, Client
|
|
from django.contrib.auth import get_user_model
|
|
from apps.parks.models import Park, ParkArea, ParkLocation, Company as Operator
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
def create_test_location(park: Park) -> ParkLocation:
|
|
"""Helper function to create a test location"""
|
|
park_location = ParkLocation.objects.create(
|
|
park=park,
|
|
street_address="123 Test St",
|
|
city="Test City",
|
|
state="TS",
|
|
country="Test Country",
|
|
postal_code="12345",
|
|
)
|
|
# Set coordinates using the helper method
|
|
park_location.set_coordinates(34.0522, -118.2437) # latitude, longitude
|
|
park_location.save()
|
|
return park_location
|
|
|
|
|
|
class ParkModelTests(TestCase):
|
|
@classmethod
|
|
def setUpTestData(cls) -> None:
|
|
# Create test user
|
|
cls.user = User.objects.create_user(
|
|
username="testuser",
|
|
email="test@example.com",
|
|
password="testpass123",
|
|
)
|
|
|
|
# Create test company
|
|
cls.operator = Operator.objects.create(
|
|
name="Test Company", website="http://example.com"
|
|
)
|
|
|
|
# Create test park
|
|
cls.park = Park.objects.create(
|
|
name="Test Park",
|
|
operator=cls.operator,
|
|
status="OPERATING",
|
|
website="http://testpark.com",
|
|
)
|
|
|
|
# Create test location
|
|
cls.location = create_test_location(cls.park)
|
|
|
|
def test_park_creation(self) -> None:
|
|
"""Test park instance creation and field values"""
|
|
self.assertEqual(self.park.name, "Test Park")
|
|
self.assertEqual(self.park.operator, self.operator)
|
|
self.assertEqual(self.park.status, "OPERATING")
|
|
self.assertEqual(self.park.website, "http://testpark.com")
|
|
self.assertTrue(self.park.slug)
|
|
|
|
def test_park_str_representation(self) -> None:
|
|
"""Test string representation of park"""
|
|
self.assertEqual(str(self.park), "Test Park")
|
|
|
|
def test_park_coordinates(self) -> None:
|
|
"""Test park coordinates property"""
|
|
coords = self.park.coordinates
|
|
self.assertIsNotNone(coords)
|
|
if coords:
|
|
self.assertAlmostEqual(coords[0], 34.0522, places=4) # latitude
|
|
self.assertAlmostEqual(coords[1], -118.2437, places=4) # longitude
|
|
|
|
def test_park_formatted_location(self) -> None:
|
|
"""Test park formatted_location property"""
|
|
expected = "123 Test St, Test City, TS, 12345, Test Country"
|
|
self.assertEqual(self.park.formatted_location, expected)
|
|
|
|
|
|
class ParkAreaTests(TestCase):
|
|
def setUp(self) -> None:
|
|
# Create test company
|
|
self.operator = Operator.objects.create(
|
|
name="Test Company", website="http://example.com"
|
|
)
|
|
|
|
# Create test park
|
|
self.park = Park.objects.create(
|
|
name="Test Park", operator=self.operator, status="OPERATING"
|
|
)
|
|
|
|
# Create test location
|
|
self.location = create_test_location(self.park)
|
|
|
|
# Create test area
|
|
self.area = ParkArea.objects.create(
|
|
park=self.park, name="Test Area", description="Test Description"
|
|
)
|
|
|
|
def test_area_creation(self) -> None:
|
|
"""Test park area creation"""
|
|
self.assertEqual(self.area.name, "Test Area")
|
|
self.assertEqual(self.area.park, self.park)
|
|
self.assertTrue(self.area.slug)
|
|
|
|
|
|
class ParkViewTests(TestCase):
|
|
def setUp(self) -> None:
|
|
self.client = Client()
|
|
self.user = User.objects.create_user(
|
|
username="testuser",
|
|
email="test@example.com",
|
|
password="testpass123",
|
|
)
|
|
self.operator = Operator.objects.create(
|
|
name="Test Company", website="http://example.com"
|
|
)
|
|
self.park = Park.objects.create(
|
|
name="Test Park", operator=self.operator, status="OPERATING"
|
|
)
|
|
self.location = create_test_location(self.park)
|