Skip to content

Commit

Permalink
Merge pull request #1284 from maykinmedia/tasks/2570-import-iotypes-w…
Browse files Browse the repository at this point in the history
…ith-multi-zgw-backend

[#2570] Add multi-backend support to ZGW iotypes importer
  • Loading branch information
alextreme authored Jul 3, 2024
2 parents f227fc2 + a113ac1 commit abc196e
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 254 deletions.
2 changes: 1 addition & 1 deletion src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def lookups(self, request, model_admin):
catalogs = CatalogusConfig.objects.filter(
id__in=qs.values_list("catalogus_id", flat=True).distinct()
)
return [("none", "None")] + [(c.id, str(c)) for c in catalogs]
return [(c.id, str(c)) for c in catalogs]

def queryset(self, request, queryset):
v = self.value()
Expand Down
21 changes: 12 additions & 9 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import warnings
from datetime import timedelta
from urllib.parse import urlparse

from django.db import models, transaction
from django.db.models import UniqueConstraint
Expand Down Expand Up @@ -312,8 +313,13 @@ class CatalogusConfig(models.Model):
class Meta:
ordering = ("domein", "rsin")

@property
def base_url(self):
service_netloc = urlparse(self.service.api_root).netloc
return service_netloc

def __str__(self):
return f"{self.domein} - {self.rsin}"
return f"{self.domein} - {self.rsin} [{self.base_url}]"


class ZaakTypeConfig(models.Model):
Expand Down Expand Up @@ -400,17 +406,14 @@ class Meta:

@property
def catalogus_url(self):
if self.catalogus_id:
return self.catalogus.url
else:
return None
return self.catalogus.url

def __str__(self):
bits = (
self.identificatie,
self.omschrijving,
)
return " - ".join(b for b in bits if b)
return " - ".join(b for b in bits if b) + f" [{self.catalogus.base_url}]"


class ZaakTypeInformatieObjectTypeConfig(models.Model):
Expand Down Expand Up @@ -473,7 +476,7 @@ def informatieobjecttype_uuid(self):
informatieobjecttype_uuid.short_description = _("Information object UUID")

def __str__(self):
return self.omschrijving
return f"{self.omschrijving} [{self.zaaktype_config.catalogus.base_url}]"


class ZaakTypeStatusTypeConfig(models.Model):
Expand Down Expand Up @@ -593,7 +596,7 @@ class Meta:
]

def __str__(self):
return f"{self.zaaktype_config.identificatie} - {self.omschrijving}"
return f"{self.zaaktype_config.identificatie} - {self.omschrijving} [{self.zaaktype_config.catalogus.base_url}]"


class ZaakTypeResultaatTypeConfig(models.Model):
Expand Down Expand Up @@ -637,7 +640,7 @@ class Meta:
]

def __str__(self):
return f"{self.zaaktype_config.identificatie} - {self.omschrijving}"
return f"{self.zaaktype_config.identificatie} - {self.omschrijving} [{self.zaaktype_config.catalogus.base_url}]"


