Skip to content

Commit

Permalink
Merge pull request #5096 from open-formulieren/fix/5089-service-fetch…
Browse files Browse the repository at this point in the history
…-changing-case-type

Return 'service fetch config' api data with original text case
  • Loading branch information
robinmolen authored Feb 24, 2025
2 parents f46fe6e + de6393a commit e7e8155
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/openforms/variables/api/renderers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from djangorestframework_camel_case.render import CamelCaseJSONRenderer


class ServiceFetchConfigurationRenderer(CamelCaseJSONRenderer):
# The field body and query_params needs to be ignored, to prevent accidental snake_case to camelCase changes.
# See github issue https://github.com/open-formulieren/open-forms/issues/5089
json_underscoreize = {
"ignore_fields": (
"body",
"query_params",
)
}
2 changes: 2 additions & 0 deletions src/openforms/variables/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from openforms.forms.api.permissions import FormAPIPermissions

from ..models import ServiceFetchConfiguration
from .renderers import ServiceFetchConfigurationRenderer
from .serializers import ServiceFetchConfigurationSerializer


Expand All @@ -26,6 +27,7 @@ class ServiceFetchConfigurationViewSet(viewsets.ReadOnlyModelViewSet):
authentication_classes = (authentication.SessionAuthentication,)
permission_classes = (FormAPIPermissions,)
serializer_class = ServiceFetchConfigurationSerializer
renderer_classes = (ServiceFetchConfigurationRenderer,)

queryset = ServiceFetchConfiguration.objects.order_by("service", "-pk")
pagination_class = pagination.PageNumberPagination
42 changes: 42 additions & 0 deletions src/openforms/variables/tests/test_viewsets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
Expand Down Expand Up @@ -92,3 +94,43 @@ def test_service_fetch_configuration_have_the_right_properties(self):
}

self.assertEqual(response.data["results"][0], expected)

def test_service_fetch_configuration_list_returns_data_using_correct_text_case(
self,
):
config = ServiceFetchConfigurationFactory.create(
name="Service fetch configuration 1",
method=ServiceFetchMethods.post,
query_params={
"snake_case": ["snake_case_data"],
"camelCase": ["camelCaseData"],
},
body={"snake_case": "snake_case_data", "camelCase": "camelCaseData"},
)
endpoint = reverse("api:servicefetchconfiguration-list")
self.client.force_authenticate(user=self.admin_user)

response = self.client.get(endpoint, format="json")

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["count"], 1)

content = json.loads(response.content)
expected = {
"id": config.pk,
"name": "Service fetch configuration 1",
"service": f"http://testserver{reverse('api:service-detail', kwargs={'pk': config.service.pk})}",
"path": "",
"method": ServiceFetchMethods.post.value,
"headers": {},
"queryParams": {
"snake_case": ["snake_case_data"],
"camelCase": ["camelCaseData"],
},
"body": {"snake_case": "snake_case_data", "camelCase": "camelCaseData"},
"dataMappingType": "",
"mappingExpression": None,
"cacheTimeout": None,
}

self.assertEqual(content["results"][0], expected)

0 comments on commit e7e8155

Please sign in to comment.