Skip to content

Commit

Permalink
Merge pull request #9 from weni-ai/feature/exact-value
Browse files Browse the repository at this point in the history
Allows you to return an exact schema value in the test plan
  • Loading branch information
Sandro-Meireles authored May 31, 2024
2 parents 12c70d9 + 6f8dbfb commit d1fde07
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apip/middlewares/subdomain_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 22 additions & 0 deletions apip/testplans/migrations/0002_testplan_exact_value.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
5 changes: 5 additions & 0 deletions apip/testplans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d1fde07

Please sign in to comment.