Refactor test utilities and enhance ASGI settings

- Cleaned up and standardized assertions in ApiTestMixin for API response validation.
- Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE.
- Removed unused imports and improved formatting in settings.py.
- Refactored URL patterns in urls.py for better readability and organization.
- Enhanced view functions in views.py for consistency and clarity.
- Added .flake8 configuration for linting and style enforcement.
- Introduced type stubs for django-environ to improve type checking with Pylance.
This commit is contained in:
pacnpal
2025-08-20 19:51:59 -04:00
parent 69c07d1381
commit 66ed4347a9
230 changed files with 15094 additions and 11578 deletions

View File

@@ -2,28 +2,27 @@
"""
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***REMOVED***iron.setdefault('DJANGO_SETTINGS_MODULE', 'thrillwiki.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thrillwiki.settings")
django.setup()
from django.contrib.gis.geos import Point
from parks.models import Company, CompanyHeadquarters
from rides.models import Ride, RideLocation
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
@@ -36,20 +35,21 @@ def test_company_headquarters():
state_province="Florida",
country="USA",
street_address="123 Theme Park Blvd",
postal_code="32801"
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()
@@ -57,74 +57,80 @@ def test_ride_location():
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"
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(
"✅ 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)
sys.exit(0 if success else 1)