diff --git a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_exception_raised_when_service_returns_unexpected_status_code.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_exception_raised_when_service_returns_unexpected_status_code.yaml index 781d459570..8e8e53d0ba 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_exception_raised_when_service_returns_unexpected_status_code.yaml +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_exception_raised_when_service_returns_unexpected_status_code.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: '{"values": {"firstName": "We Are", "auth_bsn": "123456789"}, "schema": + body: '{"values": {"auth_bsn": "123456789", "firstName": "We Are"}, "schema": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": {"static_var_1": {"type": "string", "pattern": "^cool_pattern$"}, "form_var_1": {"type": "string"}, "form_var_2": {"type": "string"}, "attachment": @@ -12,7 +12,7 @@ interactions: Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3MzU4MjY2MzksImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.8PuPAIY6PI3_g4edfqzFFbHNldYxxRIBjPuAh-p00xk + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3MzcwMjI0MTksImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.l9VMsgnQjPxkpyouQEjx-hTuH3ODXmXU1XMXUgw-RJE Connection: - keep-alive Content-Length: @@ -45,7 +45,7 @@ interactions: Content-Type: - text/html; charset=utf-8 Date: - - Thu, 02 Jan 2025 14:03:59 GMT + - Thu, 16 Jan 2025 10:13:39 GMT Server: - Werkzeug/3.1.3 Python/3.12.8 status: diff --git a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_submission_with_json_dump_backend.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_multiple_file_uploads.yaml similarity index 73% rename from src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_submission_with_json_dump_backend.yaml rename to src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_multiple_file_uploads.yaml index d2294549fc..ac93e30110 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_submission_with_json_dump_backend.yaml +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_multiple_file_uploads.yaml @@ -1,7 +1,7 @@ interactions: - request: - body: '{"values": {"file": "VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu", "firstName": "We - Are", "auth_bsn": "123456789"}, "schema": {"$schema": "https://json-schema.org/draft/2020-12/schema", + body: '{"values": {"file": {"file1.txt": "VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu", "file2.txt": + "Q29udGVudCBleGFtcGxlIGlzIHRoaXMu"}}, "schema": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": {"static_var_1": {"type": "string", "pattern": "^cool_pattern$"}, "form_var_1": {"type": "string"}, "form_var_2": {"type": "string"}, "attachment": {"type": "string", "contentEncoding": "base64"}}, "required": @@ -12,11 +12,11 @@ interactions: Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3MzU4MjY2MzksImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.8PuPAIY6PI3_g4edfqzFFbHNldYxxRIBjPuAh-p00xk + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3MzcwMjI0MTksImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.l9VMsgnQjPxkpyouQEjx-hTuH3ODXmXU1XMXUgw-RJE Connection: - keep-alive Content-Length: - - '494' + - '510' Content-Type: - application/json User-Agent: @@ -33,17 +33,18 @@ interactions: {\n \"pattern\": \"^cool_pattern$\",\n \"type\": \"string\"\n \ }\n },\n \"required\": [\n \"static_var_1\",\n \"form_var_1\",\n \ \"form_var_2\"\n ],\n \"type\": \"object\"\n },\n \"values\": - {\n \"auth_bsn\": \"123456789\",\n \"file\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n - \ \"firstName\": \"We Are\"\n }\n },\n \"message\": \"Data received\"\n}\n" + {\n \"file\": {\n \"file1.txt\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n + \ \"file2.txt\": \"Q29udGVudCBleGFtcGxlIGlzIHRoaXMu\"\n }\n }\n + \ },\n \"message\": \"Data received\"\n}\n" headers: Connection: - close Content-Length: - - '783' + - '811' Content-Type: - application/json Date: - - Thu, 02 Jan 2025 14:03:59 GMT + - Thu, 16 Jan 2025 10:13:39 GMT Server: - Werkzeug/3.1.3 Python/3.12.8 status: diff --git a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_submission_happy_flow.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_submission_happy_flow.yaml new file mode 100644 index 0000000000..570b84a1ad --- /dev/null +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_submission_happy_flow.yaml @@ -0,0 +1,53 @@ +interactions: +- request: + body: '{"values": {"auth_bsn": "123456789", "firstName": "We Are", "file": {"test_file.txt": + "VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu"}}, "schema": {"$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", "properties": {"static_var_1": {"type": "string", "pattern": + "^cool_pattern$"}, "form_var_1": {"type": "string"}, "form_var_2": {"type": + "string"}, "attachment": {"type": "string", "contentEncoding": "base64"}}, "required": + ["static_var_1", "form_var_1", "form_var_2"], "additionalProperties": false}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3MzcwMjI1ODAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.ailt3SYzZV9xQ7heUqyJejAtOplSw-vNi0nVJFNK_lY + Connection: + - keep-alive + Content-Length: + - '513' + Content-Type: + - application/json + User-Agent: + - python-requests/2.32.2 + method: POST + uri: http://localhost/json_plugin + response: + body: + string: "{\n \"data\": {\n \"schema\": {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n + \ \"additionalProperties\": false,\n \"properties\": {\n \"attachment\": + {\n \"contentEncoding\": \"base64\",\n \"type\": \"string\"\n + \ },\n \"form_var_1\": {\n \"type\": \"string\"\n },\n + \ \"form_var_2\": {\n \"type\": \"string\"\n },\n \"static_var_1\": + {\n \"pattern\": \"^cool_pattern$\",\n \"type\": \"string\"\n + \ }\n },\n \"required\": [\n \"static_var_1\",\n \"form_var_1\",\n + \ \"form_var_2\"\n ],\n \"type\": \"object\"\n },\n \"values\": + {\n \"auth_bsn\": \"123456789\",\n \"file\": {\n \"test_file.txt\": + \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\"\n },\n \"firstName\": \"We + Are\"\n }\n },\n \"message\": \"Data received\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '818' + Content-Type: + - application/json + Date: + - Thu, 16 Jan 2025 10:16:20 GMT + Server: + - Werkzeug/3.1.3 Python/3.12.8 + status: + code: 201 + message: CREATED +version: 1 diff --git a/src/openforms/registrations/contrib/json_dump/tests/test_backend.py b/src/openforms/registrations/contrib/json_dump/tests/test_backend.py index 35e7fc5249..2d7b03c182 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/test_backend.py +++ b/src/openforms/registrations/contrib/json_dump/tests/test_backend.py @@ -4,6 +4,7 @@ from django.core.exceptions import SuspiciousOperation from django.test import TestCase +from glom import Path as Path_glom, glom from requests import RequestException from zgw_consumers.test.factories import ServiceFactory @@ -22,7 +23,7 @@ class JSONDumpBackendTests(OFVCRMixin, TestCase): VCR_TEST_FILES = VCR_TEST_FILES - def test_submission_with_json_dump_backend(self): + def test_submission_happy_flow(self): submission = SubmissionFactory.from_components( [ {"key": "firstName", "type": "textField"}, @@ -49,6 +50,7 @@ def test_submission_with_json_dump_backend(self): form_key="file", submission_step=submission.submissionstep_set.get(), file_name="test_file.txt", + original_name="test_file.txt", content_type="application/text", content__data=b"This is example content.", _component_configuration_path="components.2", @@ -68,7 +70,7 @@ def test_submission_with_json_dump_backend(self): "data": { "values": { "auth_bsn": "123456789", - "file": "VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu", # Content of the attachment encoded using base64 + "file": {"test_file.txt": "VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu"}, "firstName": "We Are", }, "schema": { @@ -93,7 +95,8 @@ def test_submission_with_json_dump_backend(self): self.assertEqual(res_json, expected_response) with self.subTest("attachment content encoded"): - decoded_content = b64decode(res_json["data"]["values"]["file"]) + path = Path_glom("data", "values", "file", "test_file.txt") + decoded_content = b64decode(glom(res_json, path)) self.assertEqual(decoded_content, b"This is example content.") def test_exception_raised_when_service_returns_unexpected_status_code(self): @@ -144,6 +147,7 @@ def test_multiple_file_uploads(self): form_key="file", submission_step=submission.submissionstep_set.get(), file_name="file1.txt", + original_name="file1.txt", content_type="application/text", content__data=b"This is example content.", _component_configuration_path="components.2", @@ -154,6 +158,7 @@ def test_multiple_file_uploads(self): form_key="file", submission_step=submission.submissionstep_set.get(), file_name="file2.txt", + original_name="file2.txt", content_type="application/text", content__data=b"Content example is this.", _component_configuration_path="components.2",