Skip to content

Commit

Permalink
Merge pull request #1523 from open-zaak/issue/1474-fix-missing-catalo…
Browse files Browse the repository at this point in the history
…gus-exception

🐛[#1474] fix exception thrown with bad catalogus ID
  • Loading branch information
Coperh committed Dec 11, 2023
2 parents 2d42dce + aa499d4 commit b1b24fb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/openzaak/components/catalogi/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ def clean(self):
"onder Datum begin geldigheid."
)
)
try:
catalogus = self.catalogus
except self.__class__.catalogus.RelatedObjectDoesNotExist:
return

if has_overlapping_objects(
model_manager=self._meta.default_manager,
catalogus=self.catalogus,
catalogus=catalogus,
omschrijving_query={
self.omschrijving_field: getattr(self, self.omschrijving_field)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,44 @@ def test_default_selectielijst_year_regression(self, m):
"f4603775-5a08-4829-85c8-28017dfeee1f",
)

def test_submit_zaaktype_with_no_catalogus(self, m):
"""
Test that no catalogus ID provided causes a validation error and not an exception.
Fixes #1474
"""
url = reverse("admin:catalogi_zaaktype_add")
mock_selectielijst_oas_get(m)
mock_resource_list(m, "procestypen")
add_page = self.app.get(url)
form = add_page.form

response = form.submit()

form = response.context["adminform"].form
self.assertEqual(response.status_code, 200)
self.assertIn("Dit veld is vereist.", form.errors["catalogus"])

def test_submit_zaaktype_with_bad_catalogus(self, m):
"""
Test that a bad catalogus ID causes a validation error and not an exception.
Fixes #1474
"""
url = reverse("admin:catalogi_zaaktype_add")
mock_selectielijst_oas_get(m)
mock_resource_list(m, "procestypen")
add_page = self.app.get(url)
form = add_page.form

form["catalogus"] = 16
response = form.submit()

form = response.context["adminform"].form
self.assertEqual(response.status_code, 200)
self.assertIn(
"Selecteer een geldige keuze. Deze keuze is niet beschikbaar.",
form.errors["catalogus"],
)


class ZaakTypePublishAdminTests(SelectieLijstMixin, WebTest):
@classmethod
Expand Down

0 comments on commit b1b24fb

Please sign in to comment.