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:
pacnpal
2025-08-17 19:36:20 -04:00
parent 17228e9935
commit c26414ff74
210 changed files with 24155 additions and 833 deletions

View File

@@ -0,0 +1,50 @@
# Generated by Django 5.2.5 on 2025-08-16 17:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("contenttypes", "0002_remove_content_type_name"),
("location", "0001_initial"),
]
operations = [
migrations.AddConstraint(
model_name="location",
constraint=models.CheckConstraint(
condition=models.Q(
("latitude__isnull", True),
models.Q(("latitude__gte", -90), ("latitude__lte", 90)),
_connector="OR",
),
name="location_latitude_range",
violation_error_message="Latitude must be between -90 and 90 degrees",
),
),
migrations.AddConstraint(
model_name="location",
constraint=models.CheckConstraint(
condition=models.Q(
("longitude__isnull", True),
models.Q(("longitude__gte", -180), ("longitude__lte", 180)),
_connector="OR",
),
name="location_longitude_range",
violation_error_message="Longitude must be between -180 and 180 degrees",
),
),
migrations.AddConstraint(
model_name="location",
constraint=models.CheckConstraint(
condition=models.Q(
models.Q(("latitude__isnull", True), ("longitude__isnull", True)),
models.Q(("latitude__isnull", False), ("longitude__isnull", False)),
_connector="OR",
),
name="location_coordinates_complete",
violation_error_message="Both latitude and longitude must be provided together",
),
),
]

View File

@@ -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 = []