Skip to content

Commit

Permalink
[#2640] Update tests to check long case result description
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Jul 29, 2024
1 parent f19e912 commit 60112ae
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 10 deletions.
14 changes: 13 additions & 1 deletion src/open_inwoner/cms/cases/tests/test_contactform.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,23 @@ def setUp(self):
volgnummer=1,
isEindstatus=True,
)
self.resultaattype_with_naam = generate_oas_component_cached(
"ztc",
"schemas/ResultaatType",
url=f"{CATALOGI_ROOT}resultaattypen/b1a268dd-4322-47bb-a930-b83066b4a32c",
zaaktype=self.zaaktype["url"],
omschrijving="Short description",
resultaattypeomschrijving="http://example.com",
selectielijstklasse="http://example.com",
naam="Long description (>20 chars) of result",
)
self.result = generate_oas_component_cached(
"zrc",
"schemas/Resultaat",
uuid="a44153aa-ad2c-6a07-be75-15add5113",
url=self.zaak["resultaat"],
resultaattype=f"{CATALOGI_ROOT}resultaattypen/b1a268dd-4322-47bb-a930-b83066b4a32c",
# resultaattype=f"{CATALOGI_ROOT}resultaattypen/b1a268dd-4322-47bb-a930-b83066b4a32c",
resultaattype=self.resultaattype_with_naam["url"],
zaak=self.zaak["url"],
toelichting="resultaat toelichting",
)
Expand Down Expand Up @@ -259,6 +270,7 @@ def _setUpMocks(self, m):
for resource in [
self.zaak,
self.result,
self.resultaattype_with_naam,
self.zaaktype,
self.status_finish,
self.status_type_finish,
Expand Down
13 changes: 12 additions & 1 deletion src/open_inwoner/cms/cases/tests/test_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,22 @@ def setUp(self) -> None:
"geslachtsnaam": "Bazz",
},
)
self.resultaattype_with_naam = generate_oas_component_cached(
"ztc",
"schemas/ResultaatType",
url=f"{CATALOGI_ROOT}resultaattypen/b1a268dd-4322-47bb-a930-b83066b4a32c",
zaaktype=self.zaaktype["url"],
omschrijving="Short description",
resultaattypeomschrijving="http://example.com",
selectielijstklasse="http://example.com",
naam="Long description (>20 chars) of result",
)
self.result = generate_oas_component_cached(
"zrc",
"schemas/Resultaat",
uuid="a44153aa-ad2c-6a07-be75-15add5113",
url=self.zaak["resultaat"],
resultaattype=f"{CATALOGI_ROOT}resultaattypen/b1a268dd-4322-47bb-a930-b83066b4a32c",
resultaattype=self.resultaattype_with_naam["url"],
zaak=self.zaak["url"],
toelichting="resultaat toelichting",
)
Expand Down Expand Up @@ -324,6 +334,7 @@ def _setUpMocks(self, m):

for resource in [
self.zaak,
self.resultaattype_with_naam,
self.result,
self.zaaktype,
self.status_type_new,
Expand Down
24 changes: 20 additions & 4 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)
from open_inwoner.openzaak.api_models import Status, StatusType, Zaak
from open_inwoner.openzaak.clients import (
CatalogiClient,
ZakenClient,
build_catalogi_client,
build_documenten_client,
Expand Down Expand Up @@ -172,6 +173,7 @@ def get_context_data(self, **kwargs):
question, kcm_answer_mapping
)

# TODO: Zaken API depends on Catalogi API (according to spec), so this should not be conditional
statustypen = []
if catalogi_client := build_catalogi_client():
statustypen = catalogi_client.fetch_status_types_no_cache(
Expand All @@ -198,8 +200,9 @@ def get_context_data(self, **kwargs):
status_types_mapping=status_types_mapping,
end_statustype=self.handle_end_statustype(statuses, statustypen),
)

result_data = self.get_result_data(
self.case, self.resulttype_config_mapping, zaken_client
self.case, self.resulttype_config_mapping, zaken_client, catalogi_client
)

hooks.case_status_seen(self.request.user, self.case)
Expand Down Expand Up @@ -521,15 +524,28 @@ def get_upload_info_context(self, case: Zaak):

@staticmethod
def get_result_data(
case: Zaak, result_type_config_mapping: dict, client: ZakenClient
case: Zaak,
result_type_config_mapping: dict,
zaken_client: ZakenClient,
catalogi_client: CatalogiClient,
) -> dict:
"""
Get display and description for the result of `case`
Note:
For the description, we try the `naam` attribute of the corresponding resultaattype
first. This is for E-suite compatibility in case the E-suite returns a description
longer than 20 chars. Alternatively, we get the description from the config of the
resultaattype.
"""
if not case.resultaat:
return {}

