diff --git a/setup.cfg b/setup.cfg index a1e93f13e5..16f57e646c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,7 +32,9 @@ source = src omit = manage.py */tests/test_* + */tests/factories.py */migrations/* + src/openforms/formio/formatters/tests/mixins.py src/openforms/submissions/management/commands/test_submission_completion.py src/openforms/submissions/management/commands/render_confirmation_pdf.py src/openforms/formio/management/commands/formio_makemessages.py @@ -51,23 +53,3 @@ omit = [coverage:report] skip_covered = True -omit = - manage.py - */tests/test_* - */tests/factories.py - */migrations/* - src/openforms/submissions/management/commands/test_submission_completion.py - src/openforms/submissions/management/commands/render_confirmation_pdf.py - src/openforms/formio/management/commands/formio_makemessages.py - src/openforms/appointments/management/commands/appointment.py - src/openforms/registrations/management/commands/register_submission.py - src/openforms/registrations/contrib/microsoft_graph/management/commands/msgraph_list_files.py - src/openforms/prefill/management/commands/generate_prefill_from_spec.py - src/openforms/utils/management/commands/check_admin_index.py - src/openforms/registrations/contrib/stuf_zds/management/commands/stuf_zds_test_stp.py - src/openforms/plugins/management/commands/disable_demo_plugins.py - src/openforms/payments/management/commands/checkpaymentemaildupes.py - src/openforms/registrations/contrib/email/views.py - src/openforms/upgrades/tests/files/check_fail.py-tpl - src/openforms/upgrades/tests/files/check_pass.py-tpl - src/openforms/upgrades/tests/files/check_error.py-tpl diff --git a/src/openforms/formio/components/np_family_members/tests/test_family_members.py b/src/openforms/formio/components/np_family_members/tests/test_family_members.py index 9e8f20a6c6..12d6b7eff0 100644 --- a/src/openforms/formio/components/np_family_members/tests/test_family_members.py +++ b/src/openforms/formio/components/np_family_members/tests/test_family_members.py @@ -24,12 +24,11 @@ class FamilyMembersCustomFieldTypeTest(TestCase): - @patch("openforms.formio.components.custom.NPFamilyMembers._get_handler") - def test_get_values_for_custom_field(self, mock_get_handler): - mock_get_handler.return_value.return_value = [ - ("222333444", "Billy Doe"), - ("333444555", "Jane Doe"), - ] + @patch( + "openforms.formio.components.custom.get_np_children_haal_centraal", + return_value=[("222333444", "Billy Doe"), ("333444555", "Jane Doe")], + ) + def test_get_values_for_custom_field(self, mock_get_np_children): submission = SubmissionFactory.from_components( [ { diff --git a/src/openforms/formio/datastructures.py b/src/openforms/formio/datastructures.py index 2385ed9266..eb3e2e467a 100644 --- a/src/openforms/formio/datastructures.py +++ b/src/openforms/formio/datastructures.py @@ -52,14 +52,3 @@ def __add__( @property def configuration(self) -> JSONObject: return self._configuration - - @configuration.setter - def configuration(self, new: JSONObject) -> None: - # if there are no changes in the configuration, do not invalidate the cache - if self._configuration == new: - return - - # invalidate cache on configuration mutations - if self._cached_component_map is not None: - self._cached_component_map = None - self._configuration = new diff --git a/src/openforms/formio/dynamic_config/tests/test_file_component.py b/src/openforms/formio/dynamic_config/tests/test_file_component.py new file mode 100644 index 0000000000..32bebd6747 --- /dev/null +++ b/src/openforms/formio/dynamic_config/tests/test_file_component.py @@ -0,0 +1,41 @@ +from unittest.mock import patch + +from django.test import TestCase + +from rest_framework.test import APIRequestFactory + +from openforms.config.models import GlobalConfiguration + +from ...datastructures import FormioConfigurationWrapper +from ...service import rewrite_formio_components_for_request + +request_factory = APIRequestFactory() + + +def _get_dynamic_config(component: dict) -> FormioConfigurationWrapper: + wrapper = FormioConfigurationWrapper({"components": [component]}) + request = request_factory.get("/irrelevant") + return rewrite_formio_components_for_request(wrapper, request) + + +@patch( + "openforms.formio.components.vanilla.GlobalConfiguration.get_solo", + return_value=GlobalConfiguration( + form_upload_default_file_types=["image/png", "application/pdf"] + ), +) +class FileComponentTests(TestCase): + def test_use_global_config_filetypes(self, m_get_solo): + component = { + "type": "file", + "key": "fileTest", + "url": "", + "useConfigFiletypes": True, + "filePattern": "*", + } + + wrapper = _get_dynamic_config(component) + + updated_component = wrapper["fileTest"] + self.assertEqual(updated_component["filePattern"], "image/png,application/pdf") + self.assertNotEqual(updated_component["url"], "") diff --git a/src/openforms/formio/formatters/base.py b/src/openforms/formio/formatters/base.py index 91964b6292..4239564cbe 100644 --- a/src/openforms/formio/formatters/base.py +++ b/src/openforms/formio/formatters/base.py @@ -70,5 +70,5 @@ def __call__(self, component: Component, value: Any) -> str: component, self.join_formatted_values(component, formatted_values) ) - def format(self, component: Component, value: Any) -> str: + def format(self, component: Component, value: Any) -> str: # pragma:nocover raise NotImplementedError("%r must implement the 'format' method" % type(self)) diff --git a/src/openforms/formio/formatters/service.py b/src/openforms/formio/formatters/service.py deleted file mode 100644 index 3bc22580f4..0000000000 --- a/src/openforms/formio/formatters/service.py +++ /dev/null @@ -1,15 +0,0 @@ -import warnings - -from ..service import format_value as _format_value -from .printable import filter_printable - -__all__ = ["filter_printable"] - - -def format_value(*args, **kwargs): - warnings.warn( - "`openforms.formio.formatters.service.format_value` is deprecated in favour of " - "`openforms.formio.service.format_value`. Please update your references.", - DeprecationWarning, - ) - return _format_value(*args, **kwargs) diff --git a/src/openforms/formio/registry.py b/src/openforms/formio/registry.py index a2b84d6f06..1a3c5f40ed 100644 --- a/src/openforms/formio/registry.py +++ b/src/openforms/formio/registry.py @@ -23,11 +23,11 @@ from .typing import Component -if TYPE_CHECKING: +if TYPE_CHECKING: # pragma: nocover from openforms.submissions.models import Submission -class FormatterProtocol(Protocol): +class FormatterProtocol(Protocol): # pragma: nocover def __init__(self, as_html: bool): ... @@ -35,12 +35,12 @@ def __call__(self, component: Component, value: Any) -> str: ... -class NormalizerProtocol(Protocol): +class NormalizerProtocol(Protocol): # pragma: nocover def __call__(self, component: Component, value: Any) -> Any: ... -class RewriterForRequestProtocol(Protocol): +class RewriterForRequestProtocol(Protocol): # pragma: nocover def __call__(self, component: Component, request: Request) -> None: ... diff --git a/src/openforms/formio/tests/test_normalization.py b/src/openforms/formio/tests/test_normalization.py index 1509aa20f6..a3e8f2fc6f 100644 --- a/src/openforms/formio/tests/test_normalization.py +++ b/src/openforms/formio/tests/test_normalization.py @@ -56,3 +56,10 @@ def test_no_input_mask_given(self): result = normalize_value_for_component(component, "AAAA 34") self.assertEqual(result, "AAAA 34") + + def test_normalize_unknown_component_type(self): + component = {"type": "7923abf1-1397-40ed-b194-7a1d05e23b23"} + + result = normalize_value_for_component(component, "foo.bar-baz") + + self.assertEqual(result, "foo.bar-baz") # unmodified diff --git a/src/openforms/submissions/models/submission.py b/src/openforms/submissions/models/submission.py index 2526d8325b..505df43b49 100644 --- a/src/openforms/submissions/models/submission.py +++ b/src/openforms/submissions/models/submission.py @@ -507,7 +507,7 @@ def get_last_completed_step(self) -> Optional["SubmissionStep"]: return submission_state.get_last_completed_step() def get_ordered_data_with_component_type(self) -> OrderedDict: - from openforms.formio.formatters.service import filter_printable + from openforms.formio.formatters.printable import filter_printable ordered_data = OrderedDict() merged_data = self.get_merged_data()