From 3be58935183e90646cd14cc0429674a0b20fa284 Mon Sep 17 00:00:00 2001 From: Viktor van Wijk Date: Mon, 20 Jan 2025 15:47:39 +0100 Subject: [PATCH] :white_check_mark: [#4980] Update tests In the JSON dump docker app, explicitly load the received data before sending again. This prevents the data from being interpreted as a string instead of a JSON object. --- .../static_variables/static_variables.py | 10 +- .../tests/test_static_variables.py | 102 ++++++++ src/openforms/formio/components/utils.py | 1 + .../tests/test_component_json_schemas.py | 36 ++- .../forms/tests/test_form_to_json_schema.py | 130 +++++++++- .../test_variables_in_logic_trigger.py | 8 + src/openforms/forms/utils.py | 4 +- .../registrations/contrib/json_dump/plugin.py | 8 +- ...ervice_returns_unexpected_status_code.yaml | 16 +- ...ckendTests.test_multiple_file_uploads.yaml | 36 +-- ...e_upload_for_multiple_files_component.yaml | 33 +-- ...file_upload_for_single_file_component.yaml | 25 +- ...e_upload_for_multiple_files_component.yaml | 36 +-- ...ent_with_form_variable_as_data_source.yaml | 47 ++++ ...dio_component_with_manual_data_source.yaml | 47 ++++ ...ent_with_form_variable_as_data_source.yaml | 55 ++++ ...ed_is_empty_when_no_data_is_submitted.yaml | 50 ++++ ...ent_with_form_variable_as_data_source.yaml | 49 ++++ ...ect_component_with_manual_data_source.yaml | 49 ++++ ...ckendTests.test_submission_happy_flow.yaml | 41 +-- .../contrib/json_dump/tests/test_backend.py | 242 +++++++++++++----- src/openforms/variables/service.py | 5 +- .../variables/tests/test_registry.py | 4 + .../variables/tests/test_static_variables.py | 45 ++++ .../tests/test_user_defined_variables.py | 56 ++++ src/openforms/variables/tests/test_views.py | 8 + 26 files changed, 963 insertions(+), 180 deletions(-) create mode 100644 src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_radio_component_with_form_variable_as_data_source.yaml create mode 100644 src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_radio_component_with_manual_data_source.yaml create mode 100644 src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_boxes_component_with_form_variable_as_data_source.yaml create mode 100644 src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_boxes_schema_required_is_empty_when_no_data_is_submitted.yaml create mode 100644 src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_component_with_form_variable_as_data_source.yaml create mode 100644 src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_component_with_manual_data_source.yaml create mode 100644 src/openforms/variables/tests/test_user_defined_variables.py diff --git a/src/openforms/authentication/static_variables/static_variables.py b/src/openforms/authentication/static_variables/static_variables.py index ce5b558554..8298d19543 100644 --- a/src/openforms/authentication/static_variables/static_variables.py +++ b/src/openforms/authentication/static_variables/static_variables.py @@ -72,7 +72,11 @@ def get_initial_value( @staticmethod def as_json_schema(): # NOTE: this has been made 'vague' on purpose, see the comment on AuthContext. - return {"title": "Authentication summary", "type": "object"} + return { + "title": "Authentication summary", + "type": "object", + "additionalProperties": True, + } @register_static_variable("auth_type") @@ -293,7 +297,7 @@ def as_json_schema(): "title": "Legal subject authentication type", "description": ( "Authentication type of the legal subject (mandated to act on behalf " - "of the representee)", + "of the representee)" ), "type": "string", } @@ -316,7 +320,7 @@ def as_json_schema(): "title": "Legal subject authentication identifier", "description": ( "Authentication identifier of the legal subject (mandated to act on " - "behalf of the representee)", + "behalf of the representee)" ), "type": "string", } diff --git a/src/openforms/authentication/tests/test_static_variables.py b/src/openforms/authentication/tests/test_static_variables.py index 271a3ecd08..c91afcd614 100644 --- a/src/openforms/authentication/tests/test_static_variables.py +++ b/src/openforms/authentication/tests/test_static_variables.py @@ -2,7 +2,28 @@ from django.test import TestCase +from jsonschema.validators import Draft202012Validator + from openforms.authentication.constants import AuthAttribute +from openforms.authentication.static_variables.static_variables import ( + Auth, + AuthBSN, + AuthContext, + AuthContextActingSubjectIdentifier, + AuthContextActingSubjectIdentifierType, + AuthContextBranchNumber, + AuthContextLegalSubjectIdentifier, + AuthContextLegalSubjectIdentifierType, + AuthContextLOA, + AuthContextRepresenteeIdentifier, + AuthContextRepresenteeType, + AuthContextSource, + AuthKvK, + AuthPseudo, + AuthType, + LanguageCode, + SubmissionID, +) from openforms.authentication.tests.factories import AuthInfoFactory from openforms.submissions.tests.factories import SubmissionFactory from openforms.variables.service import get_static_variables @@ -134,3 +155,84 @@ def test_branch_number_variable(self): } self.assertEqual(static_data["auth_context_branch_number"], expected) + + +class StaticVariableValidJsonSchemaTests(TestCase): + + validator = Draft202012Validator + + def check_schema(self, properties): + schema = { + "$schema": self.validator.META_SCHEMA["$id"], + **properties, + } + + self.validator.check_schema(schema) + + def test_submission_id(self): + schema = SubmissionID.as_json_schema() + self.check_schema(schema) + + def test_language_code(self): + schema = LanguageCode.as_json_schema() + self.check_schema(schema) + + def test_auth(self): + schema = Auth.as_json_schema() + self.check_schema(schema) + + def test_auth_type(self): + schema = AuthType.as_json_schema() + self.check_schema(schema) + + def test_auth_bsn(self): + schema = AuthBSN.as_json_schema() + self.check_schema(schema) + + def test_auth_kvk(self): + schema = AuthKvK.as_json_schema() + self.check_schema(schema) + + def test_auth_pseudo(self): + schema = AuthPseudo.as_json_schema() + self.check_schema(schema) + + def test_auth_context(self): + schema = AuthContext.as_json_schema() + self.check_schema(schema) + + def test_auth_context_source(self): + schema = AuthContextSource.as_json_schema() + self.check_schema(schema) + + def test_auth_context_loa(self): + schema = AuthContextLOA.as_json_schema() + self.check_schema(schema) + + def test_auth_context_representee_type(self): + schema = AuthContextRepresenteeType.as_json_schema() + self.check_schema(schema) + + def test_auth_context_representee_identifier(self): + schema = AuthContextRepresenteeIdentifier.as_json_schema() + self.check_schema(schema) + + def test_auth_context_legal_subject_identifier_type(self): + schema = AuthContextLegalSubjectIdentifierType.as_json_schema() + self.check_schema(schema) + + def test_auth_context_legal_subject_identifier(self): + schema = AuthContextLegalSubjectIdentifier.as_json_schema() + self.check_schema(schema) + + def test_auth_context_branch_number(self): + schema = AuthContextBranchNumber.as_json_schema() + self.check_schema(schema) + + def test_auth_context_acting_subject_identifier_type(self): + schema = AuthContextActingSubjectIdentifierType.as_json_schema() + self.check_schema(schema) + + def test_auth_context_acting_subject_identifier(self): + schema = AuthContextActingSubjectIdentifier.as_json_schema() + self.check_schema(schema) diff --git a/src/openforms/formio/components/utils.py b/src/openforms/formio/components/utils.py index c978207424..9a1427a7c3 100644 --- a/src/openforms/formio/components/utils.py +++ b/src/openforms/formio/components/utils.py @@ -4,6 +4,7 @@ from ..typing import Component + def _normalize_pattern(pattern: str) -> str: """ Normalize a regex pattern so that it matches from beginning to the end of the value. diff --git a/src/openforms/formio/tests/test_component_json_schemas.py b/src/openforms/formio/tests/test_component_json_schemas.py index d44cfb4eb6..eda904fad6 100644 --- a/src/openforms/formio/tests/test_component_json_schemas.py +++ b/src/openforms/formio/tests/test_component_json_schemas.py @@ -33,6 +33,7 @@ from openforms.formio.typing import ( AddressNLComponent, Component, + ContentComponent, DateComponent, DatetimeComponent, EditGridComponent, @@ -45,7 +46,7 @@ ) -class ComponentValidJsonSchemaTestsMixin(TestCase): +class ComponentValidJsonSchemaTests(TestCase): validator = Draft202012Validator def check_schema(self, properties): @@ -80,7 +81,7 @@ def test_checkbox(self): def test_content(self): component_class = Content - component = { + component: ContentComponent = { "label": "Content", "key": "content", "html": "ASDF", @@ -303,13 +304,14 @@ def test_postcode(self): class RadioTests(TestCase): def test_manual_data_source(self): - component = { + component: RadioComponent = { "label": "Radio label", "key": "radio", "values": [ {"label": "A", "value": "a"}, {"label": "B", "value": "b"}, ], + "type": "radio", } expected_schema = { @@ -321,13 +323,14 @@ def test_manual_data_source(self): self.assertEqual(expected_schema, schema) def test_data_source_is_another_form_variable(self): - component = { + component: RadioComponent = { "label": "Radio label", "key": "radio", "values": [ {"label": "", "value": ""}, ], "openForms": {"dataSrc": "variable"}, + "type": "radio", } expected_schema = {"title": "Radio label", "type": "string"} @@ -335,11 +338,10 @@ def test_data_source_is_another_form_variable(self): self.assertEqual(expected_schema, schema) - class SelectTests(TestCase): def test_manual_data_source(self): - component = { + component: SelectComponent = { "label": "Select label", "key": "select", "data": { @@ -353,7 +355,9 @@ def test_manual_data_source(self): with self.subTest("single"): expected_schema = { - "title": "Select label", "type": "string", "enum": ["a", "b", ""] + "title": "Select label", + "type": "string", + "enum": ["a", "b", ""], } schema = Select.as_json_schema(component) self.assertEqual(schema, expected_schema) @@ -369,7 +373,7 @@ def test_manual_data_source(self): self.assertEqual(schema, expected_schema) def test_data_source_is_another_form_variable(self): - component = { + component: SelectComponent = { "label": "Select label", "key": "select", "data": { @@ -389,7 +393,9 @@ def test_data_source_is_another_form_variable(self): with self.subTest("multiple"): component["multiple"] = True expected_schema = { - "title": "Select label", "type": "array", "items": {"type": "string"} + "title": "Select label", + "type": "array", + "items": {"type": "string"}, } schema = Select.as_json_schema(component) self.assertEqual(schema, expected_schema) @@ -397,13 +403,14 @@ def test_data_source_is_another_form_variable(self): class SelectBoxesTests(TestCase): def test_manual_data_source(self): - component = { + component: SelectBoxesComponent = { "label": "Select boxes label", "key": "selectBoxes", "values": [ {"label": "A", "value": "a"}, {"label": "B", "value": "b"}, - ] + ], + "type": "selectboxes", } expected_schema = { @@ -420,17 +427,20 @@ def test_manual_data_source(self): self.assertEqual(schema, expected_schema) def test_data_source_is_another_form_variable(self): - component = { + component: SelectBoxesComponent = { "label": "Select boxes label", "key": "selectBoxes", "values": [ {"label": "", "value": ""}, ], "openForms": {"dataSrc": "variable"}, + "type": "selectboxes", } expected_schema = { - "title": "Select boxes label", "type": "object", "additionalProperties": True + "title": "Select boxes label", + "type": "object", + "additionalProperties": True, } schema = SelectBoxes.as_json_schema(component) self.assertEqual(schema, expected_schema) diff --git a/src/openforms/forms/tests/test_form_to_json_schema.py b/src/openforms/forms/tests/test_form_to_json_schema.py index 99262eba83..032a4c1a7d 100644 --- a/src/openforms/forms/tests/test_form_to_json_schema.py +++ b/src/openforms/forms/tests/test_form_to_json_schema.py @@ -4,12 +4,18 @@ FormDefinitionFactory, FormFactory, FormStepFactory, + FormVariableFactory, ) -from openforms.forms.utils import form_variables_to_json_schema +from openforms.forms.utils import ( + form_variables_to_json_schema, + get_json_schema_from_form_variable, + is_form_variable_required, +) +from openforms.variables.constants import FormVariableDataTypes, FormVariableSources class FormToJsonSchemaTestCase(TestCase): - def test_form_to_json_schema(self): + def test_correct_variables_included_in_schema(self): form = FormFactory.create() form_def_1 = FormDefinitionFactory.create( configuration={ @@ -59,16 +65,26 @@ def test_form_to_json_schema(self): ] } ) - form_step_1 = FormStepFactory.create(form=form, form_definition=form_def_1) + FormStepFactory.create(form=form, form_definition=form_def_1) form_def_2 = FormDefinitionFactory.create( configuration={ "components": [ - {"key": "file", "type": "file", "label": "File"}, + { + "key": "file", + "type": "file", + "label": "File", + "validate": {"required": True}, + }, + { + "key": "notIncluded", + "type": "textfield", + "label": "Not included text field", + }, ] } ) - form_step_2 = FormStepFactory.create(form=form, form_definition=form_def_2) + FormStepFactory.create(form=form, form_definition=form_def_2) vars_to_include = ( "firstName", @@ -81,3 +97,107 @@ def test_form_to_json_schema(self): "today", ) schema = form_variables_to_json_schema(form, vars_to_include) + + self.assertEqual(set(schema["properties"]), set(vars_to_include)) + self.assertEqual(schema["required"], ["auth_bsn", "today", "file"]) + + +# TODO-4980: add to variables app if get_json_schema_from_form_variable is moved to +# FormVariable +class TestGetJsonSchemaFromFormVariableTests(TestCase): + + def test_component(self): + form = FormFactory.create() + form_def = FormDefinitionFactory.create( + configuration={ + "components": [ + { + "key": "textfield", + "type": "textfield", + "label": "Foo", + "source": FormVariableSources.component, + }, + ] + } + ) + FormStepFactory.create(form=form, form_definition=form_def) + + var = form_def.formvariable_set.first() + schema = get_json_schema_from_form_variable(var) + + expected_schema = {"title": "Foo", "type": "string"} + self.assertEqual(schema, expected_schema) + + def test_user_defined(self): + var = FormVariableFactory.create( + name="Foo", + key="foo", + source=FormVariableSources.user_defined, + data_type=FormVariableDataTypes.array, + initial_value=["A", "B", "C"], + ) + + schema = get_json_schema_from_form_variable(var) + + expected_schema = {"title": "Foo", "type": "array"} + self.assertEqual(schema, expected_schema) + + +# TODO-4980: add to variables app if is_form_variable_required is moved toFormVariable +class TestIsFormVariableRequired(TestCase): + + def test_component_default(self): + form = FormFactory.create() + form_def = FormDefinitionFactory.create( + configuration={ + "components": [ + { + "key": "textfield", + "type": "textfield", + "label": "Foo", + "source": FormVariableSources.component, + }, + ] + } + ) + FormStepFactory.create(form=form, form_definition=form_def) + + var = form_def.formvariable_set.first() + required = is_form_variable_required(var) + + self.assertFalse(required) + + def test_component_required(self): + form = FormFactory.create() + form_def = FormDefinitionFactory.create( + configuration={ + "components": [ + { + "key": "textfield", + "type": "textfield", + "label": "Foo", + "source": FormVariableSources.component, + "validate": {"required": True}, + }, + ] + } + ) + FormStepFactory.create(form=form, form_definition=form_def) + + var = form_def.formvariable_set.first() + required = is_form_variable_required(var) + + self.assertTrue(required) + + def test_user_defined(self): + var = FormVariableFactory.create( + name="Foo", + key="foo", + source=FormVariableSources.user_defined, + data_type=FormVariableDataTypes.array, + initial_value=["A", "B", "C"], + ) + + required = is_form_variable_required(var) + + self.assertTrue(required) diff --git a/src/openforms/forms/tests/variables/test_variables_in_logic_trigger.py b/src/openforms/forms/tests/variables/test_variables_in_logic_trigger.py index 7679421f6c..cff8d06ec5 100644 --- a/src/openforms/forms/tests/variables/test_variables_in_logic_trigger.py +++ b/src/openforms/forms/tests/variables/test_variables_in_logic_trigger.py @@ -22,6 +22,10 @@ class DemoNow(BaseStaticVariable): def get_initial_value(self, *args, **kwargs): return "2021-07-16T21:15:00+00:00" + @staticmethod + def as_json_schema(): + return {} + class DemoAuth(BaseStaticVariable): name = "Authentication identifier" @@ -34,6 +38,10 @@ def get_initial_value(self, *args, **kwargs): "value": "123456782", } + @staticmethod + def as_json_schema(): + return {} + register = Registry() register("now")(DemoNow) diff --git a/src/openforms/forms/utils.py b/src/openforms/forms/utils.py index 917f660509..06a684c9a8 100644 --- a/src/openforms/forms/utils.py +++ b/src/openforms/forms/utils.py @@ -202,7 +202,7 @@ def get_json_schema_from_form_variable(form_variable: FormVariable) -> JSONObjec case FormVariableSources.user_defined: schema = get_json_schema_for_user_defined_variable(form_variable.data_type) schema["title"] = form_variable.name - case _: + case _: # pragma: no cover raise NotImplementedError("Unexpected form variable source") return schema @@ -226,7 +226,7 @@ def is_form_variable_required(form_variable: FormVariable) -> bool: case FormVariableSources.user_defined: # User defined variables have no required property required = True - case _: + case _: # pragma: no cover raise NotImplementedError("Unexpected form variable source") return required diff --git a/src/openforms/registrations/contrib/json_dump/plugin.py b/src/openforms/registrations/contrib/json_dump/plugin.py index 3dc9cdc0e1..cad7509eb9 100644 --- a/src/openforms/registrations/contrib/json_dump/plugin.py +++ b/src/openforms/registrations/contrib/json_dump/plugin.py @@ -7,8 +7,8 @@ from zgw_consumers.client import build_client -from openforms.formio.dynamic_config import rewrite_formio_components from openforms.formio.components.utils import to_multiple +from openforms.formio.dynamic_config import rewrite_formio_components from openforms.formio.typing import Component from openforms.forms.utils import form_variables_to_json_schema from openforms.submissions.logic.datastructures import DataContainer @@ -183,7 +183,7 @@ def post_processing( options["value"]: {"type": "boolean"} for options in component["values"] } - schema["properties"][variable.key].update( + schema["properties"][key].update( { "properties": properties, "required": list(properties.keys()), @@ -194,7 +194,7 @@ def post_processing( # If the select boxes component is not filled, set required # properties to empty list if not values[key]: - schema["properties"][variable.key]["required"] = list() + schema["properties"][key]["required"] = list() case _: pass @@ -211,7 +211,7 @@ def encode_attachment(attachment: SubmissionFileAttachment) -> str: def get_component( - variable: SubmissionValueVariable, submission : Submission + variable: SubmissionValueVariable, submission: Submission ) -> Component | None: """Get the component from a submission value variable. 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 874b327225..65c358a4d6 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 @@ -2,22 +2,22 @@ interactions: - request: 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\": {\"type\": \"string\", \"contentEncoding\": - \"base64\"}}, \"required\": [\"static_var_1\", \"form_var_1\", \"form_var_2\"], - \"additionalProperties\": false}}"' + \"type\": \"object\", \"properties\": {\"auth_bsn\": {\"title\": \"BSN\", \"description\": + \"Uniquely identifies the authenticated person. This value follows the rules + for Dutch social security numbers.\", \"type\": \"string\", \"pattern\": \"^\\\\d{9}$\", + \"format\": \"nl-bsn\"}, \"firstName\": {\"title\": \"Firstname\", \"type\": + \"string\"}}, \"required\": [\"auth_bsn\"], \"additionalProperties\": false}}"' headers: Accept: - '*/*' Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ Connection: - keep-alive Content-Length: - - '516' + - '560' Content-Type: - application/json User-Agent: @@ -46,7 +46,7 @@ interactions: Content-Type: - text/html; charset=utf-8 Date: - - Tue, 21 Jan 2025 14:31:40 GMT + - Wed, 22 Jan 2025 11:44:57 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_multiple_file_uploads.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_multiple_file_uploads.yaml index da0de50808..f4d801d281 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_multiple_file_uploads.yaml +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_multiple_file_uploads.yaml @@ -3,22 +3,22 @@ interactions: body: '"{\"values\": {\"file\": [{\"file_name\": \"file1.txt\", \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\"}, {\"file_name\": \"file2.txt\", \"content\": \"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\": [\"static_var_1\", \"form_var_1\", \"form_var_2\"], - \"additionalProperties\": false}}"' + \"type\": \"object\", \"properties\": {\"file\": {\"title\": \"File\", \"type\": + \"array\", \"items\": {\"type\": \"object\", \"properties\": {\"file_name\": + {\"type\": \"string\"}, \"content\": {\"type\": \"string\", \"format\": \"base64\"}}, + \"required\": [\"file_name\", \"content\"], \"additionalProperties\": false}}}, + \"required\": [], \"additionalProperties\": false}}"' headers: Accept: - '*/*' Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ Connection: - keep-alive Content-Length: - - '638' + - '646' Content-Type: - application/json User-Agent: @@ -28,14 +28,16 @@ interactions: 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 \"file\": [\n {\n \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n + \ \"additionalProperties\": false,\n \"properties\": {\n \"file\": + {\n \"items\": {\n \"additionalProperties\": false,\n + \ \"properties\": {\n \"content\": {\n \"format\": + \"base64\",\n \"type\": \"string\"\n },\n \"file_name\": + {\n \"type\": \"string\"\n }\n },\n + \ \"required\": [\n \"file_name\",\n \"content\"\n + \ ],\n \"type\": \"object\"\n },\n \"title\": + \"File\",\n \"type\": \"array\"\n }\n },\n \"required\": + [],\n \"type\": \"object\"\n },\n \"values\": {\n \"file\": + [\n {\n \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n \ \"file_name\": \"file1.txt\"\n },\n {\n \"content\": \"Q29udGVudCBleGFtcGxlIGlzIHRoaXMu\",\n \"file_name\": \"file2.txt\"\n \ }\n ]\n }\n },\n \"message\": \"Data received\"\n}\n" @@ -43,11 +45,11 @@ interactions: Connection: - close Content-Length: - - '923' + - '1035' Content-Type: - application/json Date: - - Tue, 21 Jan 2025 14:31:40 GMT + - Wed, 22 Jan 2025 11:44:57 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_no_file_upload_for_multiple_files_component.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_no_file_upload_for_multiple_files_component.yaml index af4ae5be94..8230b63760 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_no_file_upload_for_multiple_files_component.yaml +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_no_file_upload_for_multiple_files_component.yaml @@ -1,22 +1,22 @@ interactions: - request: body: '"{\"values\": {\"file\": []}, \"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}}"' + \"type\": \"object\", \"properties\": {\"file\": {\"title\": \"File\", \"type\": + \"array\", \"items\": {\"type\": \"object\", \"properties\": {\"file_name\": + {\"type\": \"string\"}, \"content\": {\"type\": \"string\", \"format\": \"base64\"}}, + \"required\": [], \"additionalProperties\": false}}}, \"required\": [], \"additionalProperties\": + false}}"' headers: Accept: - '*/*' Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ Connection: - keep-alive Content-Length: - - '474' + - '456' Content-Type: - application/json User-Agent: @@ -26,23 +26,24 @@ interactions: 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\": + \ \"additionalProperties\": false,\n \"properties\": {\n \"file\": + {\n \"items\": {\n \"additionalProperties\": false,\n + \ \"properties\": {\n \"content\": {\n \"format\": + \"base64\",\n \"type\": \"string\"\n },\n \"file_name\": + {\n \"type\": \"string\"\n }\n },\n + \ \"required\": [],\n \"type\": \"object\"\n },\n + \ \"title\": \"File\",\n \"type\": \"array\"\n }\n + \ },\n \"required\": [],\n \"type\": \"object\"\n },\n \"values\": {\n \"file\": []\n }\n },\n \"message\": \"Data received\"\n}\n" headers: Connection: - close Content-Length: - - '691' + - '739' Content-Type: - application/json Date: - - Tue, 21 Jan 2025 14:31:40 GMT + - Wed, 22 Jan 2025 11:44:57 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_no_file_upload_for_single_file_component.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_no_file_upload_for_single_file_component.yaml index 55f07cc3d8..85cee1bd43 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_no_file_upload_for_single_file_component.yaml +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_no_file_upload_for_single_file_component.yaml @@ -1,22 +1,19 @@ interactions: - request: body: '"{\"values\": {\"file\": null}, \"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}}"' + \"type\": \"object\", \"properties\": {\"file\": {\"title\": \"File\", \"type\": + \"null\"}}, \"required\": [], \"additionalProperties\": false}}"' headers: Accept: - '*/*' Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ Connection: - keep-alive Content-Length: - - '476' + - '253' Content-Type: - application/json User-Agent: @@ -26,23 +23,19 @@ interactions: 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\": + \ \"additionalProperties\": false,\n \"properties\": {\n \"file\": + {\n \"title\": \"File\",\n \"type\": \"null\"\n }\n + \ },\n \"required\": [],\n \"type\": \"object\"\n },\n \"values\": {\n \"file\": null\n }\n },\n \"message\": \"Data received\"\n}\n" headers: Connection: - close Content-Length: - - '693' + - '372' Content-Type: - application/json Date: - - Tue, 21 Jan 2025 14:31:40 GMT + - Wed, 22 Jan 2025 11:44:57 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_one_file_upload_for_multiple_files_component.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_one_file_upload_for_multiple_files_component.yaml index b129859841..b2ad5d6643 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_one_file_upload_for_multiple_files_component.yaml +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_one_file_upload_for_multiple_files_component.yaml @@ -2,22 +2,22 @@ interactions: - request: body: '"{\"values\": {\"file\": [{\"file_name\": \"file1.txt\", \"content\": \"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}}"' + \"type\": \"object\", \"properties\": {\"file\": {\"title\": \"File\", \"type\": + \"array\", \"items\": {\"type\": \"object\", \"properties\": {\"file_name\": + {\"type\": \"string\"}, \"content\": {\"type\": \"string\", \"format\": \"base64\"}}, + \"required\": [\"file_name\", \"content\"], \"additionalProperties\": false}}}, + \"required\": [], \"additionalProperties\": false}}"' headers: Accept: - '*/*' Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ Connection: - keep-alive Content-Length: - - '555' + - '563' Content-Type: - application/json User-Agent: @@ -27,25 +27,27 @@ interactions: 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 \"file\": [\n {\n \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n + \ \"additionalProperties\": false,\n \"properties\": {\n \"file\": + {\n \"items\": {\n \"additionalProperties\": false,\n + \ \"properties\": {\n \"content\": {\n \"format\": + \"base64\",\n \"type\": \"string\"\n },\n \"file_name\": + {\n \"type\": \"string\"\n }\n },\n + \ \"required\": [\n \"file_name\",\n \"content\"\n + \ ],\n \"type\": \"object\"\n },\n \"title\": + \"File\",\n \"type\": \"array\"\n }\n },\n \"required\": + [],\n \"type\": \"object\"\n },\n \"values\": {\n \"file\": + [\n {\n \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n \ \"file_name\": \"file1.txt\"\n }\n ]\n }\n },\n \ \"message\": \"Data received\"\n}\n" headers: Connection: - close Content-Length: - - '810' + - '922' Content-Type: - application/json Date: - - Tue, 21 Jan 2025 14:31:40 GMT + - Wed, 22 Jan 2025 11:44:57 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_radio_component_with_form_variable_as_data_source.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_radio_component_with_form_variable_as_data_source.yaml new file mode 100644 index 0000000000..71cd5c573c --- /dev/null +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_radio_component_with_form_variable_as_data_source.yaml @@ -0,0 +1,47 @@ +interactions: +- request: + body: '"{\"values\": {\"radio\": \"A\"}, \"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", + \"type\": \"object\", \"properties\": {\"radio\": {\"title\": \"Radio\", \"type\": + \"string\", \"enum\": [\"A\", \"B\", \"C\", \"\"]}}, \"required\": [], \"additionalProperties\": + false}}"' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ + Connection: + - keep-alive + Content-Length: + - '298' + 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 \"radio\": + {\n \"enum\": [\n \"A\",\n \"B\",\n \"C\",\n + \ \"\"\n ],\n \"title\": \"Radio\",\n \"type\": + \"string\"\n }\n },\n \"required\": [],\n \"type\": + \"object\"\n },\n \"values\": {\n \"radio\": \"A\"\n }\n },\n + \ \"message\": \"Data received\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '475' + Content-Type: + - application/json + Date: + - Wed, 22 Jan 2025 11:44:57 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/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_radio_component_with_manual_data_source.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_radio_component_with_manual_data_source.yaml new file mode 100644 index 0000000000..85e2a01f9f --- /dev/null +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_radio_component_with_manual_data_source.yaml @@ -0,0 +1,47 @@ +interactions: +- request: + body: '"{\"values\": {\"radio\": \"b\"}, \"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", + \"type\": \"object\", \"properties\": {\"radio\": {\"title\": \"Radio\", \"type\": + \"string\", \"enum\": [\"a\", \"b\", \"c\", \"\"]}}, \"required\": [], \"additionalProperties\": + false}}"' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ + Connection: + - keep-alive + Content-Length: + - '298' + 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 \"radio\": + {\n \"enum\": [\n \"a\",\n \"b\",\n \"c\",\n + \ \"\"\n ],\n \"title\": \"Radio\",\n \"type\": + \"string\"\n }\n },\n \"required\": [],\n \"type\": + \"object\"\n },\n \"values\": {\n \"radio\": \"b\"\n }\n },\n + \ \"message\": \"Data received\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '475' + Content-Type: + - application/json + Date: + - Wed, 22 Jan 2025 11:44:57 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/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_boxes_component_with_form_variable_as_data_source.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_boxes_component_with_form_variable_as_data_source.yaml new file mode 100644 index 0000000000..9e73632635 --- /dev/null +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_boxes_component_with_form_variable_as_data_source.yaml @@ -0,0 +1,55 @@ +interactions: +- request: + body: '"{\"values\": {\"selectBoxes\": {\"A\": true, \"B\": false, \"C\": true}}, + \"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", + \"type\": \"object\", \"properties\": {\"selectBoxes\": {\"title\": \"Select + Boxes\", \"type\": \"object\", \"additionalProperties\": false, \"properties\": + {\"A\": {\"type\": \"boolean\"}, \"B\": {\"type\": \"boolean\"}, \"C\": {\"type\": + \"boolean\"}}, \"required\": [\"A\", \"B\", \"C\"]}}, \"required\": [], \"additionalProperties\": + false}}"' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ + Connection: + - keep-alive + Content-Length: + - '497' + 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 \"selectBoxes\": + {\n \"additionalProperties\": false,\n \"properties\": {\n + \ \"A\": {\n \"type\": \"boolean\"\n },\n + \ \"B\": {\n \"type\": \"boolean\"\n },\n + \ \"C\": {\n \"type\": \"boolean\"\n }\n + \ },\n \"required\": [\n \"A\",\n \"B\",\n + \ \"C\"\n ],\n \"title\": \"Select Boxes\",\n + \ \"type\": \"object\"\n }\n },\n \"required\": [],\n + \ \"type\": \"object\"\n },\n \"values\": {\n \"selectBoxes\": + {\n \"A\": true,\n \"B\": false,\n \"C\": true\n }\n + \ }\n },\n \"message\": \"Data received\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '822' + Content-Type: + - application/json + Date: + - Wed, 22 Jan 2025 11:44:57 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/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_boxes_schema_required_is_empty_when_no_data_is_submitted.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_boxes_schema_required_is_empty_when_no_data_is_submitted.yaml new file mode 100644 index 0000000000..1c19124990 --- /dev/null +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_boxes_schema_required_is_empty_when_no_data_is_submitted.yaml @@ -0,0 +1,50 @@ +interactions: +- request: + body: '"{\"values\": {\"selectboxes\": {}}, \"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", + \"type\": \"object\", \"properties\": {\"selectboxes\": {\"title\": \"Selectboxes\", + \"type\": \"object\", \"properties\": {\"option1\": {\"type\": \"boolean\"}, + \"option2\": {\"type\": \"boolean\"}}, \"required\": [], \"additionalProperties\": + false}}, \"required\": [], \"additionalProperties\": false}}"' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ + Connection: + - keep-alive + Content-Length: + - '419' + 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 \"selectboxes\": + {\n \"additionalProperties\": false,\n \"properties\": {\n + \ \"option1\": {\n \"type\": \"boolean\"\n },\n + \ \"option2\": {\n \"type\": \"boolean\"\n }\n + \ },\n \"required\": [],\n \"title\": \"Selectboxes\",\n + \ \"type\": \"object\"\n }\n },\n \"required\": [],\n + \ \"type\": \"object\"\n },\n \"values\": {\n \"selectboxes\": + {}\n }\n },\n \"message\": \"Data received\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '642' + Content-Type: + - application/json + Date: + - Wed, 22 Jan 2025 11:44:57 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/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_component_with_form_variable_as_data_source.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_component_with_form_variable_as_data_source.yaml new file mode 100644 index 0000000000..e44c52337b --- /dev/null +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_component_with_form_variable_as_data_source.yaml @@ -0,0 +1,49 @@ +interactions: +- request: + body: '"{\"values\": {\"select\": [\"A\", \"C\"]}, \"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", + \"type\": \"object\", \"properties\": {\"select\": {\"type\": \"array\", \"items\": + {\"type\": \"string\", \"enum\": [\"A\", \"B\", \"C\", \"\"]}, \"title\": \"Select\"}}, + \"required\": [], \"additionalProperties\": false}}"' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ + Connection: + - keep-alive + Content-Length: + - '344' + 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 \"select\": + {\n \"items\": {\n \"enum\": [\n \"A\",\n + \ \"B\",\n \"C\",\n \"\"\n ],\n + \ \"type\": \"string\"\n },\n \"title\": \"Select\",\n + \ \"type\": \"array\"\n }\n },\n \"required\": [],\n + \ \"type\": \"object\"\n },\n \"values\": {\n \"select\": [\n + \ \"A\",\n \"C\"\n ]\n }\n },\n \"message\": \"Data + received\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '583' + Content-Type: + - application/json + Date: + - Wed, 22 Jan 2025 11:44:57 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/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_component_with_manual_data_source.yaml b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_component_with_manual_data_source.yaml new file mode 100644 index 0000000000..9a1789325c --- /dev/null +++ b/src/openforms/registrations/contrib/json_dump/tests/files/vcr_cassettes/JSONDumpBackendTests/JSONDumpBackendTests.test_select_component_with_manual_data_source.yaml @@ -0,0 +1,49 @@ +interactions: +- request: + body: '"{\"values\": {\"select\": [\"a\", \"c\"]}, \"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\", + \"type\": \"object\", \"properties\": {\"select\": {\"type\": \"array\", \"items\": + {\"type\": \"string\", \"enum\": [\"a\", \"b\", \"c\", \"\"]}, \"title\": \"Select\"}}, + \"required\": [], \"additionalProperties\": false}}"' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ + Connection: + - keep-alive + Content-Length: + - '344' + 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 \"select\": + {\n \"items\": {\n \"enum\": [\n \"a\",\n + \ \"b\",\n \"c\",\n \"\"\n ],\n + \ \"type\": \"string\"\n },\n \"title\": \"Select\",\n + \ \"type\": \"array\"\n }\n },\n \"required\": [],\n + \ \"type\": \"object\"\n },\n \"values\": {\n \"select\": [\n + \ \"a\",\n \"c\"\n ]\n }\n },\n \"message\": \"Data + received\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '583' + Content-Type: + - application/json + Date: + - Wed, 22 Jan 2025 11:44:57 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/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 index 7eb76f66a9..9073fa7ef4 100644 --- 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 @@ -3,22 +3,25 @@ interactions: body: '"{\"values\": {\"auth_bsn\": \"123456789\", \"firstName\": \"We Are\", \"file\": {\"file_name\": \"test_file.txt\", \"content\": \"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}}"' + \"type\": \"object\", \"properties\": {\"auth_bsn\": {\"title\": \"BSN\", \"description\": + \"Uniquely identifies the authenticated person. This value follows the rules + for Dutch social security numbers.\", \"type\": \"string\", \"pattern\": \"^\\\\d{9}$\", + \"format\": \"nl-bsn\"}, \"firstName\": {\"title\": \"Firstname\", \"type\": + \"string\"}, \"file\": {\"title\": \"File\", \"type\": \"object\", \"properties\": + {\"file_name\": {\"type\": \"string\"}, \"content\": {\"type\": \"string\", + \"format\": \"base64\"}}, \"required\": [\"file_name\", \"content\"], \"additionalProperties\": + false}}, \"required\": [\"auth_bsn\"], \"additionalProperties\": false}}"' headers: Accept: - '*/*' Accept-Encoding: - gzip, deflate, br Authorization: - - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc1NDYyOTcsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.RexAuQ6PNjAdp5DtEcz2dtcPXNknP0WnjZKKnr-LQEQ Connection: - keep-alive Content-Length: - - '613' + - '907' Content-Type: - application/json User-Agent: @@ -28,13 +31,19 @@ interactions: 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\": + \ \"additionalProperties\": false,\n \"properties\": {\n \"auth_bsn\": + {\n \"description\": \"Uniquely identifies the authenticated person. + This value follows the rules for Dutch social security numbers.\",\n \"format\": + \"nl-bsn\",\n \"pattern\": \"^\\\\d{9}$\",\n \"title\": + \"BSN\",\n \"type\": \"string\"\n },\n \"file\": {\n + \ \"additionalProperties\": false,\n \"properties\": {\n + \ \"content\": {\n \"format\": \"base64\",\n \"type\": + \"string\"\n },\n \"file_name\": {\n \"type\": + \"string\"\n }\n },\n \"required\": [\n \"file_name\",\n + \ \"content\"\n ],\n \"title\": \"File\",\n \"type\": + \"object\"\n },\n \"firstName\": {\n \"title\": \"Firstname\",\n + \ \"type\": \"string\"\n }\n },\n \"required\": [\n + \ \"auth_bsn\"\n ],\n \"type\": \"object\"\n },\n \"values\": {\n \"auth_bsn\": \"123456789\",\n \"file\": {\n \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n \"file_name\": \"test_file.txt\"\n \ },\n \"firstName\": \"We Are\"\n }\n },\n \"message\": \"Data @@ -43,11 +52,11 @@ interactions: Connection: - close Content-Length: - - '850' + - '1278' Content-Type: - application/json Date: - - Tue, 21 Jan 2025 14:31:40 GMT + - Wed, 22 Jan 2025 11:44:57 GMT Server: - Werkzeug/3.1.3 Python/3.12.8 status: 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 f549f82c00..33142dd0d5 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/test_backend.py +++ b/src/openforms/registrations/contrib/json_dump/tests/test_backend.py @@ -218,13 +218,17 @@ def test_multiple_file_uploads(self): "type": "object", "properties": { "file": { - "type": "object", - "properties": { - "file1.txt": {"type": "string", "format": "base64"}, - "file2.txt": {"type": "string", "format": "base64"}, + "title": "File", + "type": "array", + "items": { + "type": "object", + "properties": { + "file_name": {"type": "string"}, + "content": {"type": "string", "format": "base64"}, + }, + "required": ["file_name", "content"], + "additionalProperties": False, }, - "required": ["file1.txt", "file2.txt"], - "additionalProperties": False, } }, "additionalProperties": False, @@ -275,15 +279,39 @@ def test_one_file_upload_for_multiple_files_component(self): result = json_plugin.register_submission(submission, options) assert result is not None - self.assertEqual( - result["api_response"]["data"]["values"]["file"], - [ - { - "file_name": "file1.txt", - "content": "VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu", # This is example content. - } - ], - ) + expected_data = { + "values": { + "file": [ + { + "file_name": "file1.txt", + "content": "VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu", # This is example content. + }, + ], + }, + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "file": { + "title": "File", + "type": "array", + "items": { + "type": "object", + "properties": { + "file_name": {"type": "string"}, + "content": {"type": "string", "format": "base64"}, + }, + "required": ["file_name", "content"], + "additionalProperties": False, + }, + } + }, + "additionalProperties": False, + "required": [], + }, + } + + self.assertEqual(result["api_response"]["data"], expected_data) def test_no_file_upload_for_single_file_component(self): submission = SubmissionFactory.from_components( @@ -305,7 +333,23 @@ def test_no_file_upload_for_single_file_component(self): result = json_plugin.register_submission(submission, options) assert result is not None - self.assertEqual(result["api_response"]["data"]["values"]["file"], None) + expected_data = { + "values": {"file": None}, + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "file": { + "title": "File", + "type": "null", + }, + }, + "additionalProperties": False, + "required": [], + }, + } + + self.assertEqual(result["api_response"]["data"], expected_data) def test_no_file_upload_for_multiple_files_component(self): submission = SubmissionFactory.from_components( @@ -327,7 +371,32 @@ def test_no_file_upload_for_multiple_files_component(self): result = json_plugin.register_submission(submission, options) assert result is not None - self.assertEqual(result["api_response"]["data"]["values"]["file"], []) + expected_data = { + "values": {"file": []}, + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "file": { + "title": "File", + "type": "array", + "items": { + "type": "object", + "properties": { + "file_name": {"type": "string"}, + "content": {"type": "string", "format": "base64"}, + }, + "required": [], + "additionalProperties": False, + }, + } + }, + "required": [], + "additionalProperties": False, + }, + } + + self.assertEqual(result["api_response"]["data"], expected_data) def test_path_traversal_attack(self): submission = SubmissionFactory.from_components( @@ -357,7 +426,7 @@ def test_path_traversal_attack(self): with self.assertRaises(SuspiciousOperation): json_plugin.register_submission(submission, options) - def test_required_in_schema_is_empty_if_select_boxes_component_unfilled(self): + def test_select_boxes_schema_required_is_empty_when_no_data_is_submitted(self): submission = SubmissionFactory.from_components( [ { @@ -371,20 +440,68 @@ def test_required_in_schema_is_empty_if_select_boxes_component_unfilled(self): ], completed=True, submitted_data={"selectboxes": {}}, + with_public_registration_reference=True, ) json_plugin = JSONDumpRegistration("json_registration_plugin") options: JSONDumpOptions = { "service": self.service, - "path": "..", + "path": "json_plugin", "variables": ["selectboxes"], } result = json_plugin.register_submission(submission, options) + assert result is not None self.assertEqual( - result["api_response"]["data"]["schema"]["properties"]["selectboxes"]["required"], - [] + result["api_response"]["data"]["schema"]["properties"]["selectboxes"][ + "required" + ], + [], + ) + + def test_select_component_with_manual_data_source(self): + submission = SubmissionFactory.from_components( + [ + { + "label": "Select", + "key": "select", + "type": "select", + "multiple": True, + "data": { + "values": [ + {"value": "a", "label": "A"}, + {"value": "b", "label": "B"}, + {"value": "c", "label": "C"}, + ], + "json": "", + "url": "", + "resource": "", + "custom": "", + }, + }, + ], + completed=True, + submitted_data={"select": ["a", "c"]}, + with_public_registration_reference=True, + ) + + json_plugin = JSONDumpRegistration("json_registration_plugin") + + json_form_options = { + "service": self.service, + "path": "json_plugin", + "variables": ["select"], + } + + result = json_plugin.register_submission(submission, json_form_options) + assert result is not None + + self.assertEqual( + result["api_response"]["data"]["schema"]["properties"]["select"]["items"][ + "enum" + ], + ["a", "b", "c", ""], ) def test_select_component_with_form_variable_as_data_source(self): @@ -411,6 +528,7 @@ def test_select_component_with_form_variable_as_data_source(self): ], completed=True, submitted_data={"select": ["A", "C"]}, + with_public_registration_reference=True, ) FormVariableFactory.create( @@ -423,18 +541,20 @@ def test_select_component_with_form_variable_as_data_source(self): ) json_plugin = JSONDumpRegistration("json_registration_plugin") - set_submission_reference(submission) - json_form_options = dict( - service=(ServiceFactory(api_root="http://localhost:80/")), - relative_api_endpoint="json_plugin", - form_variables=["select"], - ) + json_form_options = { + "service": self.service, + "path": "json_plugin", + "variables": ["select"], + } - res = json_plugin.register_submission(submission, json_form_options) + result = json_plugin.register_submission(submission, json_form_options) + assert result is not None self.assertEqual( - glom(res, "api_response.data.schema.properties.select.items.enum"), + result["api_response"]["data"]["schema"]["properties"]["select"]["items"][ + "enum" + ], ["A", "B", "C", ""], ) @@ -456,6 +576,7 @@ def test_select_boxes_component_with_form_variable_as_data_source(self): ], completed=True, submitted_data={"selectBoxes": {"A": True, "B": False, "C": True}}, + with_public_registration_reference=True, ) FormVariableFactory.create( @@ -468,15 +589,15 @@ def test_select_boxes_component_with_form_variable_as_data_source(self): ) json_plugin = JSONDumpRegistration("json_registration_plugin") - set_submission_reference(submission) - json_form_options = dict( - service=(ServiceFactory(api_root="http://localhost:80/")), - relative_api_endpoint="json_plugin", - form_variables=["selectBoxes"], - ) + json_form_options = { + "service": self.service, + "path": "json_plugin", + "variables": ["selectBoxes"], + } - res = json_plugin.register_submission(submission, json_form_options) + result = json_plugin.register_submission(submission, json_form_options) + assert result is not None expected_schema = { "title": "Select Boxes", @@ -491,17 +612,17 @@ def test_select_boxes_component_with_form_variable_as_data_source(self): } self.assertEqual( - glom(res, "api_response.data.schema.properties.selectBoxes"), - expected_schema + result["api_response"]["data"]["schema"]["properties"]["selectBoxes"], + expected_schema, ) - def test_select_boxes_schema_required_is_empty_when_no_data_is_submitted(self): + def test_radio_component_with_manual_data_source(self): submission = SubmissionFactory.from_components( [ { - "label": "Select Boxes", - "key": "selectBoxes", - "type": "selectboxes", + "label": "Radio", + "key": "radio", + "type": "radio", "values": [ {"label": "A", "value": "a"}, {"label": "B", "value": "b"}, @@ -510,23 +631,23 @@ def test_select_boxes_schema_required_is_empty_when_no_data_is_submitted(self): }, ], completed=True, - submitted_data={"selectBoxes": {}}, + submitted_data={"radio": "b"}, ) json_plugin = JSONDumpRegistration("json_registration_plugin") - set_submission_reference(submission) - json_form_options = dict( - service=(ServiceFactory(api_root="http://localhost:80/")), - relative_api_endpoint="json_plugin", - form_variables=["selectBoxes"], - ) + json_form_options = { + "service": self.service, + "path": "json_plugin", + "variables": ["radio"], + } - res = json_plugin.register_submission(submission, json_form_options) + result = json_plugin.register_submission(submission, json_form_options) + assert result is not None self.assertEqual( - glom(res, "api_response.data.schema.properties.selectBoxes.required"), - [], + result["api_response"]["data"]["schema"]["properties"]["radio"]["enum"], + ["a", "b", "c", ""], ) def test_radio_component_with_form_variable_as_data_source(self): @@ -546,6 +667,7 @@ def test_radio_component_with_form_variable_as_data_source(self): ], completed=True, submitted_data={"radio": "A"}, + with_public_registration_reference=True, ) FormVariableFactory.create( @@ -558,17 +680,17 @@ def test_radio_component_with_form_variable_as_data_source(self): ) json_plugin = JSONDumpRegistration("json_registration_plugin") - set_submission_reference(submission) - json_form_options = dict( - service=(ServiceFactory(api_root="http://localhost:80/")), - relative_api_endpoint="json_plugin", - form_variables=["radio"], - ) + json_form_options = { + "service": self.service, + "path": "json_plugin", + "variables": ["radio"], + } - res = json_plugin.register_submission(submission, json_form_options) + result = json_plugin.register_submission(submission, json_form_options) + assert result is not None self.assertEqual( - glom(res, "api_response.data.schema.properties.radio.enum"), + result["api_response"]["data"]["schema"]["properties"]["radio"]["enum"], ["A", "B", "C", ""], ) diff --git a/src/openforms/variables/service.py b/src/openforms/variables/service.py index 41b67c10c8..663dbd7f41 100644 --- a/src/openforms/variables/service.py +++ b/src/openforms/variables/service.py @@ -48,8 +48,7 @@ def get_static_variables( ] -# TODO-4980: where to add this? -# TODO-4980: add tests +# TODO-4980: can be combined with get_json_schema_from_form_variable? def get_json_schema_for_user_defined_variable( data_type: FormVariableDataTypes, ) -> JSONObject: @@ -77,5 +76,5 @@ def get_json_schema_for_user_defined_variable( return {"type": "string", "format": "date"} case FormVariableDataTypes.time: return {"type": "string", "format": "time"} - case _: + case _: # pragma: no cover raise NotImplementedError(f"Unrecognized data type: {data_type}") diff --git a/src/openforms/variables/tests/test_registry.py b/src/openforms/variables/tests/test_registry.py index af753efd5f..edc1f13276 100644 --- a/src/openforms/variables/tests/test_registry.py +++ b/src/openforms/variables/tests/test_registry.py @@ -18,6 +18,10 @@ class DemoVariable(BaseStaticVariable): def get_initial_value(self, *args, **kwargs): return "Test!" + @staticmethod + def as_json_schema(): + return {} + static_vars = list(test_static_variables_register) self.assertEqual(1, len(static_vars)) diff --git a/src/openforms/variables/tests/test_static_variables.py b/src/openforms/variables/tests/test_static_variables.py index 6081898597..340c5c3a8c 100644 --- a/src/openforms/variables/tests/test_static_variables.py +++ b/src/openforms/variables/tests/test_static_variables.py @@ -4,10 +4,19 @@ from django.test import TestCase, override_settings from freezegun import freeze_time +from jsonschema import Draft202012Validator from openforms.submissions.tests.factories import SubmissionFactory from ..registry import register_static_variable as register +from ..static_variables.static_variables import ( + CurrentYear, + Environment, + FormID, + FormName, + Now, + Today, +) def _get_variable(key: str, **kwargs): @@ -120,3 +129,39 @@ def test_date_has_the_right_day(self): variable = _get_variable("today", submission=submission) self.assertEqual(variable.initial_value.day, 24) + + +class StaticVariablesValidJsonSchemaTests(TestCase): + validator = Draft202012Validator + + def check_schema(self, properties): + schema = { + "$schema": self.validator.META_SCHEMA["$id"], + **properties, + } + + self.validator.check_schema(schema) + + def test_now(self): + schema = Now.as_json_schema() + self.check_schema(schema) + + def test_today(self): + schema = Today.as_json_schema() + self.check_schema(schema) + + def test_current_year(self): + schema = CurrentYear.as_json_schema() + self.check_schema(schema) + + def test_environment(self): + schema = Environment.as_json_schema() + self.check_schema(schema) + + def test_form_name(self): + schema = FormName.as_json_schema() + self.check_schema(schema) + + def test_form_id(self): + schema = FormID.as_json_schema() + self.check_schema(schema) diff --git a/src/openforms/variables/tests/test_user_defined_variables.py b/src/openforms/variables/tests/test_user_defined_variables.py new file mode 100644 index 0000000000..4fc04af3e3 --- /dev/null +++ b/src/openforms/variables/tests/test_user_defined_variables.py @@ -0,0 +1,56 @@ +from django.test import TestCase + +from jsonschema import Draft202012Validator + +from ..constants import FormVariableDataTypes +from ..service import get_json_schema_for_user_defined_variable + + +class UserDefinedVariablesValidJsonSchemaTests(TestCase): + validator = Draft202012Validator + + def check_schema(self, properties): + schema = { + "$schema": self.validator.META_SCHEMA["$id"], + **properties, + } + + self.validator.check_schema(schema) + + def test_string(self): + base = get_json_schema_for_user_defined_variable(FormVariableDataTypes.string) + self.check_schema(base) + + def test_boolean(self): + base = get_json_schema_for_user_defined_variable( + FormVariableDataTypes.boolean + ) + self.check_schema(base) + + def test_object(self): + base = get_json_schema_for_user_defined_variable(FormVariableDataTypes.object) + self.check_schema(base) + + def test_array(self): + base = get_json_schema_for_user_defined_variable(FormVariableDataTypes.array) + self.check_schema(base) + + def test_int(self): + base = get_json_schema_for_user_defined_variable(FormVariableDataTypes.int) + self.check_schema(base) + + def test_float(self): + base = get_json_schema_for_user_defined_variable(FormVariableDataTypes.float) + self.check_schema(base) + + def test_datetime(self): + base = get_json_schema_for_user_defined_variable(FormVariableDataTypes.datetime) + self.check_schema(base) + + def test_date(self): + base = get_json_schema_for_user_defined_variable(FormVariableDataTypes.date) + self.check_schema(base) + + def test_time(self): + base = get_json_schema_for_user_defined_variable(FormVariableDataTypes.time) + self.check_schema(base) diff --git a/src/openforms/variables/tests/test_views.py b/src/openforms/variables/tests/test_views.py index 368f582669..6f38c36d0d 100644 --- a/src/openforms/variables/tests/test_views.py +++ b/src/openforms/variables/tests/test_views.py @@ -56,6 +56,10 @@ class DemoNow(BaseStaticVariable): def get_initial_value(self, *args, **kwargs): return "2021-07-16T21:15:00+00:00" + @staticmethod + def as_json_schema(): + return {} + register = VariableRegistry() register("now")(DemoNow) @@ -129,6 +133,10 @@ class DemoNow(BaseStaticVariable): def get_initial_value(self, *args, **kwargs): return "demo initial value" + @staticmethod + def as_json_schema(): + return {} + variables_registry = VariableRegistry() variables_registry("now")(DemoNow)