diff --git a/apip/middlewares/subdomain_mock.py b/apip/middlewares/subdomain_mock.py index 8883f76..522cadf 100644 --- a/apip/middlewares/subdomain_mock.py +++ b/apip/middlewares/subdomain_mock.py @@ -48,6 +48,10 @@ def __call__(self, request: Request) -> Response: try: service = Service.objects.get(name__icontains=subdomain) test_plan = service.plans.get(endpoint=path) + + if test_plan.exact_value: + return JsonResponse(test_plan.schema, status=200) + fake_data = get_faker().generate_data_by_schema(test_plan.schema) return JsonResponse(fake_data, status=200) diff --git a/apip/testplans/migrations/0002_testplan_exact_value.py b/apip/testplans/migrations/0002_testplan_exact_value.py new file mode 100644 index 0000000..91fb7a0 --- /dev/null +++ b/apip/testplans/migrations/0002_testplan_exact_value.py @@ -0,0 +1,22 @@ +# Generated by Django 5.0 on 2024-05-31 02:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("testplans", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="testplan", + name="exact_value", + field=models.BooleanField( + default=False, + help_text="This field indicates that the value returned will be the same as that defined in schema", + verbose_name="Exact Value", + ), + ), + ] diff --git a/apip/testplans/models.py b/apip/testplans/models.py index fcb5485..2c4158e 100644 --- a/apip/testplans/models.py +++ b/apip/testplans/models.py @@ -6,6 +6,11 @@ class TestPlan(models.Model): endpoint = models.CharField(max_length=255) service = models.ForeignKey(Service, on_delete=models.CASCADE, related_name="plans") + exact_value = models.BooleanField( + "Exact Value", + help_text="This field indicates that the value returned will be the same as that defined in schema", + default=False + ) schema = models.JSONField(null=True, default=dict) def __str__(self) -> str: