Skip to content

Commit 886ca65

Browse files
committed
[#5074] Added tests
1 parent 0d022ba commit 886ca65

File tree

3 files changed

+143
-1
lines changed

3 files changed

+143
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
interactions:
2+
- request:
3+
body: '"{\"values\": {\"selectBoxes1\": [\"option1\"], \"selectBoxes2\": {\"option2\":
4+
true}}, \"values_schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",
5+
\"type\": \"object\", \"properties\": {\"selectBoxes1\": {\"type\": \"array\",
6+
\"title\": \"Selectboxes1\"}, \"selectBoxes2\": {\"type\": \"object\", \"title\":
7+
\"Selectboxes2\"}}, \"required\": [\"selectBoxes1\", \"selectBoxes2\"], \"additionalProperties\":
8+
false}, \"metadata\": {}, \"metadata_schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",
9+
\"type\": \"object\", \"properties\": {}, \"required\": [], \"additionalProperties\":
10+
false}}"'
11+
headers:
12+
Accept:
13+
- '*/*'
14+
Accept-Encoding:
15+
- gzip, deflate, br
16+
Authorization:
17+
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3NDExNzMxNDksImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.rTOGuzHYxjtTy86oN3jiiSQD9TREPid0CnNWoeMU_LQ
18+
Connection:
19+
- keep-alive
20+
Content-Length:
21+
- '635'
22+
Content-Type:
23+
- application/json
24+
User-Agent:
25+
- python-requests/2.32.2
26+
method: POST
27+
uri: http://localhost/json_plugin
28+
response:
29+
body:
30+
string: "{\n \"data\": {\n \"metadata\": {},\n \"metadata_schema\": {\n
31+
\ \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\":
32+
false,\n \"properties\": {},\n \"required\": [],\n \"type\":
33+
\"object\"\n },\n \"values\": {\n \"selectBoxes1\": [\n \"option1\"\n
34+
\ ],\n \"selectBoxes2\": {\n \"option2\": true\n }\n
35+
\ },\n \"values_schema\": {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n
36+
\ \"additionalProperties\": false,\n \"properties\": {\n \"selectBoxes1\":
37+
{\n \"title\": \"Selectboxes1\",\n \"type\": \"array\"\n
38+
\ },\n \"selectBoxes2\": {\n \"title\": \"Selectboxes2\",\n
39+
\ \"type\": \"object\"\n }\n },\n \"required\": [\n
40+
\ \"selectBoxes1\",\n \"selectBoxes2\"\n ],\n \"type\":
41+
\"object\"\n }\n },\n \"message\": \"Data received\"\n}\n"
42+
headers:
43+
Connection:
44+
- close
45+
Content-Length:
46+
- '860'
47+
Content-Type:
48+
- application/json
49+
Date:
50+
- Wed, 05 Mar 2025 11:12:29 GMT
51+
Server:
52+
- Werkzeug/3.1.3 Python/3.12.9
53+
status:
54+
code: 201
55+
message: CREATED
56+
version: 1

src/openforms/registrations/contrib/json_dump/tests/test_backend.py

+50-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_submission_happy_flow(self):
7878
json_plugin = JSONDumpRegistration("json_registration_plugin")
7979

8080
expected_values = {
81-
# Note that `lastName` is not included here as it wasn't specified in the variables
81+
# Note that `lastName` is not included here as it wasn"t specified in the variables
8282
"auth_bsn": "123456789",
8383
"firstName": "We Are",
8484
"file": {
@@ -497,6 +497,55 @@ def test_select_boxes_schema_required_is_empty_when_no_data_is_submitted(self):
497497
[],
498498
)
499499

500+
def test_list_transformation_in_selectboxes(self):
501+
submission = SubmissionFactory.from_components(
502+
[
503+
{"key": "selectBoxes1", "type": "selectboxes"},
504+
{"key": "selectBoxes2", "type": "selectboxes"},
505+
],
506+
completed=True,
507+
submitted_data={
508+
"selectBoxes1": {"option1": True},
509+
"selectBoxes2": {"option2": True},
510+
},
511+
)
512+
513+
options: JSONDumpOptions = {
514+
"service": self.service,
515+
"path": "json_plugin",
516+
"variables": ["selectBoxes1", "selectBoxes2"],
517+
"fixed_metadata_variables": [],
518+
"additional_metadata_variables": [],
519+
"transform_to_list": {"select_boxes1": True},
520+
}
521+
json_plugin = JSONDumpRegistration("json_registration_plugin")
522+
523+
expected_values = {
524+
"selectBoxes1": ["option1"],
525+
"selectBoxes2": {"option2": True},
526+
}
527+
expected_schema = {
528+
"$schema": "https://json-schema.org/draft/2020-12/schema",
529+
"type": "object",
530+
"properties": {
531+
"selectBoxes1": {"type": "array", "title": "Selectboxes1"},
532+
"selectBoxes2": {"type": "object", "title": "Selectboxes2"},
533+
},
534+
"required": ["selectBoxes1", "selectBoxes2"],
535+
"additionalProperties": False,
536+
}
537+
538+
result = json_plugin.register_submission(submission, options)
539+
assert result is not None
540+
541+
with self.subTest("values"):
542+
self.assertEqual(result["api_response"]["data"]["values"], expected_values)
543+
544+
with self.subTest("schema"):
545+
self.assertEqual(
546+
result["api_response"]["data"]["values_schema"], expected_schema
547+
)
548+
500549
def test_select_component_with_manual_data_source(self):
501550
submission = SubmissionFactory.from_components(
502551
[

src/openforms/registrations/contrib/objects_api/tests/test_backend_v2.py

+37
Original file line numberDiff line numberDiff line change
@@ -1441,3 +1441,40 @@ def test_addressNl_with_object_target_path(self):
14411441
}
14421442
},
14431443
)
1444+
1445+
def test_selectboxes_with_transform_to_list(self):
1446+
submission = SubmissionFactory.from_components(
1447+
[
1448+
{"key": "selectBoxes1", "type": "selectboxes"},
1449+
{"key": "selectBoxes2", "type": "selectboxes"},
1450+
],
1451+
completed=True,
1452+
submitted_data={
1453+
"selectBoxes1": {"option1": True},
1454+
"selectBoxes2": {"option2": True},
1455+
},
1456+
)
1457+
ObjectsAPIRegistrationData.objects.create(submission=submission)
1458+
v2_options: RegistrationOptionsV2 = {
1459+
"objects_api_group": self.group,
1460+
"version": 2,
1461+
"objecttype": UUID("f3f1b370-97ed-4730-bc7e-ebb20c230377"),
1462+
"objecttype_version": 1,
1463+
"update_existing_object": False,
1464+
"auth_attribute_path": [],
1465+
"variables_mapping": [
1466+
{"variable_key": "selectBoxes1", "target_path": ["path1"]},
1467+
{"variable_key": "selectBoxes2", "target_path": ["path2"]},
1468+
],
1469+
"iot_attachment": "",
1470+
"iot_submission_csv": "",
1471+
"iot_submission_report": "",
1472+
"transform_to_list": {"select_boxes1": True},
1473+
}
1474+
handler = ObjectsAPIV2Handler()
1475+
1476+
record_data = handler.get_record_data(submission=submission, options=v2_options)
1477+
1478+
data = record_data["data"]
1479+
1480+
self.assertEqual(data, {"path1": ["option1"], "path2": {"option2": True}})

0 commit comments

Comments
 (0)