Files
thrillwiki_django_no_react/tests/test_location_models.py
pacnpal 1b246eeaa4 Add comprehensive test scripts for various models and services
- Implement tests for RideLocation and CompanyHeadquarters models to verify functionality and data integrity.
- Create a manual trigger test script for trending content calculation endpoint, including authentication and unauthorized access tests.
- Develop a manufacturer sync test to ensure ride manufacturers are correctly associated with ride models.
- Add tests for ParkLocation model, including coordinate setting and distance calculations between parks.
- Implement a RoadTripService test suite covering geocoding, route calculation, park discovery, and error handling.
- Create a unified map service test script to validate map functionality, API endpoints, and performance metrics.
2025-09-27 22:26:40 -04:00

137 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""
Basic test script to verify RideLocation and CompanyHeadquarters models work correctly.
"""
from rides.models import Ride, RideLocation
from parks.models import Company, CompanyHeadquarters
import os
import sys
import django
# Setup Django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thrillwiki.settings")
django.setup()
def test_company_headquarters():
"""Test CompanyHeadquarters model functionality"""
print("Testing CompanyHeadquarters...")
# Try to use an existing company or skip this test if none exist
existing_company = Company.objects.first()
if not existing_company:
print("⚠️ No existing companies found, skipping CompanyHeadquarters test")
return None, None
# Check if headquarters already exist
try:
headquarters = existing_company.headquarters
print(f"✓ Found existing headquarters: {headquarters}")
except CompanyHeadquarters.DoesNotExist:
# Create headquarters for existing company
headquarters = CompanyHeadquarters.objects.create(
company=existing_company,
city="Orlando",
state_province="Florida",
country="USA",
street_address="123 Theme Park Blvd",
postal_code="32801",
)
print(f"✓ Created new headquarters: {headquarters}")
print(f"✓ Created headquarters: {headquarters}")
print(f"✓ Location display: {headquarters.location_display}")
print(f"✓ Formatted location: {headquarters.formatted_location}")
return existing_company, headquarters
def test_ride_location():
"""Test RideLocation model functionality"""
print("\nTesting RideLocation...")
# First, we need a ride - let's check if any exist
if Ride.objects.exists():
ride = Ride.objects.first()
print(f"✓ Using existing ride: {ride.name}")
else:
print("! No rides found in database - skipping RideLocation test")
return None, None
# Create ride location
ride_location = RideLocation.objects.create(
ride=ride,
park_area="Fantasyland",
notes="General location information",
entrance_notes="Queue entrance is to the left of the main attraction sign",
accessibility_notes="Wheelchair accessible entrance available via side path",
)
print(f"✓ Created ride location: {ride_location}")
print(f"✓ Has coordinates: {ride_location.has_coordinates}")
# Test setting coordinates
ride_location.set_coordinates(28.3772, -81.5707) # Disney World coordinates
ride_location.save()
print(f"✓ Set coordinates: {ride_location.coordinates}")
print(f"✓ Latitude: {ride_location.latitude}")
print(f"✓ Longitude: {ride_location.longitude}")
return ride, ride_location
def cleanup_test_data(company=None, headquarters=None, ride_location=None):
"""Clean up test data"""
print("\nCleaning up test data...")
if ride_location:
ride_location.delete()
print("✓ Deleted test ride location")
if headquarters:
headquarters.delete()
print("✓ Deleted test headquarters")
if company:
company.delete()
print("✓ Deleted test company")
def main():
"""Run all tests"""
print("=" * 50)
print("Testing Location Models Implementation")
print("=" * 50)
try:
# Test CompanyHeadquarters
company, headquarters = test_company_headquarters()
# Test RideLocation
ride, ride_location = test_ride_location()
print("\n" + "=" * 50)
print("✅ ALL TESTS PASSED!")
print(
"✅ Both RideLocation and CompanyHeadquarters models are working correctly"
)
print("=" * 50)
# Clean up
cleanup_test_data(company, headquarters, ride_location)
except Exception as e:
print(f"\n❌ TEST FAILED: {e}")
import traceback
traceback.print_exc()
return False
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)