Skip to content

Commit

Permalink
♻️ [open-formulieren/open-forms#3489] Update tests for refactored cli…
Browse files Browse the repository at this point in the history
…ents situation
  • Loading branch information
sergei-maertens committed Sep 29, 2023
1 parent 55ce22b commit c04bf9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 38 deletions.
34 changes: 6 additions & 28 deletions prefill_haalcentraalhr/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

from openforms.authentication.constants import AuthAttribute
from openforms.plugins.exceptions import InvalidPluginConfiguration
from openforms.registrations.contrib.zgw_apis.tests.factories import ServiceFactory
from openforms.submissions.tests.factories import SubmissionFactory
from requests_mock import Mocker
from zgw_consumers.constants import APITypes
from zgw_consumers.test import mock_service_oas_get
from zgw_consumers_ext.tests.factories import ServiceFactory

from ..models import HaalCentraalHRConfig
from ..plugin import HaalCentraalHRPrefill
Expand Down Expand Up @@ -43,7 +42,7 @@ def test_no_service_configured(self):
)

with patch(
"prefill_haalcentraalhr.plugin.HaalCentraalHRConfig.get_solo",
"prefill_haalcentraalhr.client.HaalCentraalHRConfig.get_solo",
return_value=HaalCentraalHRConfig(),
):
data = plugin.get_prefill_values(
Expand All @@ -56,13 +55,6 @@ def test_no_service_configured(self):
@Mocker()
@override_settings(ZGW_CONSUMERS_TEST_SCHEMA_DIRS=[FILES_DIR])
def test_happy_flow(self, m):
mock_service_oas_get(
m,
url="http://haalcentraal-hr.nl/api/",
service="haalcentraal-hr-oas",
oas_url="https://haalcentraal-hr.nl/api/schema/openapi.yaml",
)

with open(FILES_DIR / "maatschappelijkeactiviteiten-response.json", "rb") as f:
m.get(
"http://haalcentraal-hr.nl/api/maatschappelijkeactiviteiten/111222333",
Expand All @@ -80,7 +72,7 @@ def test_happy_flow(self, m):
)

with patch(
"prefill_haalcentraalhr.plugin.HaalCentraalHRConfig.get_solo",
"prefill_haalcentraalhr.client.HaalCentraalHRConfig.get_solo",
return_value=HaalCentraalHRConfig(service=service),
):
data = plugin.get_prefill_values(
Expand All @@ -97,13 +89,6 @@ def test_happy_flow(self, m):
@Mocker()
@override_settings(ZGW_CONSUMERS_TEST_SCHEMA_DIRS=[FILES_DIR])
def test_check_config_happy_flow(self, m):
mock_service_oas_get(
m,
url="http://haalcentraal-hr.nl/api/",
service="haalcentraal-hr-oas",
oas_url="https://haalcentraal-hr.nl/api/schema/openapi.yaml",
)

m.get(
"http://haalcentraal-hr.nl/api/maatschappelijkeactiviteiten/TEST",
status_code=400,
Expand All @@ -123,21 +108,14 @@ def test_check_config_happy_flow(self, m):
)

with patch(
"prefill_haalcentraalhr.plugin.HaalCentraalHRConfig.get_solo",
"prefill_haalcentraalhr.client.HaalCentraalHRConfig.get_solo",
return_value=HaalCentraalHRConfig(service=service),
):
plugin.check_config()

@Mocker()
@override_settings(ZGW_CONSUMERS_TEST_SCHEMA_DIRS=[FILES_DIR])
def test_check_config_wrong_response(self, m):
mock_service_oas_get(
m,
url="http://haalcentraal-hr.nl/api/",
service="haalcentraal-hr-oas",
oas_url="https://haalcentraal-hr.nl/api/schema/openapi.yaml",
)

m.get(
"http://haalcentraal-hr.nl/api/maatschappelijkeactiviteiten/TEST",
status_code=403,
Expand All @@ -152,7 +130,7 @@ def test_check_config_wrong_response(self, m):
)

with patch(
"prefill_haalcentraalhr.plugin.HaalCentraalHRConfig.get_solo",
"prefill_haalcentraalhr.client.HaalCentraalHRConfig.get_solo",
return_value=HaalCentraalHRConfig(service=service),
):
with self.assertRaises(
Expand All @@ -165,7 +143,7 @@ def test_check_config_no_service_configured(self):
plugin = HaalCentraalHRPrefill("haalcentraal_hr")

with patch(
"prefill_haalcentraalhr.plugin.HaalCentraalHRConfig.get_solo",
"prefill_haalcentraalhr.client.HaalCentraalHRConfig.get_solo",
return_value=HaalCentraalHRConfig(),
):
with self.assertRaises(
Expand Down
12 changes: 2 additions & 10 deletions prefill_haalcentraalhr/tests/test_plugin_with_token_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
from openforms.authentication.constants import AuthAttribute
from openforms.pre_requests.base import PreRequestHookBase
from openforms.pre_requests.registry import Registry
from openforms.registrations.contrib.zgw_apis.tests.factories import ServiceFactory
from openforms.submissions.models import Submission
from openforms.submissions.tests.factories import SubmissionFactory
from requests.auth import AuthBase
from requests_mock import Mocker
from zgw_consumers.constants import APITypes
from zgw_consumers.test import mock_service_oas_get
from zgw_consumers_ext.tests.factories import ServiceFactory

from ..models import HaalCentraalHRConfig
from ..plugin import HaalCentraalHRPrefill
Expand Down Expand Up @@ -51,13 +50,6 @@ def __call__(
@override_settings(ZGW_CONSUMERS_TEST_SCHEMA_DIRS=[FILES_DIR])
class HaalCentraalHRPluginWithTokenExchangeTests(TestCase):
def test_token_exchange(self, m):
mock_service_oas_get(
m,
url="http://haalcentraal-hr.nl/api/",
service="haalcentraal-hr-oas",
oas_url="https://haalcentraal-hr.nl/api/schema/openapi.yaml",
)

with open(FILES_DIR / "maatschappelijkeactiviteiten-response.json", "rb") as f:
m.get(
"http://haalcentraal-hr.nl/api/maatschappelijkeactiviteiten/111222333",
Expand All @@ -82,7 +74,7 @@ def test_token_exchange(self, m):
)

with patch(
"prefill_haalcentraalhr.plugin.HaalCentraalHRConfig.get_solo",
"prefill_haalcentraalhr.client.HaalCentraalHRConfig.get_solo",
return_value=HaalCentraalHRConfig(service=service),
), patch(
"openforms.pre_requests.clients.registry",
Expand Down

0 comments on commit c04bf9c

Please sign in to comment.