mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 07:31:07 -05:00
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:
@@ -5,55 +5,55 @@ from django.conf.urls.static import static
|
||||
from django.views.static import serve
|
||||
from accounts import views as accounts_views
|
||||
from django.views.generic import TemplateView
|
||||
from .views import HomeView, SearchView
|
||||
from .views import HomeView
|
||||
from . import views
|
||||
from autocomplete import urls as autocomplete_urls
|
||||
import os
|
||||
|
||||
# Import API documentation views
|
||||
try:
|
||||
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView
|
||||
from drf_spectacular.views import (
|
||||
SpectacularAPIView,
|
||||
SpectacularSwaggerView,
|
||||
SpectacularRedocView,
|
||||
)
|
||||
|
||||
HAS_SPECTACULAR = True
|
||||
except ImportError:
|
||||
HAS_SPECTACULAR = False
|
||||
|
||||
# Import enhanced health check views
|
||||
try:
|
||||
from core.views.health_views import HealthCheckAPIView, PerformanceMetricsView, SimpleHealthView
|
||||
from core.views.health_views import (
|
||||
HealthCheckAPIView,
|
||||
PerformanceMetricsView,
|
||||
SimpleHealthView,
|
||||
)
|
||||
|
||||
HAS_HEALTH_VIEWS = True
|
||||
except ImportError:
|
||||
HAS_HEALTH_VIEWS = False
|
||||
|
||||
# Import autocomplete URLs
|
||||
try:
|
||||
from autocomplete import urls as autocomplete_urls
|
||||
|
||||
HAS_AUTOCOMPLETE = True
|
||||
except ImportError:
|
||||
HAS_AUTOCOMPLETE = False
|
||||
|
||||
# Build URL patterns list dynamically
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
# Main app URLs
|
||||
path("", HomeView.as_view(), name="home"),
|
||||
# Autocomplete URLs (must be before other URLs)
|
||||
path("ac/", autocomplete_urls),
|
||||
|
||||
# API Documentation URLs
|
||||
path("api/schema/", SpectacularAPIView.as_view(),
|
||||
name="schema") if HAS_SPECTACULAR else path("", lambda r: None),
|
||||
path("api/docs/", SpectacularSwaggerView.as_view(url_name="schema"),
|
||||
name="swagger-ui") if HAS_SPECTACULAR else path("", lambda r: None),
|
||||
path("api/redoc/", SpectacularRedocView.as_view(url_name="schema"),
|
||||
name="redoc") if HAS_SPECTACULAR else path("", lambda r: None),
|
||||
|
||||
# Health Check URLs
|
||||
path("health/", include("health_check.urls")),
|
||||
path("health/api/", HealthCheckAPIView.as_view(),
|
||||
name="health-api") if HAS_HEALTH_VIEWS else path("", lambda r: None),
|
||||
path("health/simple/", SimpleHealthView.as_view(),
|
||||
name="health-simple") if HAS_HEALTH_VIEWS else path("", lambda r: None),
|
||||
path("health/metrics/", PerformanceMetricsView.as_view(),
|
||||
name="health-metrics") if HAS_HEALTH_VIEWS else path("", lambda r: None),
|
||||
|
||||
# API URLs (before app URLs to avoid conflicts)
|
||||
path("api/v1/", include("parks.api.urls", namespace="parks_api")),
|
||||
path("api/v1/", include("rides.api.urls", namespace="rides_api")),
|
||||
path("api/v1/map/", include("core.urls.map_urls",
|
||||
namespace="map_api")), # Map API URLs
|
||||
|
||||
path(
|
||||
"api/v1/map/", include("core.urls.map_urls", namespace="map_api")
|
||||
), # Map API URLs
|
||||
# Parks and Rides URLs
|
||||
path("parks/", include("parks.urls", namespace="parks")),
|
||||
# Global rides URLs
|
||||
@@ -61,11 +61,15 @@ urlpatterns = [
|
||||
# Operators URLs
|
||||
path("operators/", include("parks.urls", namespace="operators")),
|
||||
# Other URLs
|
||||
path("photos/", include("media.urls", namespace="photos")), # Add photos URLs
|
||||
path("photos/", include("media.urls", namespace="photos")),
|
||||
# Add photos URLs
|
||||
path("search/", include("core.urls.search", namespace="search")),
|
||||
path("maps/", include("core.urls.maps", namespace="maps")), # Map HTML views
|
||||
path("maps/", include("core.urls.maps", namespace="maps")),
|
||||
# Map HTML views
|
||||
path(
|
||||
"terms/", TemplateView.as_view(template_name="pages/terms.html"), name="terms"
|
||||
"terms/",
|
||||
TemplateView.as_view(template_name="pages/terms.html"),
|
||||
name="terms",
|
||||
),
|
||||
path(
|
||||
"privacy/",
|
||||
@@ -77,7 +81,9 @@ urlpatterns = [
|
||||
# Default allauth URLs (for social auth and other features)
|
||||
path("accounts/", include("allauth.urls")),
|
||||
path(
|
||||
"accounts/email-required/", accounts_views.email_required, name="email_required"
|
||||
"accounts/email-required/",
|
||||
accounts_views.email_required,
|
||||
name="email_required",
|
||||
),
|
||||
# User profile URLs
|
||||
path(
|
||||
@@ -86,7 +92,9 @@ urlpatterns = [
|
||||
name="user_profile",
|
||||
),
|
||||
path(
|
||||
"profile/<str:username>/", accounts_views.ProfileView.as_view(), name="profile"
|
||||
"profile/<str:username>/",
|
||||
accounts_views.ProfileView.as_view(),
|
||||
name="profile",
|
||||
),
|
||||
path("settings/", accounts_views.SettingsView.as_view(), name="settings"),
|
||||
# Redirect /user/ to the user's profile if logged in
|
||||
@@ -100,39 +108,84 @@ urlpatterns = [
|
||||
),
|
||||
]
|
||||
|
||||
# Add autocomplete URLs if available
|
||||
if HAS_AUTOCOMPLETE:
|
||||
urlpatterns.insert(2, path("ac/", include((autocomplete_urls[0], autocomplete_urls[1]), namespace=autocomplete_urls[2])))
|
||||
|
||||
# Add API Documentation URLs if available
|
||||
if HAS_SPECTACULAR:
|
||||
urlpatterns.extend(
|
||||
[
|
||||
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
|
||||
path(
|
||||
"api/docs/",
|
||||
SpectacularSwaggerView.as_view(url_name="schema"),
|
||||
name="swagger-ui",
|
||||
),
|
||||
path(
|
||||
"api/redoc/",
|
||||
SpectacularRedocView.as_view(url_name="schema"),
|
||||
name="redoc",
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
# Add enhanced health check URLs if available
|
||||
if HAS_HEALTH_VIEWS:
|
||||
urlpatterns.extend(
|
||||
[
|
||||
path("health/api/", HealthCheckAPIView.as_view(), name="health-api"),
|
||||
path(
|
||||
"health/simple/",
|
||||
SimpleHealthView.as_view(),
|
||||
name="health-simple",
|
||||
),
|
||||
path(
|
||||
"health/metrics/",
|
||||
PerformanceMetricsView.as_view(),
|
||||
name="health-metrics",
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
# Serve static files in development
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.STATIC_URL,
|
||||
document_root=settings.STATIC_ROOT)
|
||||
urlpatterns += static(settings.MEDIA_URL,
|
||||
document_root=settings.MEDIA_ROOT)
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
# Development monitoring URLs
|
||||
try:
|
||||
import debug_toolbar
|
||||
|
||||
urlpatterns = [
|
||||
path('__debug__/', include(debug_toolbar.urls)),
|
||||
path("__debug__/", include(debug_toolbar.urls)),
|
||||
] + urlpatterns
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
import silk
|
||||
urlpatterns += [path('silk/', include('silk.urls', namespace='silk'))]
|
||||
pass
|
||||
|
||||
urlpatterns += [path("silk/", include("silk.urls", namespace="silk"))]
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Serve test coverage reports in development
|
||||
coverage_dir = os.path.join(settings.BASE_DIR, 'tests', 'coverage_html')
|
||||
coverage_dir = os.path.join(settings.BASE_DIR, "tests", "coverage_html")
|
||||
if os.path.exists(coverage_dir):
|
||||
urlpatterns += [
|
||||
path('coverage/', serve, {
|
||||
'document_root': coverage_dir,
|
||||
'path': 'index.html'
|
||||
}),
|
||||
path('coverage/<path:path>', serve, {
|
||||
'document_root': coverage_dir,
|
||||
}),
|
||||
path(
|
||||
"coverage/",
|
||||
serve,
|
||||
{"document_root": coverage_dir, "path": "index.html"},
|
||||
),
|
||||
path(
|
||||
"coverage/<path:path>",
|
||||
serve,
|
||||
{
|
||||
"document_root": coverage_dir,
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
handler404 = "thrillwiki.views.handler404"
|
||||
|
||||
Reference in New Issue
Block a user