Skip to content

Commit

Permalink
✅ [#1068] -- improving test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Nov 24, 2022
1 parent 1dc3088 commit 536133b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 58 deletions.
22 changes: 2 additions & 20 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
{
Expand Down
11 changes: 0 additions & 11 deletions src/openforms/formio/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions src/openforms/formio/dynamic_config/tests/test_file_component.py
Original file line number Diff line number Diff line change
@@ -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"], "")
2 changes: 1 addition & 1 deletion src/openforms/formio/formatters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
15 changes: 0 additions & 15 deletions src/openforms/formio/formatters/service.py

This file was deleted.

8 changes: 4 additions & 4 deletions src/openforms/formio/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@

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):
...

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:
...

Expand Down
7 changes: 7 additions & 0 deletions src/openforms/formio/tests/test_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/openforms/submissions/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 536133b

Please sign in to comment.