mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 05:11:09 -05:00
Add comprehensive tests for Parks API and models
- 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.
This commit is contained in:
@@ -73,6 +73,27 @@ class Location(TrackedModel):
|
||||
models.Index(fields=['country']),
|
||||
]
|
||||
ordering = ['name']
|
||||
constraints = [
|
||||
# Business rule: Latitude must be within valid range (-90 to 90)
|
||||
models.CheckConstraint(
|
||||
name="location_latitude_range",
|
||||
check=models.Q(latitude__isnull=True) | (models.Q(latitude__gte=-90) & models.Q(latitude__lte=90)),
|
||||
violation_error_message="Latitude must be between -90 and 90 degrees"
|
||||
),
|
||||
# Business rule: Longitude must be within valid range (-180 to 180)
|
||||
models.CheckConstraint(
|
||||
name="location_longitude_range",
|
||||
check=models.Q(longitude__isnull=True) | (models.Q(longitude__gte=-180) & models.Q(longitude__lte=180)),
|
||||
violation_error_message="Longitude must be between -180 and 180 degrees"
|
||||
),
|
||||
# Business rule: If coordinates are provided, both lat and lng must be present
|
||||
models.CheckConstraint(
|
||||
name="location_coordinates_complete",
|
||||
check=models.Q(latitude__isnull=True, longitude__isnull=True) |
|
||||
models.Q(latitude__isnull=False, longitude__isnull=False),
|
||||
violation_error_message="Both latitude and longitude must be provided together"
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
location_parts = []
|
||||
|
||||
Reference in New Issue
Block a user