diff --git a/src/openforms/formio/components/vanilla.py b/src/openforms/formio/components/vanilla.py index a6888d300b..c8a0685ff1 100644 --- a/src/openforms/formio/components/vanilla.py +++ b/src/openforms/formio/components/vanilla.py @@ -29,6 +29,7 @@ from csp_post_processor import post_process_html from openforms.config.constants import UploadFileType from openforms.config.models import GlobalConfiguration +from openforms.formio.constants import DataSrcOptions from openforms.submissions.attachments import temporary_upload_from_url from openforms.submissions.models import EmailVerification from openforms.typing import DataMapping, JSONObject @@ -700,7 +701,7 @@ def as_json_schema(component: SelectBoxesComponent) -> JSONObject: data_src = component.get("openForms", {}).get("dataSrc") base = {"title": label, "type": "object"} - if data_src != "variable": + if data_src != DataSrcOptions.variable: # Only add properties if the data source IS NOT another variable, because # component[values] is not updated when it IS. So it does not make sense to # add properties in that case. @@ -775,7 +776,7 @@ def as_json_schema(component: SelectComponent) -> JSONObject: data_src = component.get("openForms", {}).get("dataSrc") base = {"type": "string"} - if data_src != "variable": + if data_src != DataSrcOptions.variable: # Only add properties if the data source IS NOT another variable, because # component[data][values] is not updated when it IS. So it does not make # sense to add properties in that case. @@ -863,7 +864,7 @@ def as_json_schema(component: RadioComponent) -> JSONObject: data_src = component.get("openForms", {}).get("dataSrc") base = {"title": label, "type": "string"} - if data_src != "variable": + if data_src != DataSrcOptions.variable: # Only add enum if the data source IS NOT another variable, because # component[values] is not updated when it IS. So it does not make sense to # add a list of choices to the enum in that case. diff --git a/src/openforms/formio/constants.py b/src/openforms/formio/constants.py index 69e21071ce..40ca00fa62 100644 --- a/src/openforms/formio/constants.py +++ b/src/openforms/formio/constants.py @@ -1,3 +1,5 @@ +from enum import StrEnum + COMPONENT_DATATYPES = { "date": "date", "time": "time", @@ -11,3 +13,9 @@ "editgrid": "array", "datetime": "datetime", } + + +class DataSrcOptions(StrEnum): + manual = "manual" + variable = "variable" + referentielijsten = "referentielijsten" diff --git a/src/openforms/formio/dynamic_config/dynamic_options.py b/src/openforms/formio/dynamic_config/dynamic_options.py index 9a40bad7c8..4a7a3eec7a 100644 --- a/src/openforms/formio/dynamic_config/dynamic_options.py +++ b/src/openforms/formio/dynamic_config/dynamic_options.py @@ -7,6 +7,7 @@ from json_logic import jsonLogic from openforms.api.exceptions import ServiceUnavailable +from openforms.formio.constants import DataSrcOptions from openforms.logging import logevent from openforms.submissions.models import Submission from openforms.typing import DataMapping, JSONValue @@ -108,13 +109,13 @@ def add_options_to_config( ) -> None: data_src = glom(component, "openForms.dataSrc", default=None) match data_src: - case "referentielijsten": + case DataSrcOptions.referentielijsten: items_array = fetch_options_from_referentielijsten(component, submission) if not items_array: raise ServiceUnavailable( _("Could not retrieve options from Referentielijsten API."), ) - case "variable": + case DataSrcOptions.variable: items_array = get_options_from_variable(component, data, submission) if items_array is None: return diff --git a/src/openforms/formio/dynamic_config/tests/test_dynamic_options.py b/src/openforms/formio/dynamic_config/tests/test_dynamic_options.py index 1964ad1eab..0452ba7f52 100644 --- a/src/openforms/formio/dynamic_config/tests/test_dynamic_options.py +++ b/src/openforms/formio/dynamic_config/tests/test_dynamic_options.py @@ -5,6 +5,7 @@ from rest_framework.test import APITestCase from openforms.accounts.tests.factories import SuperUserFactory +from openforms.formio.constants import DataSrcOptions from openforms.formio.datastructures import FormioConfigurationWrapper from openforms.formio.dynamic_config import rewrite_formio_components from openforms.forms.tests.factories import ( @@ -30,7 +31,7 @@ def test_manual_options_not_updated(self): {"label": "A", "value": "a"}, {"label": "B", "value": "b"}, ], - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, { "label": "Select", @@ -40,7 +41,7 @@ def test_manual_options_not_updated(self): {"label": "A", "value": "a"}, {"label": "B", "value": "b"}, ], - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, "json": "", "url": "", "resource": "", @@ -56,7 +57,7 @@ def test_manual_options_not_updated(self): {"label": "A", "value": "a"}, {"label": "B", "value": "b"}, ], - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, ] } @@ -105,7 +106,7 @@ def test_variable_options_repeating_group(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "map": [{"var": "repeatingGroup"}, {"var": "name"}] }, @@ -120,7 +121,7 @@ def test_variable_options_repeating_group(self): ], }, "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "map": [{"var": "repeatingGroup"}, {"var": "name"}] }, @@ -138,7 +139,7 @@ def test_variable_options_repeating_group(self): "itemsExpression": { "map": [{"var": "repeatingGroup"}, {"var": "name"}] }, - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, }, }, ] @@ -189,7 +190,7 @@ def test_variable_options_repeating_group_empty_data(self): "values": [ {"label": "", "value": ""}, ], - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "data": { "itemsExpression": { "map": [{"var": "repeatingGroup"}, {"var": "name"}] @@ -203,7 +204,7 @@ def test_variable_options_repeating_group_empty_data(self): "values": [ {"label": "", "value": ""}, ], - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "map": [{"var": "repeatingGroup"}, {"var": "name"}] }, @@ -217,7 +218,7 @@ def test_variable_options_repeating_group_empty_data(self): "values": [ {"label": "", "value": ""}, ], - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "data": { "itemsExpression": { "map": [{"var": "repeatingGroup"}, {"var": "name"}] @@ -264,7 +265,7 @@ def test_variable_options_multiple_component(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": {"var": "textField"}, }, }, @@ -277,7 +278,7 @@ def test_variable_options_multiple_component(self): ], }, "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": {"var": "textField"}, }, "type": "select", @@ -290,7 +291,7 @@ def test_variable_options_multiple_component(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": {"var": "textField"}, }, }, @@ -342,7 +343,7 @@ def test_variable_options_multiple_empty_data(self): "values": [ {"label": "", "value": ""}, ], - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "data": { "itemsExpression": {"var": "textField"}, }, @@ -354,7 +355,7 @@ def test_variable_options_multiple_empty_data(self): "values": [ {"label": "", "value": ""}, ], - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": {"var": "textField"}, }, "type": "select", @@ -366,7 +367,7 @@ def test_variable_options_multiple_empty_data(self): "values": [ {"label": "", "value": ""}, ], - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "data": { "itemsExpression": {"var": "textField"}, }, @@ -411,7 +412,7 @@ def test_variable_options_repeating_group_missing_map(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "var": "repeatingGroup" }, # No map operation to transform dict into str @@ -426,7 +427,7 @@ def test_variable_options_repeating_group_missing_map(self): ], }, "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "var": "repeatingGroup" }, # No map operation to transform dict into str @@ -444,7 +445,7 @@ def test_variable_options_repeating_group_missing_map(self): "itemsExpression": { "var": "repeatingGroup" }, # No map operation to transform dict into str - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, }, }, ] @@ -506,7 +507,7 @@ def test_escaped_html(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": {"var": "textField"}, }, }, @@ -547,7 +548,7 @@ def test_wrong_type_variable(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": {"var": "textField"}, }, }, @@ -593,7 +594,7 @@ def test_duplicate_options_with_multiple_field(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": {"var": "textField"}, }, }, @@ -628,7 +629,7 @@ def test_duplicate_options_with_repeating_group(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "map": [{"var": "repeatingGroup"}, {"var": "name"}] }, @@ -660,7 +661,7 @@ def test_badly_formatted_items(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "map": [{"var": "externalData"}, {"var": "id"}] }, @@ -722,7 +723,7 @@ def test_different_label_key_options(self): {"label": "", "value": ""}, ], "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "map": [ {"var": "repeatingGroup"}, @@ -781,7 +782,7 @@ def test_overwrite_html_in_content_component(self):
-
+ """, }, { diff --git a/src/openforms/formio/dynamic_config/tests/test_referentielijsten_config.py b/src/openforms/formio/dynamic_config/tests/test_referentielijsten_config.py index ab4cd80a13..b7d59d2668 100644 --- a/src/openforms/formio/dynamic_config/tests/test_referentielijsten_config.py +++ b/src/openforms/formio/dynamic_config/tests/test_referentielijsten_config.py @@ -12,6 +12,7 @@ from zgw_consumers.test.factories import ServiceFactory from openforms.api.exceptions import ServiceUnavailable +from openforms.formio.constants import DataSrcOptions from openforms.formio.registry import register from openforms.formio.typing import ( RadioComponent, @@ -60,7 +61,7 @@ def test_success(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -85,7 +86,7 @@ def test_table_with_paginated_items(self): "dataType": "string", "openForms": { "code": "tabel-with-many-items", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -107,7 +108,7 @@ def test_no_service_configured(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": "", "translations": {}, }, @@ -136,7 +137,7 @@ def test_no_code_configured(self): "dataType": "string", "openForms": { "code": "", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -165,7 +166,7 @@ def test_service_does_not_exist(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -196,7 +197,7 @@ def test_items_not_found(self): "dataType": "string", "openForms": { "code": "non-existent", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -226,7 +227,7 @@ def test_request_exception(self, m): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -285,7 +286,7 @@ def test_success(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -310,7 +311,7 @@ def test_no_service_configured(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": "", "translations": {}, }, @@ -340,7 +341,7 @@ def test_no_code_configured(self): "dataType": "string", "openForms": { "code": "", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -370,7 +371,7 @@ def test_service_does_not_exist(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -402,7 +403,7 @@ def test_items_not_found(self): "dataType": "string", "openForms": { "code": "non-existent", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -433,7 +434,7 @@ def test_request_exception(self, m): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -493,7 +494,7 @@ def test_success(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -518,7 +519,7 @@ def test_no_service_configured(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": "", "translations": {}, }, @@ -547,7 +548,7 @@ def test_no_code_configured(self): "dataType": "string", "openForms": { "code": "", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -576,7 +577,7 @@ def test_service_does_not_exist(self): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -607,7 +608,7 @@ def test_items_not_found(self): "dataType": "string", "openForms": { "code": "non-existent", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -637,7 +638,7 @@ def test_request_exception(self, m): "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": self.service.slug, "translations": {}, }, @@ -682,7 +683,7 @@ def test_get_submissionstep_detail_raises_error_for_referentielijsten_if_service "dataType": "string", "openForms": { "code": "tabel1", - "dataSrc": "referentielijsten", + "dataSrc": DataSrcOptions.referentielijsten, "service": "non-existent", "translations": {}, }, diff --git a/src/openforms/formio/migration_converters.py b/src/openforms/formio/migration_converters.py index 9df2686559..07f1f753b5 100644 --- a/src/openforms/formio/migration_converters.py +++ b/src/openforms/formio/migration_converters.py @@ -11,6 +11,7 @@ from glom import assign, glom +from openforms.formio.constants import DataSrcOptions from openforms.formio.typing.vanilla import ColumnsComponent, FileComponent from openforms.typing import JSONObject @@ -81,7 +82,7 @@ def set_openforms_datasrc(component: Component) -> bool: # if a dataSrc is specified, there is nothing to do if glom(component, "openForms.dataSrc", default=None): return False - assign(component, "openForms.dataSrc", val="manual", missing=dict) + assign(component, "openForms.dataSrc", val=DataSrcOptions.manual, missing=dict) return True diff --git a/src/openforms/formio/rendering/tests/test_component_node.py b/src/openforms/formio/rendering/tests/test_component_node.py index 371df802ef..ac6aa867eb 100644 --- a/src/openforms/formio/rendering/tests/test_component_node.py +++ b/src/openforms/formio/rendering/tests/test_component_node.py @@ -2,6 +2,7 @@ from django.test import TestCase, tag +from openforms.formio.constants import DataSrcOptions from openforms.submissions.rendering import Renderer, RenderModes from openforms.submissions.tests.factories import SubmissionFactory @@ -637,7 +638,7 @@ def test_render_mode_pdf_with_list_values(self): "label": "Select single", "multiple": False, "openForms": { - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, "data": { "values": [ @@ -652,7 +653,7 @@ def test_render_mode_pdf_with_list_values(self): "label": "Select multiple", "multiple": True, "openForms": { - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, "data": { "values": [ @@ -846,7 +847,7 @@ def test_render_mode_summary_with_list_values(self): "label": "Select single", "multiple": False, "openForms": { - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, "data": { "values": [ @@ -861,7 +862,7 @@ def test_render_mode_summary_with_list_values(self): "label": "Select multiple", "multiple": True, "openForms": { - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, "data": { "values": [ diff --git a/src/openforms/formio/tests/search_strategies.py b/src/openforms/formio/tests/search_strategies.py index 2fda033474..7a5f92a31b 100644 --- a/src/openforms/formio/tests/search_strategies.py +++ b/src/openforms/formio/tests/search_strategies.py @@ -20,6 +20,7 @@ from hypothesis import strategies as st +from openforms.formio.constants import DataSrcOptions from openforms.tests.search_strategies import jsonb_text @@ -206,7 +207,7 @@ def option(): def data_sources(): - return st.sampled_from(["manual", "variable"]) + return st.sampled_from([DataSrcOptions.manual, DataSrcOptions.variable]) def select_component(): diff --git a/src/openforms/formio/tests/test_component_json_schemas.py b/src/openforms/formio/tests/test_component_json_schemas.py index 35d7ddd974..7ed334d639 100644 --- a/src/openforms/formio/tests/test_component_json_schemas.py +++ b/src/openforms/formio/tests/test_component_json_schemas.py @@ -2,6 +2,8 @@ from jsonschema import Draft202012Validator +from openforms.formio.constants import DataSrcOptions + from ..service import as_json_schema from ..typing import ( AddressNLComponent, @@ -279,7 +281,7 @@ def test_data_source_is_another_form_variable(self): "values": [ {"label": "", "value": ""}, ], - "openForms": {"dataSrc": "variable"}, + "openForms": {"dataSrc": DataSrcOptions.variable}, "type": "radio", } @@ -331,7 +333,7 @@ def test_data_source_is_another_form_variable(self): {"label": "", "value": ""}, ], }, - "openForms": {"dataSrc": "variable"}, + "openForms": {"dataSrc": DataSrcOptions.variable}, "type": "select", } @@ -383,7 +385,7 @@ def test_data_source_is_another_form_variable(self): "values": [ {"label": "", "value": ""}, ], - "openForms": {"dataSrc": "variable"}, + "openForms": {"dataSrc": DataSrcOptions.variable}, "type": "selectboxes", } diff --git a/src/openforms/formio/tests/validation/test_editgrid.py b/src/openforms/formio/tests/validation/test_editgrid.py index 19190aa959..2b7b998641 100644 --- a/src/openforms/formio/tests/validation/test_editgrid.py +++ b/src/openforms/formio/tests/validation/test_editgrid.py @@ -4,6 +4,7 @@ from rest_framework import serializers +from openforms.formio.constants import DataSrcOptions from openforms.submissions.tests.factories import SubmissionFactory from openforms.typing import JSONObject, JSONValue @@ -245,7 +246,7 @@ def test_regression_dh_ooievaarspas(self): "key": "heeftUEenWerkgever", "label": "Heeft u een werkgever?", "validate": {"required": True}, - "openForms": {"dataSrc": "manual"}, + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"label": "Ja", "value": "ja"}, {"label": "Nee", "value": "nee"}, @@ -282,7 +283,7 @@ def test_regression_dh_ooievaarspas(self): "key": "periodeNettoLoon", "label": "Over welke periode ontvangt u dit loon?", "validate": {"required": True}, - "openForms": {"dataSrc": "manual"}, + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"label": "Per week", "value": "week"}, {"label": "Per 4 weken", "value": "vierWeken"}, diff --git a/src/openforms/formio/tests/validation/test_radio.py b/src/openforms/formio/tests/validation/test_radio.py index 16f47aa5ed..9da3b0891c 100644 --- a/src/openforms/formio/tests/validation/test_radio.py +++ b/src/openforms/formio/tests/validation/test_radio.py @@ -1,5 +1,6 @@ from django.test import SimpleTestCase, tag +from openforms.formio.constants import DataSrcOptions from openforms.typing import JSONObject from ...typing import RadioComponent @@ -14,7 +15,7 @@ def test_radio_required_validation(self): "key": "foo", "label": "Test", "validate": {"required": True}, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"}, @@ -42,7 +43,7 @@ def test_invalid_option_provided(self): "key": "foo", "label": "Test", "validate": {"required": False}, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"}, diff --git a/src/openforms/formio/tests/validation/test_selectboxes.py b/src/openforms/formio/tests/validation/test_selectboxes.py index fec7a95750..e5d382b75e 100644 --- a/src/openforms/formio/tests/validation/test_selectboxes.py +++ b/src/openforms/formio/tests/validation/test_selectboxes.py @@ -2,6 +2,7 @@ from hypothesis import given, strategies as st +from openforms.formio.constants import DataSrcOptions from openforms.typing import JSONValue from ...typing import SelectBoxesComponent @@ -16,7 +17,7 @@ def test_selectboxes_required_validation(self): "key": "foo", "label": "Test", "validate": {"required": True}, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"}, @@ -51,7 +52,7 @@ def test_optional_selectboxes(self): "key": "foo", "label": "Test", "validate": {"required": False}, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"}, @@ -81,7 +82,7 @@ def test_all_options_must_be_specified(self, required: bool): "key": "foo", "label": "Test", "validate": {"required": required}, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"}, @@ -101,7 +102,7 @@ def test_additional_options_are_ignored(self): "key": "foo", "label": "Test", "validate": {"required": False}, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"}, @@ -123,7 +124,7 @@ def test_validate_min_checked(self): "required": False, "minSelectedCount": 2, }, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"}, @@ -147,7 +148,7 @@ def test_validate_max_checked(self): "required": False, "maxSelectedCount": 1, }, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"}, diff --git a/src/openforms/formio/typing/base.py b/src/openforms/formio/typing/base.py index 8d873f6e91..a0cc1c61c3 100644 --- a/src/openforms/formio/typing/base.py +++ b/src/openforms/formio/typing/base.py @@ -6,6 +6,7 @@ from typing import Literal, NotRequired, TypeAlias, TypedDict +from openforms.formio.constants import DataSrcOptions from openforms.typing import JSONValue from .dates import DateConstraintConfiguration @@ -44,7 +45,13 @@ class OpenFormsConfig(TypedDict): translations: NotRequired[TranslationsDict] components: NotRequired[AddressValidationComponents] requireVerification: NotRequired[bool] - dataSrc: NotRequired[Literal["manual", "variable", "referentielijsten"]] + dataSrc: NotRequired[ + Literal[ + DataSrcOptions.manual, + DataSrcOptions.variable, + DataSrcOptions.referentielijsten, + ] + ] code: NotRequired[str] service: NotRequired[str] diff --git a/src/openforms/forms/tests/e2e_tests/test_form_designer.py b/src/openforms/forms/tests/e2e_tests/test_form_designer.py index 52f2521b7f..338f7b699e 100644 --- a/src/openforms/forms/tests/e2e_tests/test_form_designer.py +++ b/src/openforms/forms/tests/e2e_tests/test_form_designer.py @@ -7,6 +7,7 @@ from furl import furl from playwright.async_api import Page, expect +from openforms.formio.constants import DataSrcOptions from openforms.products.tests.factories import ProductFactory from openforms.tests.e2e.base import ( E2ETestCase, @@ -110,7 +111,7 @@ def setUpTestData(): "description": "Description 2", "tooltip": "Tooltip 2", "openForms": { - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, "data": { "values": [ @@ -1406,7 +1407,7 @@ def setUpTestData(): "type": "radio", "key": "radio", "label": "Radio 1", - "openForms": {"dataSrc": "manual"}, + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "option", "label": "Option"}, ], @@ -1415,7 +1416,7 @@ def setUpTestData(): "type": "select", "key": "select", "label": "Select 1", - "openForms": {"dataSrc": "manual"}, + "openForms": {"dataSrc": DataSrcOptions.manual}, "dataSrc": "values", "data": { "values": [ @@ -1427,7 +1428,7 @@ def setUpTestData(): "type": "selectboxes", "key": "selectBoxes", "label": "Select Boxes 1", - "openForms": {"dataSrc": "manual"}, + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "option", "label": "Option"}, ], diff --git a/src/openforms/forms/tests/test_json_schema.py b/src/openforms/forms/tests/test_json_schema.py index e17b3994fe..593ea16cf7 100644 --- a/src/openforms/forms/tests/test_json_schema.py +++ b/src/openforms/forms/tests/test_json_schema.py @@ -1,5 +1,6 @@ from django.test import TestCase +from openforms.formio.constants import DataSrcOptions from openforms.forms.tests.factories import ( FormDefinitionFactory, FormFactory, @@ -32,7 +33,7 @@ def test_correct_variables_included_in_schema(self): {"label": "A", "value": "a"}, {"label": "B", "value": "b"}, ], - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, "json": "", "url": "", "resource": "", @@ -57,7 +58,7 @@ def test_correct_variables_included_in_schema(self): {"label": "A", "value": "a"}, {"label": "B", "value": "b"}, ], - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, ] } diff --git a/src/openforms/registrations/contrib/json_dump/plugin.py b/src/openforms/registrations/contrib/json_dump/plugin.py index b377d0f6a4..09181f49cd 100644 --- a/src/openforms/registrations/contrib/json_dump/plugin.py +++ b/src/openforms/registrations/contrib/json_dump/plugin.py @@ -8,6 +8,7 @@ from zgw_consumers.client import build_client +from openforms.formio.constants import DataSrcOptions from openforms.formio.service import rewrite_formio_components from openforms.formio.typing import ( FileComponent, @@ -135,13 +136,13 @@ def post_process( values[key] = value schema["properties"][key] = base_schema # type: ignore - case {"type": "radio", "openForms": {"dataSrc": "variable"}}: + case {"type": "radio", "openForms": {"dataSrc": DataSrcOptions.variable}}: component = cast(RadioComponent, component) choices = [options["value"] for options in component["values"]] choices.append("") # Take into account an unfilled field schema["properties"][key]["enum"] = choices # type: ignore - case {"type": "select", "openForms": {"dataSrc": "variable"}}: + case {"type": "select", "openForms": {"dataSrc": DataSrcOptions.variable}}: component = cast(SelectComponent, component) choices = [options["value"] for options in component["data"]["values"]] # type: ignore[reportTypedDictNotRequiredAccess] choices.append("") # Take into account an unfilled field @@ -155,7 +156,7 @@ def post_process( component = cast(SelectBoxesComponent, component) data_src = component.get("openForms", {}).get("dataSrc") - if data_src == "variable": + if data_src == DataSrcOptions.variable: properties = { options["value"]: {"type": "boolean"} for options in component["values"] 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 03809cbfdc..48d237e84c 100644 --- a/src/openforms/registrations/contrib/json_dump/tests/test_backend.py +++ b/src/openforms/registrations/contrib/json_dump/tests/test_backend.py @@ -8,6 +8,7 @@ from requests import RequestException from zgw_consumers.test.factories import ServiceFactory +from openforms.formio.constants import DataSrcOptions from openforms.submissions.tests.factories import ( FormVariableFactory, SubmissionFactory, @@ -515,7 +516,7 @@ def test_select_component_with_form_variable_as_data_source(self): "type": "select", "multiple": True, "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": {"var": "valuesForSelect"}, }, "data": { @@ -568,7 +569,7 @@ def test_select_boxes_component_with_form_variable_as_data_source(self): "key": "selectBoxes", "type": "selectboxes", "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "translations": {}, "itemsExpression": {"var": "valuesForSelectBoxes"}, }, @@ -659,7 +660,7 @@ def test_radio_component_with_form_variable_as_data_source(self): "key": "radio", "type": "radio", "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "translations": {}, "itemsExpression": {"var": "valuesForRadio"}, }, diff --git a/src/openforms/registrations/contrib/objects_api/tests/test_template.py b/src/openforms/registrations/contrib/objects_api/tests/test_template.py index df6a18904c..900627ebd8 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/test_template.py +++ b/src/openforms/registrations/contrib/objects_api/tests/test_template.py @@ -10,6 +10,7 @@ from freezegun import freeze_time from openforms.contrib.objects_api.tests.factories import ObjectsAPIGroupConfigFactory +from openforms.formio.constants import DataSrcOptions from openforms.submissions.tests.factories import ( SubmissionFactory, SubmissionFileAttachmentFactory, @@ -351,7 +352,7 @@ def test_object_nulls_regression(self, m): ], "defaultValue": None, "validate": {"required": True}, - "openForms": {"dataSrc": "manual"}, + "openForms": {"dataSrc": DataSrcOptions.manual}, }, { "type": "textfield", diff --git a/src/openforms/submissions/tests/test_submission_completion.py b/src/openforms/submissions/tests/test_submission_completion.py index f741848a99..f0a6aa4b54 100644 --- a/src/openforms/submissions/tests/test_submission_completion.py +++ b/src/openforms/submissions/tests/test_submission_completion.py @@ -21,6 +21,7 @@ from openforms.authentication.service import FORM_AUTH_SESSION_KEY, AuthAttribute from openforms.config.models import GlobalConfiguration +from openforms.formio.constants import DataSrcOptions from openforms.forms.constants import StatementCheckboxChoices, SubmissionAllowedChoices from openforms.forms.tests.factories import ( FormFactory, @@ -604,7 +605,7 @@ def test_dynamic_configuration_evaluated(self): "key": "someCondition", "type": "radio", "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": [ ["a", "A"], ], diff --git a/src/openforms/submissions/tests/test_submission_step_validate.py b/src/openforms/submissions/tests/test_submission_step_validate.py index 6c1c299f15..4aa27fa76a 100644 --- a/src/openforms/submissions/tests/test_submission_step_validate.py +++ b/src/openforms/submissions/tests/test_submission_step_validate.py @@ -7,6 +7,7 @@ from rest_framework.reverse import reverse from rest_framework.test import APITestCase +from openforms.formio.constants import DataSrcOptions from openforms.formio.tests.factories import ( SubmittedFileFactory, TemporaryFileUploadFactory, @@ -364,7 +365,7 @@ def test_validate_selectboxes_with_dynamic_values_source(self): "maxSelectedCount": 3, }, "openForms": { - "dataSrc": "variable", + "dataSrc": DataSrcOptions.variable, "itemsExpression": { "var": "items", }, diff --git a/src/openforms/submissions/tests/test_tasks_pdf.py b/src/openforms/submissions/tests/test_tasks_pdf.py index a01c44f546..eec5fe2c10 100644 --- a/src/openforms/submissions/tests/test_tasks_pdf.py +++ b/src/openforms/submissions/tests/test_tasks_pdf.py @@ -10,6 +10,7 @@ from testfixtures import LogCapture from openforms.config.models import GlobalConfiguration +from openforms.formio.constants import DataSrcOptions from openforms.forms.tests.factories import FormLogicFactory from ..form_logic import evaluate_form_logic @@ -379,7 +380,7 @@ def test_select_component_with_multiple_is_rendered_as_html(self): "label": "Select single", "multiple": False, "openForms": { - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, "data": { "values": [ @@ -394,7 +395,7 @@ def test_select_component_with_multiple_is_rendered_as_html(self): "label": "Select multiple", "multiple": True, "openForms": { - "dataSrc": "manual", + "dataSrc": DataSrcOptions.manual, }, "data": { "values": [ diff --git a/src/openforms/tests/e2e/test_input_validation.py b/src/openforms/tests/e2e/test_input_validation.py index cfe258f86a..71c3b8c518 100644 --- a/src/openforms/tests/e2e/test_input_validation.py +++ b/src/openforms/tests/e2e/test_input_validation.py @@ -17,6 +17,7 @@ from furl import furl from playwright.async_api import Page, expect +from openforms.formio.constants import DataSrcOptions from openforms.formio.tests.factories import SubmittedFileFactory from openforms.formio.typing import ( AddressNLComponent, @@ -209,7 +210,7 @@ def test_required_field(self): "key": "requiredRadio", "label": "Required radio", "validate": {"required": True}, - "openForms": {"dataSrc": "manual"}, # type: ignore + "openForms": {"dataSrc": DataSrcOptions.manual}, "values": [ {"value": "a", "label": "A"}, {"value": "b", "label": "B"},