result = client.fetch_single_result(case.resultaat)
result = zaken_client.fetch_single_result(case.resultaat)
result_type = catalogi_client.fetch_single_resultaat_type(result.resultaattype)

display = result.toelichting
description = getattr(
description = getattr(result_type, "naam", "") or getattr(
result_type_config_mapping.get(result.resultaattype), "description", ""
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def test_cms_ssd_override_settings(self):

self.assertTrue(benefits_page_is_published())

# import pdbr;pdbr.set_trace()
# check common extension
page = Page.objects.get(publisher_is_draft=False)
extension = page.commonextension
Expand Down
8 changes: 8 additions & 0 deletions src/open_inwoner/openzaak/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
UserCaseStatusNotification,
ZaakTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
ZaakTypeResultaatTypeConfig,
ZaakTypeStatusTypeConfig,
ZGWApiGroupConfig,
)
Expand Down Expand Up @@ -90,6 +91,13 @@ class Meta:
model = ZaakTypeConfig


class ZaakTypeResultaatTypeConfigFactory(factory.django.DjangoModelFactory):
zaaktype_config = factory.SubFactory(ZaakTypeConfigFactory)

class Meta:
model = ZaakTypeResultaatTypeConfig


class ZaakTypeInformatieObjectTypeConfigFactory(factory.django.DjangoModelFactory):
zaaktype_config = factory.SubFactory(ZaakTypeConfigFactory)
informatieobjecttype_url = factory.Faker("url")
Expand Down
25 changes: 22 additions & 3 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from open_inwoner.openzaak.tests.factories import (
ZaakTypeConfigFactory,
ZaakTypeInformatieObjectTypeConfigFactory,
ZaakTypeResultaatTypeConfigFactory,
ZaakTypeStatusTypeConfigFactory,
)
from open_inwoner.utils.test import (
Expand Down Expand Up @@ -213,6 +214,16 @@ def setUp(self):
richting="inkomend",
statustype=self.status_type_finish,
)
self.resultaattype_with_naam = generate_oas_component_cached(
"ztc",
"schemas/ResultaatType",
url=f"{CATALOGI_ROOT}resultaattypen/3dc5e2d3-ed72-41ec-a91e-000f72a7b291",
zaaktype=self.zaaktype["url"],
omschrijving="Short description",
resultaattypeomschrijving="http://example.com",
selectielijstklasse="http://example.com",
naam="Long description (>20 chars) of result",
)

#
# Documenten API (DRC)
Expand Down Expand Up @@ -418,7 +429,7 @@ def setUp(self):
"schemas/Resultaat",
uuid="a44153aa-ad2c-6a07-be75-15add5113",
url=self.zaak["resultaat"],
resultaattype=f"{CATALOGI_ROOT}resultaattypen/b1a268dd-4322-47bb-a930-b83066b4a32c",
resultaattype=self.resultaattype_with_naam["url"],
zaak=self.zaak["url"],
toelichting="resultaat toelichting",
)
Expand Down Expand Up @@ -581,6 +592,7 @@ def _setUpMocks(self, m, use_eindstatus=True):
self.informatie_object,
self.informatie_object_2,
self.informatie_object_invisible,
self.resultaattype_with_naam,
self.zaaktype_informatie_object_type,
self.status_type_new,
self.status_type_in_behandeling,
Expand Down Expand Up @@ -713,6 +725,13 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(
case_link_text="Bekijk aanvraag",
)

ZaakTypeResultaatTypeConfigFactory.create(
zaaktype_config=self.zaaktype_config,
resultaattype_url=self.resultaattype_with_naam["url"],
omschrijving=self.resultaattype_with_naam["omschrijving"],
zaaktype_uuids=[self.zaaktype["uuid"]],
)

self._setUpMocks(m)
status_new_obj, status_finish_obj = factory(
Status, [self.status_new, self.status_finish]
Expand Down Expand Up @@ -766,7 +785,7 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(
],
"initiator": "Foo Bar van der Bazz",
"result": "resultaat toelichting",
"result_description": "",
"result_description": "Long description (>20 chars) of result",
"case_type_config_description": "",
"case_type_document_upload_description": "",
"internal_upload_enabled": False,
Expand Down Expand Up @@ -888,7 +907,7 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
],
"initiator": "Foo Bar van der Bazz",
"result": "resultaat toelichting",
"result_description": "",
"result_description": "Long description (>20 chars) of result",
"case_type_config_description": "",
"case_type_document_upload_description": "",
"internal_upload_enabled": False,
Expand Down

0 comments on commit 60112ae

Please sign in to comment.