mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 09:11:08 -05:00
fix: Update import paths to use 'apps' prefix for models and services
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
"""
|
||||
Basic test script to verify RideLocation and CompanyHeadquarters models work correctly.
|
||||
"""
|
||||
from rides.models import Ride, RideLocation
|
||||
from parks.models import Company, CompanyHeadquarters
|
||||
from apps.rides.models import Ride, RideLocation
|
||||
from apps.parks.models import Company, CompanyHeadquarters
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
@@ -23,11 +23,11 @@ def test_company_headquarters():
|
||||
print("⚠️ No existing companies found, skipping CompanyHeadquarters test")
|
||||
return None, None
|
||||
|
||||
# Check if headquarters already exist
|
||||
try:
|
||||
headquarters = existing_company.headquarters
|
||||
# Check if headquarters already exist (use queryset lookup to avoid relying on a reverse attribute name)
|
||||
headquarters = CompanyHeadquarters.objects.filter(company=existing_company).first()
|
||||
if headquarters:
|
||||
print(f"✓ Found existing headquarters: {headquarters}")
|
||||
except CompanyHeadquarters.DoesNotExist:
|
||||
else:
|
||||
# Create headquarters for existing company
|
||||
headquarters = CompanyHeadquarters.objects.create(
|
||||
company=existing_company,
|
||||
@@ -53,7 +53,13 @@ def test_ride_location():
|
||||
# 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}")
|
||||
# Safely access the ride's name in case static analysis or runtime sees None/no attribute.
|
||||
ride_name = getattr(ride, "name", None) if ride is not None else None
|
||||
if ride_name:
|
||||
print(f"✓ Using existing ride: {ride_name}")
|
||||
else:
|
||||
# Fall back to repr of the ride object to avoid AttributeError
|
||||
print(f"✓ Using existing ride: {ride!r}")
|
||||
else:
|
||||
print("! No rides found in database - skipping RideLocation test")
|
||||
return None, None
|
||||
@@ -93,9 +99,9 @@ def cleanup_test_data(company=None, headquarters=None, ride_location=None):
|
||||
headquarters.delete()
|
||||
print("✓ Deleted test headquarters")
|
||||
|
||||
if company:
|
||||
company.delete()
|
||||
print("✓ Deleted test company")
|
||||
# Do not delete an existing company record discovered in the database.
|
||||
# Tests should avoid removing production/existing data. If a test created a Company
|
||||
# instance explicitly, add logic to delete it here (not implemented by default).
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -46,7 +46,7 @@ def test_trigger_endpoint(token):
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
print(f"\n🚀 Testing manual trigger endpoint...")
|
||||
print("\n🚀 Testing manual trigger endpoint...")
|
||||
print(f"URL: {trigger_url}")
|
||||
|
||||
response = requests.post(trigger_url, headers=headers)
|
||||
@@ -72,7 +72,7 @@ def test_trigger_endpoint(token):
|
||||
|
||||
def test_trending_endpoints():
|
||||
"""Test the trending content endpoints to see the results."""
|
||||
print(f"\n📊 Testing trending content endpoints...")
|
||||
print("\n📊 Testing trending content endpoints...")
|
||||
|
||||
# Test trending content endpoint
|
||||
trending_url = f"{BASE_URL}/api/v1/trending/content/"
|
||||
@@ -109,7 +109,7 @@ def test_trending_endpoints():
|
||||
|
||||
# Show the newly_opened structure to verify our changes
|
||||
if data.get('newly_opened'):
|
||||
print(f"\n🎢 First newly opened item structure:")
|
||||
print("\n🎢 First newly opened item structure:")
|
||||
first_item = data['newly_opened'][0]
|
||||
print(f" Name: {first_item.get('name')}")
|
||||
# Should be park name, not location
|
||||
@@ -124,12 +124,12 @@ def test_trending_endpoints():
|
||||
print(
|
||||
f" ❌ ERROR: 'location' field still present: {first_item['location']}")
|
||||
else:
|
||||
print(f" ✅ SUCCESS: 'location' field removed as requested")
|
||||
print(" ✅ SUCCESS: 'location' field removed as requested")
|
||||
|
||||
|
||||
def test_unauthorized_access():
|
||||
"""Test that non-admin users cannot access the trigger endpoint."""
|
||||
print(f"\n🔒 Testing unauthorized access...")
|
||||
print("\n🔒 Testing unauthorized access...")
|
||||
|
||||
trigger_url = f"{BASE_URL}/api/v1/trending/calculate/"
|
||||
|
||||
@@ -169,7 +169,7 @@ def main():
|
||||
trigger_result = test_trigger_endpoint(token)
|
||||
|
||||
if trigger_result:
|
||||
print(f"\n⏳ Waiting 10 seconds for tasks to process...")
|
||||
print("\n⏳ Waiting 10 seconds for tasks to process...")
|
||||
time.sleep(10)
|
||||
|
||||
# Test the trending endpoints to see results
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"""
|
||||
Test script for ParkLocation model functionality
|
||||
"""
|
||||
from parks.models import Park, ParkLocation, Company
|
||||
from apps.parks.models import Park, ParkLocation, Company
|
||||
import os
|
||||
import django
|
||||
|
||||
|
||||
@@ -9,14 +9,21 @@ This script tests all functionality of the OSM Road Trip Service including:
|
||||
- Integration with existing Park models
|
||||
"""
|
||||
|
||||
from typing import cast
|
||||
from apps.parks.services import RoadTripService
|
||||
from apps.parks.services.roadtrip import Coordinates
|
||||
from apps.parks.models import Park
|
||||
from django.core.cache import cache
|
||||
from parks.models import Park
|
||||
from parks.services.roadtrip import Coordinates
|
||||
from parks.services import RoadTripService
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
|
||||
# Setup Django
|
||||
# Ensure project root is on sys.path so imports like `parks.models` resolve.
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if PROJECT_ROOT not in sys.path:
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
# Setup Django before importing project modules that depend on settings.
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thrillwiki.settings")
|
||||
django.setup()
|
||||
|
||||
@@ -40,16 +47,13 @@ def test_geocoding():
|
||||
print(f"\nGeocoding: {address}")
|
||||
coords = service.geocode_address(address)
|
||||
if coords:
|
||||
print(
|
||||
f" ✅ Success: {
|
||||
coords.latitude:.6f}, {
|
||||
coords.longitude:.6f}"
|
||||
)
|
||||
# fixed: single-line f-string formatting
|
||||
print(f" ✅ Success: {coords.latitude:.6f}, {coords.longitude:.6f}")
|
||||
else:
|
||||
print(f" ❌ Failed")
|
||||
print(" ❌ Failed")
|
||||
|
||||
# Test cache functionality
|
||||
print(f"\nTesting cache...")
|
||||
print("\nTesting cache...")
|
||||
coords1 = service.geocode_address("Cedar Point, Sandusky, Ohio")
|
||||
coords2 = service.geocode_address("Cedar Point, Sandusky, Ohio")
|
||||
if coords1 and coords2:
|
||||
@@ -66,30 +70,30 @@ def test_route_calculation():
|
||||
cedar_point = Coordinates(41.4793, -82.6833)
|
||||
magic_kingdom = Coordinates(28.4177, -81.5812)
|
||||
|
||||
print(f"Calculating route from Cedar Point to Magic Kingdom...")
|
||||
print("Calculating route from Cedar Point to Magic Kingdom...")
|
||||
route = service.calculate_route(cedar_point, magic_kingdom)
|
||||
|
||||
if route:
|
||||
print(f" ✅ Success:")
|
||||
print(" ✅ Success:")
|
||||
print(f" Distance: {route.formatted_distance}")
|
||||
print(f" Duration: {route.formatted_duration}")
|
||||
print(f" Geometry: {'Yes' if route.geometry else 'No'}")
|
||||
else:
|
||||
print(f" ❌ Failed")
|
||||
print(" ❌ Failed")
|
||||
|
||||
# Test short distance (should use OSRM)
|
||||
disneyland = Coordinates(33.8121, -117.9190)
|
||||
knotts = Coordinates(33.8442, -118.0000)
|
||||
|
||||
print(f"\nCalculating route from Disneyland to Knott's Berry Farm...")
|
||||
print("\nCalculating route from Disneyland to Knott's Berry Farm...")
|
||||
route = service.calculate_route(disneyland, knotts)
|
||||
|
||||
if route:
|
||||
print(f" ✅ Success:")
|
||||
print(" ✅ Success:")
|
||||
print(f" Distance: {route.formatted_distance}")
|
||||
print(f" Duration: {route.formatted_duration}")
|
||||
else:
|
||||
print(f" ❌ Failed")
|
||||
print(" ❌ Failed")
|
||||
|
||||
|
||||
def test_park_integration():
|
||||
@@ -108,24 +112,25 @@ def test_park_integration():
|
||||
print(f"Found {len(parks)} parks to test with:")
|
||||
for park in parks:
|
||||
print(f" - {park.name}")
|
||||
if hasattr(park, "location") and park.location:
|
||||
coords = park.coordinates
|
||||
# Use getattr to safely access the optional related attribute and avoid static type warnings.
|
||||
location = getattr(park, "location", None)
|
||||
if location:
|
||||
coords = getattr(park, "coordinates", None)
|
||||
if coords:
|
||||
print(f" 📍 {coords[0]:.4f}, {coords[1]:.4f}")
|
||||
else:
|
||||
print(f" 📍 No coordinates, will try to geocode...")
|
||||
print(" 📍 No coordinates, will try to geocode...")
|
||||
success = service.geocode_park_if_needed(park)
|
||||
if success:
|
||||
coords = park.coordinates
|
||||
print(
|
||||
f" ✅ Geocoded to: {
|
||||
coords[0]:.4f}, {
|
||||
coords[1]:.4f}"
|
||||
)
|
||||
coords = getattr(park, "coordinates", None)
|
||||
if coords:
|
||||
print(f" ✅ Geocoded to: {coords[0]:.4f}, {coords[1]:.4f}")
|
||||
else:
|
||||
print(" ❌ Geocoding succeeded but coordinates still missing")
|
||||
else:
|
||||
print(f" ❌ Geocoding failed")
|
||||
print(" ❌ Geocoding failed")
|
||||
else:
|
||||
print(f" ❌ No location data")
|
||||
print(" ❌ No location data")
|
||||
|
||||
|
||||
def test_nearby_parks():
|
||||
@@ -153,13 +158,9 @@ def test_nearby_parks():
|
||||
for result in nearby_parks[:5]: # Show first 5
|
||||
park = result["park"]
|
||||
print(
|
||||
f" {
|
||||
park.name}: {
|
||||
result['formatted_distance']}, {
|
||||
result['formatted_duration']}"
|
||||
)
|
||||
f" {park.name}: {result['formatted_distance']}, {result['formatted_duration']}")
|
||||
else:
|
||||
print(f" ❌ No nearby parks found")
|
||||
print(" ❌ No nearby parks found")
|
||||
|
||||
|
||||
def test_route_park_discovery():
|
||||
@@ -180,11 +181,7 @@ def test_route_park_discovery():
|
||||
start_park = parks_with_location[0]
|
||||
end_park = parks_with_location[1]
|
||||
|
||||
print(
|
||||
f"Finding parks along route from {
|
||||
start_park.name} to {
|
||||
end_park.name}..."
|
||||
)
|
||||
print(f"Finding parks along route from {start_park.name} to {end_park.name}...")
|
||||
|
||||
parks_along_route = service.find_parks_along_route(
|
||||
start_park, end_park, max_detour_km=100
|
||||
@@ -195,7 +192,7 @@ def test_route_park_discovery():
|
||||
for park in parks_along_route[:3]: # Show first 3
|
||||
print(f" - {park.name}")
|
||||
else:
|
||||
print(f" ❌ No parks found along route")
|
||||
print(" ❌ No parks found along route")
|
||||
|
||||
|
||||
def test_multi_park_trip():
|
||||
@@ -221,19 +218,16 @@ def test_multi_park_trip():
|
||||
trip = service.create_multi_park_trip(parks_list)
|
||||
|
||||
if trip:
|
||||
print(f" ✅ Trip planned successfully:")
|
||||
print(" ✅ Trip planned successfully:")
|
||||
print(f" Total Distance: {trip.formatted_total_distance}")
|
||||
print(f" Total Duration: {trip.formatted_total_duration}")
|
||||
print(f" Route:")
|
||||
print(" Route:")
|
||||
for i, leg in enumerate(trip.legs, 1):
|
||||
print(f" {i}. {leg.from_park.name} → {leg.to_park.name}")
|
||||
print(
|
||||
f" {
|
||||
leg.route.formatted_distance}, {
|
||||
leg.route.formatted_duration}"
|
||||
)
|
||||
f" {leg.route.formatted_distance}, {leg.route.formatted_duration}")
|
||||
else:
|
||||
print(f" ❌ Trip planning failed")
|
||||
print(" ❌ Trip planning failed")
|
||||
|
||||
|
||||
def test_error_handling():
|
||||
@@ -249,28 +243,28 @@ def test_error_handling():
|
||||
|
||||
route = service.calculate_route(invalid_coords, valid_coords)
|
||||
if route:
|
||||
print(
|
||||
f" ⚠️ Got route with invalid coords: {
|
||||
route.formatted_distance}"
|
||||
)
|
||||
print(f" ⚠️ Got route with invalid coords: {route.formatted_distance}")
|
||||
else:
|
||||
print(f" ✅ Correctly handled invalid coordinates")
|
||||
print(" ✅ Correctly handled invalid coordinates")
|
||||
|
||||
# Test with empty address
|
||||
print("Testing empty address geocoding...")
|
||||
coords = service.geocode_address("")
|
||||
if coords:
|
||||
print(f" ⚠️ Got coordinates for empty address")
|
||||
print(" ⚠️ Got coordinates for empty address")
|
||||
else:
|
||||
print(f" ✅ Correctly handled empty address")
|
||||
print(" ✅ Correctly handled empty address")
|
||||
|
||||
# Test with None values
|
||||
print("Testing None coordinates...")
|
||||
route = service.calculate_route(None, valid_coords)
|
||||
# cast(None, Coordinates) is used only to satisfy static typing checks
|
||||
# while keeping the runtime intent of passing None to the service.
|
||||
route = service.calculate_route(cast(Coordinates, None), valid_coords)
|
||||
|
||||
if route:
|
||||
print(f" ⚠️ Got route with None coordinates")
|
||||
print(" ⚠️ Got route with None coordinates")
|
||||
else:
|
||||
print(f" ✅ Correctly handled None coordinates")
|
||||
print(" ✅ Correctly handled None coordinates")
|
||||
|
||||
|
||||
def test_rate_limiting():
|
||||
@@ -294,19 +288,15 @@ def test_rate_limiting():
|
||||
for address in addresses:
|
||||
coords = service.geocode_address(address)
|
||||
if coords:
|
||||
print(
|
||||
f" ✅ {address}: {
|
||||
coords.latitude:.4f}, {
|
||||
coords.longitude:.4f}"
|
||||
)
|
||||
print(f" ✅ {address}: {coords.latitude:.4f}, {coords.longitude:.4f}")
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
print(f" Total time for 3 requests: {elapsed:.2f} seconds")
|
||||
|
||||
if elapsed >= 2.0: # Should take at least 2 seconds with 1 req/sec limit
|
||||
print(f" ✅ Rate limiting appears to be working")
|
||||
print(" ✅ Rate limiting appears to be working")
|
||||
else:
|
||||
print(f" ⚠️ Requests may have been cached or rate limiting not working")
|
||||
print(" ⚠️ Requests may have been cached or rate limiting not working")
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -4,16 +4,24 @@ Test script for the unified map service.
|
||||
This script tests the map service with real location data.
|
||||
"""
|
||||
|
||||
from core.services.data_structures import GeoBounds, MapFilters, LocationType
|
||||
from core.services.map_service import unified_map_service
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
|
||||
# Setup Django environment
|
||||
# Ensure project root is on sys.path so imports like `core.services.*` resolve.
|
||||
# This inserts the parent directory of the tests folder (project root).
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if PROJECT_ROOT not in sys.path:
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
# Setup Django environment before importing app modules that depend on settings.
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thrillwiki.settings")
|
||||
django.setup()
|
||||
|
||||
# Now import project modules
|
||||
from apps.core.services.data_structures import GeoBounds, MapFilters, LocationType # noqa: E402
|
||||
from apps.core.services.map_service import unified_map_service # noqa: E402
|
||||
|
||||
|
||||
def test_basic_map_service():
|
||||
"""Test basic map service functionality."""
|
||||
@@ -215,7 +223,7 @@ def test_performance():
|
||||
print(f" Max time: {max(times):.2f}ms")
|
||||
|
||||
# Test cache performance
|
||||
print(f"\n Testing cache performance:")
|
||||
print("\n Testing cache performance:")
|
||||
start = time.time()
|
||||
response1 = unified_map_service.get_map_data(zoom_level=10, use_cache=True)
|
||||
time1 = time.time() - start
|
||||
|
||||
Reference in New Issue
Block a user