mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 14:31:08 -05:00
- Implemented extensive test cases for the Parks API, covering endpoints for listing, retrieving, creating, updating, and deleting parks. - Added tests for filtering, searching, and ordering parks in the API. - Created tests for error handling in the API, including malformed JSON and unsupported methods. - Developed model tests for Park, ParkArea, Company, and ParkReview models, ensuring validation and constraints are enforced. - Introduced utility mixins for API and model testing to streamline assertions and enhance test readability. - Included integration tests to validate complete workflows involving park creation, retrieval, updating, and deletion.
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
"""
|
|
URL configuration for Parks API following Django styleguide patterns.
|
|
"""
|
|
|
|
from django.urls import path, include
|
|
from rest_framework.routers import DefaultRouter
|
|
|
|
from .views import (
|
|
ParkListApi,
|
|
ParkDetailApi,
|
|
ParkCreateApi,
|
|
ParkUpdateApi,
|
|
ParkDeleteApi,
|
|
ParkApi
|
|
)
|
|
|
|
app_name = 'parks_api'
|
|
|
|
# Option 1: Separate ViewSets for each operation (more explicit)
|
|
router_separate = DefaultRouter()
|
|
router_separate.register(r'list', ParkListApi, basename='park-list')
|
|
router_separate.register(r'detail', ParkDetailApi, basename='park-detail')
|
|
router_separate.register(r'create', ParkCreateApi, basename='park-create')
|
|
router_separate.register(r'update', ParkUpdateApi, basename='park-update')
|
|
router_separate.register(r'delete', ParkDeleteApi, basename='park-delete')
|
|
|
|
# Option 2: Unified ViewSet (more conventional DRF)
|
|
router_unified = DefaultRouter()
|
|
router_unified.register(r'parks', ParkApi, basename='park')
|
|
|
|
# Use unified approach for cleaner URLs
|
|
urlpatterns = [
|
|
path('v1/', include(router_unified.urls)),
|
|
]
|
|
|
|
# Alternative manual URL patterns for more control
|
|
urlpatterns_manual = [
|
|
# List and create
|
|
path('v1/parks/', ParkApi.as_view({
|
|
'get': 'list',
|
|
'post': 'create'
|
|
}), name='park-list'),
|
|
|
|
# Stats endpoint
|
|
path('v1/parks/stats/', ParkApi.as_view({
|
|
'get': 'stats'
|
|
}), name='park-stats'),
|
|
|
|
# Detail operations
|
|
path('v1/parks/<slug:slug>/', ParkApi.as_view({
|
|
'get': 'retrieve',
|
|
'put': 'update',
|
|
'patch': 'partial_update',
|
|
'delete': 'destroy'
|
|
}), name='park-detail'),
|
|
|
|
# Park reviews
|
|
path('v1/parks/<slug:slug>/reviews/', ParkApi.as_view({
|
|
'get': 'reviews'
|
|
}), name='park-reviews'),
|
|
]
|