Skip to content

Commit

Permalink
Merge pull request #1100 from maykinmedia/fix/2234-contactmomenten-su…
Browse files Browse the repository at this point in the history
…bject

[#2234] Fix subject for questions without e-suite code mapping
  • Loading branch information
alextreme authored Mar 20, 2024
2 parents 62e7777 + e7d0338 commit c844fa4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
16 changes: 7 additions & 9 deletions src/open_inwoner/accounts/views/contactmoments.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ def get_kcm_data(
),
}

# replace e_suite_subject_code with OIP configured subject, if applicable
e_suite_subject_code = getattr(kcm.contactmoment, "onderwerp", None)

data["onderwerp"] = self.get_kcm_subject(kcm, e_suite_subject_code)
data["onderwerp"] = self.get_kcm_subject(kcm)

return data

Expand All @@ -114,13 +111,14 @@ def get_context_data(self, **kwargs):
def get_kcm_subject(
self,
kcm: KlantContactMoment,
e_suite_subject_code: str | None,
) -> str | None:
"""
Try to determine the subject ('onderwerp') of a contactmoment
Determine the subject (`onderwerp`) of a `KlantContactMoment.contactmoment`:
1. replace e-suite subject code with OIP configured subject or
2. return e-suite subject code or
3. return an empty string as fallback
"""
if not e_suite_subject_code:
return None
e_suite_subject_code = getattr(kcm.contactmoment, "onderwerp", "")

try:
subject = ContactFormSubject.objects.get(subject_code=e_suite_subject_code)
Expand All @@ -133,7 +131,7 @@ def get_kcm_subject(
kcm.contactmoment.url,
exc_info=exc,
)
return None
return e_suite_subject_code

return subject.subject

Expand Down
39 changes: 35 additions & 4 deletions src/open_inwoner/openklant/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@
class ContactMomentViewsTestCase(ClearCachesMixin, DisableRequestLogMixin, WebTest):
maxDiff = None

@classmethod
def setUpTestData(cls):
super().setUpTestData()
def setUp(self):
super().setUp()
MockAPIReadData.setUpServices()

# for testing replacement of e-suite "onderwerp" code with OIP configured subject
cls.contactformsubject = ContactFormSubject.objects.create(
self.contactformsubject = ContactFormSubject.objects.create(
subject="oip_subject",
subject_code="e_suite_subject_code",
config=OpenKlantConfig.get_solo(),
Expand Down Expand Up @@ -363,6 +362,38 @@ def test_show_detail_for_bsn_with_zaak_reformat_esuite_id(
),
)

def test_display_esuite_subject_code(self, m, mock_get_kcm_answer_mapping):
data = MockAPIReadData().install_mocks(m)

ContactFormSubject.objects.first().delete()

detail_url = reverse(
"cases:contactmoment_detail",
kwargs={"kcm_uuid": data.klant_contactmoment["uuid"]},
)
list_url = reverse("cases:contactmoment_list")
response = self.app.get(list_url, user=data.user)

kcms = response.context["contactmomenten"]
cm_data = data.contactmoment

self.assertEqual(len(kcms), 1)
self.assertEqual(
kcms[0],
{
"registered_date": datetime.fromisoformat(cm_data["registratiedatum"]),
"channel": cm_data["kanaal"].title(),
"text": cm_data["tekst"],
"onderwerp": "e_suite_subject_code",
"antwoord": cm_data["antwoord"],
"identificatie": cm_data["identificatie"],
"type": cm_data["type"],
"status": Status.afgehandeld.label,
"url": detail_url,
"new_answer_available": False,
},
)

def test_show_detail_for_kvk_or_rsin(self, m, mock_get_kcm_answer_mapping):
for use_rsin_for_innNnpId_query_parameter in [True, False]:
with self.subTest(
Expand Down

0 comments on commit c844fa4

Please sign in to comment.