From 49936995e0a3741b3a21e6a45b994443ec40807a Mon Sep 17 00:00:00 2001 From: Paul Schilling Date: Mon, 11 Dec 2023 14:08:30 +0100 Subject: [PATCH] [#1928] Check missing volgnummer for second status preview --- src/open_inwoner/cms/cases/views/status.py | 4 ++ src/open_inwoner/openzaak/api_models.py | 2 +- .../openzaak/tests/test_case_detail.py | 61 ++++++++++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index cc193d5750..cb3712a51c 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -251,6 +251,10 @@ def get_second_status_preview(self, statustypen: list) -> Optional[StatusType]: """ statustype_numbers = [s.volgnummer for s in statustypen] + # status_types retrieved via eSuite don't always have a volgnummer + if not all(statustype_numbers): + return + # only 1 statustype for `self.case` # (this scenario is blocked by openzaak, but not part of the zgw standard) if len(statustype_numbers) < 2: diff --git a/src/open_inwoner/openzaak/api_models.py b/src/open_inwoner/openzaak/api_models.py index e4b7b73207..005cc78869 100644 --- a/src/open_inwoner/openzaak/api_models.py +++ b/src/open_inwoner/openzaak/api_models.py @@ -229,7 +229,7 @@ class StatusType(ZGWModel): url: str # bug: not required according to OAS zaaktype: str omschrijving: str - volgnummer: int + volgnummer: Optional[int] # not in eSuite omschrijving_generiek: str = "" statustekst: str = "" is_eindstatus: bool = False diff --git a/src/open_inwoner/openzaak/tests/test_case_detail.py b/src/open_inwoner/openzaak/tests/test_case_detail.py index d2e3877f4c..a5e4a0c415 100644 --- a/src/open_inwoner/openzaak/tests/test_case_detail.py +++ b/src/open_inwoner/openzaak/tests/test_case_detail.py @@ -2,6 +2,7 @@ from unittest.mock import patch from django.contrib.auth.models import AnonymousUser +from django.test import RequestFactory from django.test.utils import override_settings from django.urls import reverse from django.utils.translation import gettext_lazy as _ @@ -23,7 +24,7 @@ from open_inwoner.accounts.choices import LoginTypeChoices from open_inwoner.accounts.tests.factories import UserFactory, eHerkenningUserFactory -from open_inwoner.cms.cases.views.status import SimpleFile +from open_inwoner.cms.cases.views.status import InnerCaseDetailView, SimpleFile from open_inwoner.openzaak.constants import StatusIndicators from open_inwoner.openzaak.tests.factories import ( StatusTranslationFactory, @@ -204,12 +205,12 @@ def setUpTestData(cls): cls.second_status_preview = StatusType( url=cls.status_type_in_behandeling["url"], zaaktype=cls.status_type_in_behandeling["zaaktype"], - omschrijving=cls.status_type_in_behandeling["omschrijving"], - volgnummer=cls.status_type_in_behandeling["volgnummer"], + omschrijving="In behandeling", omschrijving_generiek=cls.status_type_in_behandeling[ "omschrijvingGeneriek" ], statustekst=cls.status_type_in_behandeling["statustekst"], + volgnummer=3, is_eindstatus=cls.status_type_in_behandeling["isEindstatus"], informeren=cls.status_type_in_behandeling["informeren"], ) @@ -625,6 +626,60 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m): }, ) + def test_second_status_preview(self, m): + """Unit test for `InnerCaseDetailView.get_second_status_preview`""" + + request = RequestFactory().get("/") + detail_view = InnerCaseDetailView() + detail_view.setup(request) + detail_view.case = self.zaak + + st1 = StatusType( + url="http://statustype_2.com", + zaaktype=self.status_type_in_behandeling["zaaktype"], + omschrijving=self.status_type_in_behandeling["omschrijving"], + volgnummer=2, + omschrijving_generiek=self.status_type_in_behandeling[ + "omschrijvingGeneriek" + ], + statustekst=self.status_type_in_behandeling["statustekst"], + is_eindstatus=self.status_type_in_behandeling["isEindstatus"], + informeren=self.status_type_in_behandeling["informeren"], + ) + st2 = StatusType( + url="http://statustype_1.com", + zaaktype=self.status_type_new["zaaktype"], + omschrijving=self.status_type_new["omschrijving"], + volgnummer=1, + omschrijving_generiek=self.status_type_new["omschrijvingGeneriek"], + statustekst=self.status_type_new["statustekst"], + is_eindstatus=self.status_type_new["isEindstatus"], + informeren=self.status_type_new["informeren"], + ) + st3 = StatusType( + url=self.status_type_in_behandeling["url"], + zaaktype=self.status_type_in_behandeling["zaaktype"], + omschrijving=self.status_type_in_behandeling["omschrijving"], + volgnummer=None, + omschrijving_generiek=self.status_type_in_behandeling[ + "omschrijvingGeneriek" + ], + statustekst=self.status_type_in_behandeling["statustekst"], + is_eindstatus=self.status_type_in_behandeling["isEindstatus"], + informeren=self.status_type_in_behandeling["informeren"], + ) + + test_cases = [ + ([st1, st2], st1), # OK + ([st1, st2, st3], None), # status_type with volgnummer=None + ([st1], None), # no second status_type + ([], None), # no status_type + ] + for i, (status_types, result) in enumerate(test_cases): + with self.subTest(i=i): + res = detail_view.get_second_status_preview(status_types) + self.assertEqual(res, result) + @freeze_time("2021-01-12 17:00:00") def test_new_docs(self, m): self._setUpMocks(m)