Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2234] Fix subject for questions without e-suite code mapping #1100

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading