From 2b7adc3d36324beb908cfabe6362f548235f594e Mon Sep 17 00:00:00 2001 From: "sandro.meireles" Date: Fri, 31 May 2024 10:36:08 -0300 Subject: [PATCH 1/2] feat: Add exact_value field in the TestPlan model --- .../migrations/0002_testplan_exact_value.py | 22 +++++++++++++++++++ apip/testplans/models.py | 5 +++++ 2 files changed, 27 insertions(+) create mode 100644 apip/testplans/migrations/0002_testplan_exact_value.py 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: From 6f8dbfb94eb6769d172a6246becf0165e97aec86 Mon Sep 17 00:00:00 2001 From: "sandro.meireles" Date: Fri, 31 May 2024 10:41:19 -0300 Subject: [PATCH 2/2] feat: Allows you to return an exact schema value in the test plan --- apip/middlewares/subdomain_mock.py | 4 ++++ 1 file changed, 4 insertions(+) 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)