Skip to content

Commit

Permalink
✅ [#4908] Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorvanwijk committed Jan 16, 2025
1 parent 1766a87 commit 4262b0c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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":
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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":
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"},
Expand All @@ -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",
Expand All @@ -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": {
Expand All @@ -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):
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 4262b0c

Please sign in to comment.