Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2046] Add regression test for e-suite missing statuses
Browse files Browse the repository at this point in the history
pi-sigma committed Jan 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e3d539f commit 3c08798
Showing 2 changed files with 102 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
@@ -148,7 +148,6 @@ def get_context_data(self, **kwargs):
documents = self.get_case_document_files(self.case)
statuses = fetch_status_history(self.case.url)
self.store_statustype_resulttype_mapping(self.case.zaaktype.identificatie)
# NOTE maybe this should be cached?
statustypen = fetch_status_types_no_cache(self.case.zaaktype.url)

# NOTE we cannot sort on the Status.datum_status_gezet (datetime) because eSuite
@@ -163,18 +162,22 @@ def get_context_data(self, **kwargs):
else:
second_status_preview = None

# transform current status of `self.case` to ZGW model object
status_types = defaultdict(list)
for status in statuses:
status_types[status.statustype].append(status)
if self.case.status == status.url:
self.case.status = status

if type(self.case.status) == str:
# e-suite compatibility
if isinstance(self.case.status, str):
logger.info(
"Issue #2037 -- Retrieving status individually to deal with the situation where eSuite doesnt return current status as part of statuslist retrieval"
"Issue #2037 -- Retrieving status individually to deal with the situation"
"where eSuite doesnt return current status as part of statuslist retrieval"
)
self.case.status = fetch_single_status(self.case.status)
status_types[self.case.status.statustype].append(self.case.status)
statuses.append(self.case.status)

for status_type_url, _statuses in list(status_types.items()):
# todo parallel
96 changes: 96 additions & 0 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import requests_mock
from django_webtest import WebTest
from freezegun import freeze_time
from pyquery import PyQuery
from timeline_logger.models import TimelineLog
from webtest import Upload
from webtest.forms import Hidden
@@ -877,6 +878,101 @@ def test_document_ordering_by_name(self, m):
self.assertEqual(documents[1].name, "uploaded_document_title.txt")
self.assertEqual(documents[2].name, "yet_another_document_title.txt")

@patch("open_inwoner.cms.cases.views.status.fetch_status_history")
def test_e_suite_missing_current_status_fetch_status(
self, m, mock_fetch_status_history
):
"""
Regression test for #2037
eSuite can fail to return the status of the current case as part of status
history, which causes the upload button to be hidden. Check that the status
is fetched if it's missing from the eSuite response.
"""
self.maxDiff = None

# e-suite returns nothing, hence status history list is empty
mock_fetch_status_history.return_value = []
m.get(
f"{ZAKEN_ROOT}statussen/29ag1264-c4he-249j-bc24-jip862tle833",
json=self.status_finish,
)

status_new_obj, status_finish_obj = factory(
Status, [self.status_new, self.status_finish]
)
status_new_obj.statustype = factory(StatusType, self.status_type_new)
status_finish_obj.statustype = factory(StatusType, self.status_type_finish)

response = self.app.get(self.case_detail_url, user=self.user)

self.assertEqual(
response.context.get("case")["statuses"],
[
{
"date": datetime.datetime(2021, 3, 12, 0, 0),
"label": "Finish",
"status_indicator": None,
"status_indicator_text": None,
"call_to_action_url": None,
"call_to_action_text": None,
"description": None,
"case_link_text": "Bekijk aanvraag",
}
],
)

@patch("open_inwoner.cms.cases.views.status.fetch_status_history")
def test_e_suite_missing_current_status_upload_button_displayed(
self, m, mock_fetch_status_history
):
"""
Regression test for #2037
eSuite can fail to return the status of the current case as part of status
history, which causes the upload button to be hidden. Check that the upload
button is displayed.
"""
self.maxDiff = None
self._setUpMocks(m)

# e-suite returns nothing, hence status history list is empty
mock_fetch_status_history.return_value = []
m.get(
f"{ZAKEN_ROOT}statussen/29ag1264-c4he-249j-bc24-jip862tle833",
json=self.status_finish,
)

zaak_type_config = ZaakTypeConfigFactory(
catalogus__url=f"{CATALOGI_ROOT}catalogussen/1b643db-81bb-d71bd5a2317a",
identificatie=self.zaaktype["identificatie"],
)
zaak_type_iotc = ZaakTypeInformatieObjectTypeConfigFactory(
zaaktype_config=zaak_type_config,
informatieobjecttype_url=self.informatie_object["url"],
zaaktype_uuids=[self.zaaktype["uuid"]],
document_upload_enabled=True,
)
zt_statustype_config = ZaakTypeStatusTypeConfigFactory(
zaaktype_config=zaak_type_config,
statustype_url=self.status_type_finish["url"],
zaaktype_uuids=[self.zaaktype["uuid"]],
document_upload_description="- Foo\n- bar",
)
response = self.app.get(
reverse(
"cases:case_detail_content",
kwargs={"object_id": self.zaak["uuid"]},
),
user=self.user,
)

doc = PyQuery(response.content)

upload_button = doc.find("#document-upload").find("button")

self.assertEqual(upload_button.text(), "Upload documenten")

@freeze_time("2021-01-12 17:00:00")
def test_new_docs(self, m):
self._setUpMocks(m)

0 comments on commit 3c08798

Please sign in to comment.