mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-23 04:31: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:
137
rides/migrations/0002_add_business_constraints.py
Normal file
137
rides/migrations/0002_add_business_constraints.py
Normal file
@@ -0,0 +1,137 @@
|
||||
# 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", "0003_add_business_constraints"),
|
||||
("rides", "0001_initial"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddConstraint(
|
||||
model_name="ride",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("closing_date__isnull", True),
|
||||
("opening_date__isnull", True),
|
||||
("closing_date__gte", models.F("opening_date")),
|
||||
_connector="OR",
|
||||
),
|
||||
name="ride_closing_after_opening",
|
||||
violation_error_message="Closing date must be after opening date",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ride",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("min_height_in__isnull", True),
|
||||
("max_height_in__isnull", True),
|
||||
("min_height_in__lte", models.F("max_height_in")),
|
||||
_connector="OR",
|
||||
),
|
||||
name="ride_height_requirements_logical",
|
||||
violation_error_message="Minimum height cannot exceed maximum height",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ride",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("min_height_in__isnull", True),
|
||||
models.Q(("min_height_in__gte", 30), ("min_height_in__lte", 90)),
|
||||
_connector="OR",
|
||||
),
|
||||
name="ride_min_height_reasonable",
|
||||
violation_error_message="Minimum height must be between 30 and 90 inches",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ride",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("max_height_in__isnull", True),
|
||||
models.Q(("max_height_in__gte", 30), ("max_height_in__lte", 90)),
|
||||
_connector="OR",
|
||||
),
|
||||
name="ride_max_height_reasonable",
|
||||
violation_error_message="Maximum height must be between 30 and 90 inches",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ride",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("average_rating__isnull", True),
|
||||
models.Q(("average_rating__gte", 1), ("average_rating__lte", 10)),
|
||||
_connector="OR",
|
||||
),
|
||||
name="ride_rating_range",
|
||||
violation_error_message="Average rating must be between 1 and 10",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ride",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("capacity_per_hour__isnull", True),
|
||||
("capacity_per_hour__gt", 0),
|
||||
_connector="OR",
|
||||
),
|
||||
name="ride_capacity_positive",
|
||||
violation_error_message="Hourly capacity must be positive",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ride",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("ride_duration_seconds__isnull", True),
|
||||
("ride_duration_seconds__gt", 0),
|
||||
_connector="OR",
|
||||
),
|
||||
name="ride_duration_positive",
|
||||
violation_error_message="Ride duration must be positive",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ridereview",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(("rating__gte", 1), ("rating__lte", 10)),
|
||||
name="ride_review_rating_range",
|
||||
violation_error_message="Rating must be between 1 and 10",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ridereview",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("visit_date__lte", django.db.models.functions.datetime.Now())
|
||||
),
|
||||
name="ride_review_visit_date_not_future",
|
||||
violation_error_message="Visit date cannot be in the future",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="ridereview",
|
||||
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="ride_review_moderation_consistency",
|
||||
violation_error_message="Moderated reviews must have both moderator and moderation timestamp",
|
||||
),
|
||||
),
|
||||
]
|
||||
43
rides/migrations/0003_add_company_model.py
Normal file
43
rides/migrations/0003_add_company_model.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# Generated by Django 5.2.5 on 2025-08-16 23:12
|
||||
|
||||
import django.contrib.postgres.fields
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("rides", "0002_add_business_constraints"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Company',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('slug', models.SlugField(max_length=255, unique=True)),
|
||||
('roles', django.contrib.postgres.fields.ArrayField(
|
||||
base_field=models.CharField(
|
||||
choices=[('MANUFACTURER', 'Ride Manufacturer'), ('DESIGNER', 'Ride Designer'), ('OPERATOR', 'Park Operator'), ('PROPERTY_OWNER', 'Property Owner')],
|
||||
max_length=20
|
||||
),
|
||||
blank=True,
|
||||
default=list,
|
||||
size=None
|
||||
)),
|
||||
('description', models.TextField(blank=True)),
|
||||
('website', models.URLField(blank=True)),
|
||||
('founded_date', models.DateField(blank=True, null=True)),
|
||||
('rides_count', models.IntegerField(default=0)),
|
||||
('coasters_count', models.IntegerField(default=0)),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'Companies',
|
||||
'ordering': ['name'],
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,49 @@
|
||||
# Generated by Django 5.2.5 on 2025-08-16 23:13
|
||||
|
||||
import pgtrigger.compiler
|
||||
import pgtrigger.migrations
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("rides", "0003_add_company_model"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="company",
|
||||
name="created_at",
|
||||
field=models.DateTimeField(auto_now_add=True),
|
||||
),
|
||||
pgtrigger.migrations.AddTrigger(
|
||||
model_name="company",
|
||||
trigger=pgtrigger.compiler.Trigger(
|
||||
name="insert_insert",
|
||||
sql=pgtrigger.compiler.UpsertTriggerSql(
|
||||
func='INSERT INTO "rides_companyevent" ("coasters_count", "created_at", "description", "founded_date", "id", "name", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "rides_count", "roles", "slug", "updated_at", "website") VALUES (NEW."coasters_count", NEW."created_at", NEW."description", NEW."founded_date", NEW."id", NEW."name", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."rides_count", NEW."roles", NEW."slug", NEW."updated_at", NEW."website"); RETURN NULL;',
|
||||
hash="[AWS-SECRET-REMOVED]",
|
||||
operation="INSERT",
|
||||
pgid="pgtrigger_insert_insert_e7194",
|
||||
table="rides_company",
|
||||
when="AFTER",
|
||||
),
|
||||
),
|
||||
),
|
||||
pgtrigger.migrations.AddTrigger(
|
||||
model_name="company",
|
||||
trigger=pgtrigger.compiler.Trigger(
|
||||
name="update_update",
|
||||
sql=pgtrigger.compiler.UpsertTriggerSql(
|
||||
condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
|
||||
func='INSERT INTO "rides_companyevent" ("coasters_count", "created_at", "description", "founded_date", "id", "name", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "rides_count", "roles", "slug", "updated_at", "website") VALUES (NEW."coasters_count", NEW."created_at", NEW."description", NEW."founded_date", NEW."id", NEW."name", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."rides_count", NEW."roles", NEW."slug", NEW."updated_at", NEW."website"); RETURN NULL;',
|
||||
hash="[AWS-SECRET-REMOVED]",
|
||||
operation="UPDATE",
|
||||
pgid="pgtrigger_update_update_456a8",
|
||||
table="rides_company",
|
||||
when="AFTER",
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user