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

[#2560] Treat catalogus as a required field on zaaktype response #1259

Merged
merged 1 commit into from
Jun 18, 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
3 changes: 1 addition & 2 deletions src/open_inwoner/openzaak/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class ZaakType(ZGWModel):
url: str
identificatie: str
omschrijving: str
catalogus: str
vertrouwelijkheidaanduiding: str
doel: str
aanleiding: str
Expand All @@ -129,8 +130,6 @@ class ZaakType(ZGWModel):
# roltypen: list
# besluittypen: list

# catalogus not on eSuite
catalogus: str = ""
begin_geldigheid: Optional[date] = None
einde_geldigheid: Optional[date] = None
versiedatum: Optional[date] = None
Expand Down
45 changes: 6 additions & 39 deletions src/open_inwoner/openzaak/tests/test_zgw_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ def __init__(self):
self.extra_zaaktype,
]

def install_mocks(self, m, *, with_catalog=True) -> "ZaakTypeMockData":
if not with_catalog:
for zt in self.all_zaak_types:
zt["catalogus"] = None

def install_mocks(self, m) -> "ZaakTypeMockData":
m.get(
f"{CATALOGI_ROOT}zaaktypen",
json=paginated_response(self.zaak_types),
Expand Down Expand Up @@ -238,38 +234,9 @@ def test_import_zaaktype_configs_with_catalogs(self, m):

def test_import_zaaktype_configs_without_catalogs(self, m):
data = ZaakTypeMockData()
data.install_mocks(m, with_catalog=False)

res = import_zaaktype_configs()

# first two got added, third one has same identificatie, fourth one is internal
self.assertEqual(len(res), 2)
self.assertEqual(ZaakTypeConfig.objects.count(), 2)

for i, config in enumerate(res):
self.assertEqual(config.identificatie, data.zaak_types[i]["identificatie"])
self.assertEqual(config.omschrijving, data.zaak_types[i]["omschrijving"])
self.assertIsNone(config.catalogus)

# run again with same API response
res = import_zaaktype_configs()

# nothing got added
self.assertEqual(len(res), 0)
self.assertEqual(ZaakTypeConfig.objects.count(), 2)

# add more elements to API response and run again
m.get(
f"{CATALOGI_ROOT}zaaktypen",
json=paginated_response([data.extra_zaaktype] + data.zaak_types),
)
res = import_zaaktype_configs()

# one got added
self.assertEqual(len(res), 1)
self.assertEqual(ZaakTypeConfig.objects.count(), 3)
data.install_mocks(m)

config = res[0]
self.assertEqual(config.identificatie, data.extra_zaaktype["identificatie"])
self.assertEqual(config.omschrijving, data.extra_zaaktype["omschrijving"])
self.assertIsNone(config.catalogus)
with self.assertRaises(
RuntimeError, msg="Catalogus must exist prior to import"
):
import_zaaktype_configs()
72 changes: 2 additions & 70 deletions src/open_inwoner/openzaak/tests/test_zgw_imports_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,73 +122,5 @@ def test_zgw_import_data_command_without_catalog(self, m):
)
InformationObjectTypeMockData().install_mocks(m, with_catalog=False)

# # run it to import our data
out = StringIO()
call_command("zgw_import_data", stdout=out)

self.assertEqual(CatalogusConfig.objects.count(), 0)
self.assertEqual(ZaakTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeInformatieObjectTypeConfig.objects.count(), 3)
self.assertEqual(ZaakTypeStatusTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeResultaatTypeConfig.objects.count(), 2)

stdout = out.getvalue().strip()

expected = inspect.cleandoc(
"""
imported 0 new catalogus configs

imported 2 new zaaktype configs
AAA - zaaktype-aaa
BBB - zaaktype-bbb

imported 3 new zaaktype-informatiebjecttype configs
AAA - zaaktype-aaa
info-aaa-1
info-aaa-2
BBB - zaaktype-bbb
info-bbb

imported 2 new zaaktype-statustype configs
AAA - zaaktype-aaa
AAA - status-aaa-1
AAA - status-aaa-2

imported 2 new zaaktype-resultaattype configs
AAA - zaaktype-aaa
AAA - test
BBB - zaaktype-bbb
BBB - test
"""
).strip()

self.assertEqual(stdout, expected)

# run it again without changes
out = StringIO()
call_command("zgw_import_data", stdout=out)

# still same
self.assertEqual(CatalogusConfig.objects.count(), 0)
self.assertEqual(ZaakTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeInformatieObjectTypeConfig.objects.count(), 3)
self.assertEqual(ZaakTypeStatusTypeConfig.objects.count(), 2)
self.assertEqual(ZaakTypeResultaatTypeConfig.objects.count(), 2)

stdout = out.getvalue().strip()

expected = inspect.cleandoc(
"""
imported 0 new catalogus configs

imported 0 new zaaktype configs

imported 0 new zaaktype-informatiebjecttype configs

imported 0 new zaaktype-statustype configs

imported 0 new zaaktype-resultaattype configs
"""
).strip()

self.assertEqual(stdout, expected)
with self.assertRaises(RuntimeError):
call_command("zgw_import_data")
20 changes: 8 additions & 12 deletions src/open_inwoner/openzaak/zgw_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,16 @@ def import_zaaktype_configs() -> list[ZaakTypeConfig]:
)

for zaak_type in zaak_types:
catalog = None
if zaak_type.catalogus:
catalog = catalog_lookup.get(zaak_type.catalogus)
if not catalog:
# weird edge-case: if the zaak_type has a catalogus-url but we don't have the object
# TODO this is bad, log/raise something
pass
try:
catalog = catalog_lookup[zaak_type.catalogus]
except KeyError as exc:
raise RuntimeError(
f"ZaakType `{zaak_type.url}` points to a Catalogus at"
f" `{zaak_type.catalogus}` which is not currently configured."
) from exc

# make key for de-duplication and collapsing related zaak-types on their 'identificatie'
if catalog:
key = (catalog.id, zaak_type.identificatie)
else:
key = (None, zaak_type.identificatie)

key = (catalog.id, zaak_type.identificatie)
if key not in known_keys:
known_keys.add(key)
create[key] = ZaakTypeConfig(
Expand Down
Loading