class UserCaseStatusNotificationBase(models.Model):
Expand Down
13 changes: 11 additions & 2 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,19 @@ def test_expected_information_object_types_are_available_in_upload_form(
form = response.forms["document-upload"]
type_field = form["type"]
expected_choices = [
(str(zaak_type_iotc1.id), False, zaak_type_iotc1.omschrijving),
(str(zaak_type_iotc2.id), False, zaak_type_iotc2.omschrijving),
(
str(zaak_type_iotc1.id),
False,
f"{zaak_type_iotc1.omschrijving} [{zaak_type_iotc1.zaaktype_config.catalogus.base_url}]",
),
(
str(zaak_type_iotc2.id),
False,
f"{zaak_type_iotc2.omschrijving} [{zaak_type_iotc2.zaaktype_config.catalogus.base_url}]",
),
]

# zaak_type_iotc1.zaaktype_config.catalogus.base_url
self.assertEqual(sorted(type_field.options), sorted(expected_choices))

@patch(
Expand Down
120 changes: 65 additions & 55 deletions src/open_inwoner/openzaak/tests/test_zgw_imports_command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import inspect
from io import StringIO
from unittest import skip

from django.core.management import call_command
from django.test import TestCase
Expand All @@ -16,7 +15,7 @@
ZaakTypeStatusTypeConfig,
)
from open_inwoner.openzaak.tests.factories import ZGWApiGroupConfigFactory
from open_inwoner.openzaak.tests.shared import CATALOGI_ROOT
from open_inwoner.openzaak.tests.shared import ANOTHER_CATALOGI_ROOT, CATALOGI_ROOT
from open_inwoner.openzaak.tests.test_zgw_imports import CatalogMockData
from open_inwoner.openzaak.tests.test_zgw_imports_iotypes import (
InformationObjectTypeMockData,
Expand All @@ -32,55 +31,77 @@ class ZGWImportTest(ClearCachesMixin, TestCase):
def setUpTestData(cls):
super().setUpTestData()

ZGWApiGroupConfigFactory(
ztc_service__api_root=CATALOGI_ROOT,
form_service=None,
)
cls.config = OpenZaakConfig.get_solo()
cls.roots = (CATALOGI_ROOT, ANOTHER_CATALOGI_ROOT)
cls.api_groups_for_root = {
root: ZGWApiGroupConfigFactory(ztc_service__api_root=root)
for root in cls.roots
}

@skip("Being fixed in the next PR")
def test_zgw_import_data_command(self, m):
CatalogMockData().install_mocks(m)
InformationObjectTypeMockData().install_mocks(m)
m.reset_mock()
for root in self.roots:
CatalogMockData(root).install_mocks(m)
InformationObjectTypeMockData(root).install_mocks(m)
# ZaakTypeMockData(root).install_mocks(m)

# TODO: ADD CATALOGI like in iotypes

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

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

stdout = out.getvalue().strip()

expected = inspect.cleandoc(
"""
imported 2 new catalogus configs
aaaaa - 123456789
bbbbb - 123456789
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
imported 4 new catalogus configs
aaaaa - 123456789 [andere-catalogi.nl]
aaaaa - 123456789 [catalogi.nl]
bbbbb - 123456789 [andere-catalogi.nl]
bbbbb - 123456789 [catalogi.nl]
imported 4 new zaaktype configs
AAA - zaaktype-aaa [andere-catalogi.nl]
AAA - zaaktype-aaa [catalogi.nl]
BBB - zaaktype-bbb [andere-catalogi.nl]
BBB - zaaktype-bbb [catalogi.nl]
imported 6 new zaaktype-informatiebjecttype configs
AAA - zaaktype-aaa [andere-catalogi.nl]
info-aaa-1 [andere-catalogi.nl]
info-aaa-2 [andere-catalogi.nl]
AAA - zaaktype-aaa [catalogi.nl]
info-aaa-1 [catalogi.nl]
info-aaa-2 [catalogi.nl]
BBB - zaaktype-bbb [andere-catalogi.nl]
info-bbb [andere-catalogi.nl]
BBB - zaaktype-bbb [catalogi.nl]
info-bbb [catalogi.nl]
imported 4 new zaaktype-statustype configs
AAA - zaaktype-aaa [andere-catalogi.nl]
AAA - status-aaa-1 [andere-catalogi.nl]
AAA - status-aaa-2 [andere-catalogi.nl]
AAA - zaaktype-aaa [catalogi.nl]
AAA - status-aaa-1 [catalogi.nl]
AAA - status-aaa-2 [catalogi.nl]
imported 4 new zaaktype-resultaattype configs
AAA - zaaktype-aaa [andere-catalogi.nl]
AAA - test [andere-catalogi.nl]
AAA - zaaktype-aaa [catalogi.nl]
AAA - test [catalogi.nl]
BBB - zaaktype-bbb [andere-catalogi.nl]
BBB - test [andere-catalogi.nl]
BBB - zaaktype-bbb [catalogi.nl]
BBB - test [catalogi.nl]
"""
).strip()

Expand All @@ -91,12 +112,11 @@ def test_zgw_import_data_command(self, m):
call_command("zgw_import_data", stdout=out)

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

self.assertEqual(CatalogusConfig.objects.count(), 4)
self.assertEqual(ZaakTypeConfig.objects.count(), 4)
self.assertEqual(ZaakTypeInformatieObjectTypeConfig.objects.count(), 6)
self.assertEqual(ZaakTypeStatusTypeConfig.objects.count(), 4)
self.assertEqual(ZaakTypeResultaatTypeConfig.objects.count(), 4)
stdout = out.getvalue().strip()

expected = inspect.cleandoc(
Expand All @@ -114,13 +134,3 @@ def test_zgw_import_data_command(self, m):
).strip()

self.assertEqual(stdout, expected)

def test_zgw_import_data_command_without_catalog(self, m):
m.get(
f"{CATALOGI_ROOT}catalogussen",
status_code=500,
)
InformationObjectTypeMockData().install_mocks(m, with_catalog=False)

with self.assertRaises(RuntimeError):
call_command("zgw_import_data")
Loading

0 comments on commit abc196e

Please sign in to comment.