Skip to content

Commit f53da53

Browse files
committed
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! ✨ [#500] Implement Referentielijsten integration for Klantcontact
1 parent 66cf829 commit f53da53

File tree

6 files changed

+88
-41
lines changed

6 files changed

+88
-41
lines changed

src/openklant/config/tests/test_models.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -57,41 +57,3 @@ def test_validation_fails_for_invalid_kanaal(self):
5757
self.assertIn("'fax' is not a valid kanaal", str(cm.exception))
5858
self.assertIn("email", str(cm.exception))
5959
self.assertIn("phone", str(cm.exception))
60-
61-
# @patch(PATCH_TARGET, autospec=True)
62-
# def test_validation_succeeds_when_config_is_disabled(self, mock_get_items):
63-
# ReferentielijstenConfig.objects.all().update(enabled=False)
64-
#
65-
# validator = KanaalValidator()
66-
#
67-
# validator("not-a-real-channel")
68-
# mock_get_items.assert_not_called()
69-
#
70-
# @patch(PATCH_TARGET, autospec=True)
71-
# def test_validation_fails_on_api_400(self, mock_get_items):
72-
# from requests.exceptions import HTTPError
73-
# from requests.models import Response
74-
#
75-
# response = Response()
76-
# response.status_code = 400
77-
# mock_get_items.side_effect = HTTPError(response=response)
78-
#
79-
# validator = KanaalValidator()
80-
# with self.assertRaises(ValidationError) as cm:
81-
# validator("email")
82-
#
83-
# self.assertIn(
84-
# "Failed to retrieve valid channels from the API", str(cm.exception)
85-
# )
86-
#
87-
# @patch(PATCH_TARGET, autospec=True)
88-
# def test_validation_fails_on_api_request_exception(self, mock_get_items):
89-
# mock_get_items.side_effect = RequestException("Timeout occurred")
90-
#
91-
# validator = KanaalValidator()
92-
# with self.assertRaises(ValidationError) as cm:
93-
# validator("email")
94-
#
95-
# self.assertIn(
96-
# "Failed to retrieve valid channels from the API", str(cm.exception)
97-
# )

src/referentielijsten_client/setup_configuration/steps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def execute(self, model: ReferentielijstenConfigurationModel) -> None:
2929
logger.info(
3030
"configuring_referentielijsten",
3131
enabled=model.enabled,
32-
service_identifier=model.service_identifier,
32+
service_identifier=model.referentielijsten_api_service_identifier,
3333
)
3434

3535
service = None
36-
if identifier := model.service_identifier:
36+
if identifier := model.referentielijsten_api_service_identifier:
3737
try:
3838
service = get_service(identifier)
3939
except Service.DoesNotExist as exc:
@@ -46,7 +46,7 @@ def execute(self, model: ReferentielijstenConfigurationModel) -> None:
4646
config_instance.enabled = model.enabled
4747
config_instance.service = service
4848

49-
config_instance.kanalen_tabel_code = model.tabel_code
49+
config_instance.kanalen_tabel_code = model.kanalen_tabel_code
5050

5151
config_instance.save()
5252

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
referentielijsten_config:
2+
enabled: true
3+
referentielijsten_api_service_identifier: referentielijsten-api-test
4+
kanalen_tabel_code: KANAAL
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
referentielijsten_config:
2+
enabled: true
3+
referentielijsten_api_service_identifier: idempotent-service
4+
kanalen_tabel_code: TABEL_IDEMPOTENT
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
referentielijsten_config:
2+
enabled: true
3+
referentielijsten_api_service_identifier: non-existent-api
4+
kanalen_tabel_code: KANAAL
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from pathlib import Path
2+
3+
from django.test import TestCase
4+
5+
from django_setup_configuration.exceptions import ConfigurationRunFailed
6+
from django_setup_configuration.test_utils import execute_single_step
7+
from zgw_consumers.test.factories import ServiceFactory
8+
9+
from openklant.config.models import ReferentielijstenConfig
10+
from referentielijsten_client.setup_configuration.steps import (
11+
ReferentielijstenConfigurationStep,
12+
)
13+
14+
TEST_FILES = (Path(__file__).parent / "files").resolve()
15+
16+
17+
class ReferentielijstenConfigurationStepTests(TestCase):
18+
def setUp(self):
19+
ReferentielijstenConfig.objects.all().delete()
20+
21+
def test_happy_flow(self):
22+
service = ServiceFactory(
23+
slug="referentielijsten-api-test", api_root="http://test.nl/api/v1"
24+
)
25+
26+
test_file_path = str(TEST_FILES / "referentielijsten_happy_flow.yaml")
27+
28+
execute_single_step(
29+
ReferentielijstenConfigurationStep, yaml_source=test_file_path
30+
)
31+
32+
config = ReferentielijstenConfig.get_solo()
33+
34+
self.assertTrue(config.enabled)
35+
self.assertEqual(config.service, service)
36+
self.assertEqual(config.kanalen_tabel_code, "KANAAL")
37+
38+
def test_error_flow_missing_service(self):
39+
test_file_path = str(TEST_FILES / "referentielijsten_missing_service.yaml")
40+
41+
with self.assertRaises(ConfigurationRunFailed) as cm:
42+
execute_single_step(
43+
ReferentielijstenConfigurationStep, yaml_source=test_file_path
44+
)
45+
46+
self.assertIn(
47+
"Could not find Service with identifier 'non-existent-api'",
48+
str(cm.exception),
49+
)
50+
51+
config = ReferentielijstenConfig.get_solo()
52+
self.assertFalse(config.enabled)
53+
self.assertIsNone(config.service)
54+
55+
def test_idempotency(self):
56+
service = ServiceFactory(
57+
slug="idempotent-service", api_root="http://idempotent.nl/api/v1"
58+
)
59+
60+
test_file_path = str(TEST_FILES / "referentielijsten_idempotent.yaml")
61+
62+
execute_single_step(
63+
ReferentielijstenConfigurationStep, yaml_source=test_file_path
64+
)
65+
66+
execute_single_step(
67+
ReferentielijstenConfigurationStep, yaml_source=test_file_path
68+
)
69+
70+
config = ReferentielijstenConfig.get_solo()
71+
self.assertTrue(config.enabled)
72+
self.assertEqual(config.service, service)
73+
self.assertEqual(config.kanalen_tabel_code, "TABEL_IDEMPOTENT")

0 commit comments

Comments
 (0)