Files
thrillwiki_django_no_react/parks/migrations/0003_add_business_constraints.py
pacnpal c26414ff74 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.
2025-08-17 19:36:20 -04:00

123 lines
4.6 KiB
Python

# Generated by Django 5.2.5 on 2025-08-16 17:42
import django.db.models.functions.datetime
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("parks", "0002_alter_parkarea_unique_together"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddConstraint(
model_name="park",
constraint=models.CheckConstraint(
condition=models.Q(
("closing_date__isnull", True),
("opening_date__isnull", True),
("closing_date__gte", models.F("opening_date")),
_connector="OR",
),
name="park_closing_after_opening",
violation_error_message="Closing date must be after opening date",
),
),
migrations.AddConstraint(
model_name="park",
constraint=models.CheckConstraint(
condition=models.Q(
("size_acres__isnull", True), ("size_acres__gt", 0), _connector="OR"
),
name="park_size_positive",
violation_error_message="Park size must be positive",
),
),
migrations.AddConstraint(
model_name="park",
constraint=models.CheckConstraint(
condition=models.Q(
("average_rating__isnull", True),
models.Q(("average_rating__gte", 1), ("average_rating__lte", 10)),
_connector="OR",
),
name="park_rating_range",
violation_error_message="Average rating must be between 1 and 10",
),
),
migrations.AddConstraint(
model_name="park",
constraint=models.CheckConstraint(
condition=models.Q(
("ride_count__isnull", True),
("ride_count__gte", 0),
_connector="OR",
),
name="park_ride_count_non_negative",
violation_error_message="Ride count must be non-negative",
),
),
migrations.AddConstraint(
model_name="park",
constraint=models.CheckConstraint(
condition=models.Q(
("coaster_count__isnull", True),
("coaster_count__gte", 0),
_connector="OR",
),
name="park_coaster_count_non_negative",
violation_error_message="Coaster count must be non-negative",
),
),
migrations.AddConstraint(
model_name="park",
constraint=models.CheckConstraint(
condition=models.Q(
("coaster_count__isnull", True),
("ride_count__isnull", True),
("coaster_count__lte", models.F("ride_count")),
_connector="OR",
),
name="park_coaster_count_lte_ride_count",
violation_error_message="Coaster count cannot exceed total ride count",
),
),
migrations.AddConstraint(
model_name="parkreview",
constraint=models.CheckConstraint(
condition=models.Q(("rating__gte", 1), ("rating__lte", 10)),
name="park_review_rating_range",
violation_error_message="Rating must be between 1 and 10",
),
),
migrations.AddConstraint(
model_name="parkreview",
constraint=models.CheckConstraint(
condition=models.Q(
("visit_date__lte", django.db.models.functions.datetime.Now())
),
name="park_review_visit_date_not_future",
violation_error_message="Visit date cannot be in the future",
),
),
migrations.AddConstraint(
model_name="parkreview",
constraint=models.CheckConstraint(
condition=models.Q(
models.Q(
("moderated_at__isnull", True), ("moderated_by__isnull", True)
),
models.Q(
("moderated_at__isnull", False), ("moderated_by__isnull", False)
),
_connector="OR",
),
name="park_review_moderation_consistency",
violation_error_message="Moderated reviews must have both moderator and moderation timestamp",
),
),
]