Skip to content

Commit

Permalink
💚 [#4057] Update tests after model/validation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Mar 26, 2024
1 parent a0d3757 commit bc38084
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 126 deletions.
63 changes: 0 additions & 63 deletions src/openforms/registrations/contrib/zgw_apis/tests/test_admin.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ def test_zgw_backend_default_author(self, m):
zgw_form_options = dict(
zgw_api_group=self.zgw_group,
zaaktype="https://catalogi.nl/api/v1/zaaktypen/1",
informatieobjecttype="https://catalogi.nl/api/v1/informatieobjecttypen/1",
)
self.install_mocks(m)

Expand Down Expand Up @@ -1409,7 +1410,11 @@ def test_zgw_backend_has_reference_after_pre_submission(self, m):
)
submission = SubmissionFactory.create(
form__registration_backend="zgw-create-zaak",
form__registration_backend_options={"zgw_api_group": self.zgw_group.pk},
form__registration_backend_options={
"zgw_api_group": self.zgw_group.pk,
"zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1",
"informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1",
},
completed_not_preregistered=True,
)
assert submission.public_registration_reference == ""
Expand Down
26 changes: 7 additions & 19 deletions src/openforms/registrations/contrib/zgw_apis/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,27 @@
from .factories import ZGWApiGroupConfigFactory


class ZGWBackendTests(TestCase):
def setUp(self):
self.config = ZGWApiGroupConfigFactory.create(
class ZGWApiGroupModelTests(TestCase):
@classmethod
def setUpTestData(cls):
config = ZGWApiGroupConfigFactory.create(
zrc_service__api_root="https://zaken.nl/api/v1/",
drc_service__api_root="https://documenten.nl/api/v1/",
ztc_service__api_root="https://catalogus.nl/api/v1/",
)
self.config.full_clean()
config.full_clean()
cls.config = config

def test_model_validate(self):
self.config.zaaktype = "https://catalogus.nl/api/v1/zaaktype/1"
self.config.informatieobjecttype = "https://catalogus.nl/api/v1/info/1"
self.config.rsin = "619183020"
self.config.full_clean()

def test_model_invalid_zaaktype(self):
with self.assertRaises(ValidationError):
self.config.zaaktype = "https://BAD_DOMAIN.nl/api/v1/zaak/1"
self.config.full_clean()

def test_model_invalid_informatieobjecttype(self):
with self.assertRaises(ValidationError):
self.config.informatieobjecttype = "https://BAD_DOMAIN.nl/api/v1/info/1"
self.config.full_clean()

def test_model_invalid_rsin(self):
with self.assertRaises(ValidationError):
self.config.organisatie_rsin = "063-08836"
self.config.full_clean()

def test_model_string(self):
api_group = ZGWApiGroupConfigFactory.create(
name="ZGW API test",
)
api_group = ZGWApiGroupConfigFactory.create(name="ZGW API test")

self.assertEqual(str(api_group), "ZGW API test")
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_valid_omschrijving(self, m):
data = {
"zgw_api_group": self.zgw_group.pk,
"zaaktype": "https://catalogus.nl/api/v1/zaaktypen/111",
"informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1",
"medewerker_roltype": "Some description",
}

Expand All @@ -69,6 +70,7 @@ def test_invalid_omschrijving(self, m):
data = {
"zgw_api_group": self.zgw_group.pk,
"zaaktype": "https://catalogus.nl/api/v1/zaaktypen/111",
"informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1",
"medewerker_roltype": "Some description",
}

Expand All @@ -88,7 +90,12 @@ def test_invalid_omschrijving(self, m):
class ZGWAPIGroupConfigTest(TestCase):
def test_no_zgw_api_group_and_no_default(self):
# No zgw_api_group provided
serializer = ZaakOptionsSerializer(data={})
serializer = ZaakOptionsSerializer(
data={
"zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1",
"informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1",
}
)

# No ZgwConfig.default_zgw_api_group configured
with patch(
Expand All @@ -111,8 +118,6 @@ def test_existing_provided_variable_in_specific_zaaktype(self, m):
drc_service__api_root="https://documenten.nl/api/v1/",
ztc_service__api_root="https://catalogus.nl/api/v1/",
)
zgw_group.zaaktype = "https://zaken.nl/api/v1/zaaktypen/1"
zgw_group.save()
m.get(
"https://catalogus.nl/api/v1/eigenschappen?zaaktype=https%3A%2F%2Fzaken.nl%2Fapi%2Fv1%2Fzaaktypen%2F1",
status_code=200,
Expand Down Expand Up @@ -143,6 +148,8 @@ def test_existing_provided_variable_in_specific_zaaktype(self, m):

data = {
"zgw_api_group": zgw_group.pk,
"zaaktype": "https://zaken.nl/api/v1/zaaktypen/1",
"informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1",
"property_mappings": [
{"component_key": "textField", "eigenschap": "a property name"}
],
Expand All @@ -160,8 +167,6 @@ def test_provided_variable_does_not_exist_in_specific_zaaktype(self, m):
drc_service__api_root="https://documenten.nl/api/v1/",
ztc_service__api_root="https://catalogus.nl/api/v1/",
)
zgw_group.zaaktype = "https://zaken.nl/api/v1/zaaktypen/1"
zgw_group.save()
m.get(
"https://catalogus.nl/api/v1/eigenschappen?zaaktype=https%3A%2F%2Fzaken.nl%2Fapi%2Fv1%2Fzaaktypen%2F1",
status_code=200,
Expand Down Expand Up @@ -192,6 +197,8 @@ def test_provided_variable_does_not_exist_in_specific_zaaktype(self, m):

data = {
"zgw_api_group": zgw_group.pk,
"zaaktype": "https://zaken.nl/api/v1/zaaktypen/1",
"informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1",
"property_mappings": [
{"component_key": "textField", "eigenschap": "wrong variable"}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ def setUpTestData(cls):
cls.zgw_group1 = ZGWApiGroupConfigFactory.create(
zrc_service__api_root="https://zaken-1.nl/api/v1/",
drc_service__api_root="https://documenten-1.nl/api/v1/",
ztc_service__api_root="https://catalogus-1.nl/api/v1/",
zaaktype="https://catalogi-1.nl/api/v1/zaaktypen/1",
informatieobjecttype="https://catalogi-1.nl/api/v1/informatieobjecttypen/1",
ztc_service__api_root="https://catalogi-1.nl/api/v1/",
# zaaktype="https://catalogi-1.nl/api/v1/zaaktypen/1",
# informatieobjecttype="https://catalogi-1.nl/api/v1/informatieobjecttypen/1",
organisatie_rsin="000000000",
zaak_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.openbaar,
)
cls.zgw_group2 = ZGWApiGroupConfigFactory.create(
zrc_service__api_root="https://zaken-2.nl/api/v1/",
drc_service__api_root="https://documenten-2.nl/api/v1/",
ztc_service__api_root="https://catalogus-2.nl/api/v1/",
zaaktype="https://catalogi-2.nl/api/v1/zaaktypen/1",
informatieobjecttype="https://catalogi-2.nl/api/v1/informatieobjecttypen/1",
ztc_service__api_root="https://catalogi-2.nl/api/v1/",
# zaaktype="https://catalogi-2.nl/api/v1/zaaktypen/1",
# informatieobjecttype="https://catalogi-2.nl/api/v1/informatieobjecttypen/1",
organisatie_rsin="000000001",
zaak_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.beperkt_openbaar,
)
Expand Down Expand Up @@ -108,7 +108,7 @@ def install_mocks(self, m):
)

m.get(
"https://catalogus-1.nl/api/v1/roltypen?zaaktype=https%3A%2F%2Fcatalogi-1.nl%2Fapi%2Fv1%2Fzaaktypen%2F1&omschrijvingGeneriek=initiator",
"https://catalogi-1.nl/api/v1/roltypen?zaaktype=https%3A%2F%2Fcatalogi-1.nl%2Fapi%2Fv1%2Fzaaktypen%2F1&omschrijvingGeneriek=initiator",
status_code=200,
json={
"count": 1,
Expand All @@ -118,7 +118,7 @@ def install_mocks(self, m):
generate_oas_component(
"catalogi",
"schemas/RolType",
url="https://catalogus-1.nl/api/v1/roltypen/1",
url="https://catalogi-1.nl/api/v1/roltypen/1",
)
],
},
Expand All @@ -131,7 +131,7 @@ def install_mocks(self, m):
),
)
m.get(
"https://catalogus-1.nl/api/v1/statustypen?zaaktype=https%3A%2F%2Fcatalogi-1.nl%2Fapi%2Fv1%2Fzaaktypen%2F1",
"https://catalogi-1.nl/api/v1/statustypen?zaaktype=https%3A%2F%2Fcatalogi-1.nl%2Fapi%2Fv1%2Fzaaktypen%2F1",
status_code=200,
json={
"count": 2,
Expand All @@ -141,19 +141,19 @@ def install_mocks(self, m):
generate_oas_component(
"catalogi",
"schemas/StatusType",
url="https://catalogus-1.nl/api/v1/statustypen/2",
url="https://catalogi-1.nl/api/v1/statustypen/2",
volgnummer=2,
),
generate_oas_component(
"catalogi",
"schemas/StatusType",
url="https://catalogus-1.nl/api/v1/statustypen/1",
url="https://catalogi-1.nl/api/v1/statustypen/1",
volgnummer=1,
),
],
},
)
m.get("https://catalogus-1.nl/api/v1/zaaktypen", status_code=200, json=[])
m.get("https://catalogi-1.nl/api/v1/zaaktypen", status_code=200, json=[])
m.post(
"https://zaken-1.nl/api/v1/statussen",
status_code=201,
Expand Down Expand Up @@ -225,7 +225,7 @@ def install_mocks(self, m):
)

m.get(
"https://catalogus-2.nl/api/v1/roltypen?zaaktype=https%3A%2F%2Fcatalogi-2.nl%2Fapi%2Fv1%2Fzaaktypen%2F1&omschrijvingGeneriek=initiator",
"https://catalogi-2.nl/api/v1/roltypen?zaaktype=https%3A%2F%2Fcatalogi-2.nl%2Fapi%2Fv1%2Fzaaktypen%2F1&omschrijvingGeneriek=initiator",
status_code=200,
json={
"count": 1,
Expand All @@ -235,13 +235,13 @@ def install_mocks(self, m):
generate_oas_component(
"catalogi",
"schemas/RolType",
url="https://catalogus-2.nl/api/v1/roltypen/1",
url="https://catalogi-2.nl/api/v1/roltypen/1",
)
],
},
)
m.get(
"https://catalogus-2.nl/api/v1/roltypen?zaaktype=https%3A%2F%2Fcatalogi-2.nl%2Fapi%2Fv1%2Fzaaktypen%2F2&omschrijvingGeneriek=initiator",
"https://catalogi-2.nl/api/v1/roltypen?zaaktype=https%3A%2F%2Fcatalogi-2.nl%2Fapi%2Fv1%2Fzaaktypen%2F2&omschrijvingGeneriek=initiator",
status_code=200,
json={
"count": 1,
Expand All @@ -251,12 +251,12 @@ def install_mocks(self, m):
generate_oas_component(
"catalogi",
"schemas/RolType",
url="https://catalogus-2.nl/api/v1/roltypen/2",
url="https://catalogi-2.nl/api/v1/roltypen/2",
)
],
},
)
m.get("https://catalogus-2.nl/api/v1/zaaktypen", status_code=200, json=[])
m.get("https://catalogi-2.nl/api/v1/zaaktypen", status_code=200, json=[])
m.post(
"https://zaken-2.nl/api/v1/rollen",
status_code=201,
Expand All @@ -265,7 +265,7 @@ def install_mocks(self, m):
),
)
m.get(
"https://catalogus-2.nl/api/v1/statustypen?zaaktype=https%3A%2F%2Fcatalogi-2.nl%2Fapi%2Fv1%2Fzaaktypen%2F1",
"https://catalogi-2.nl/api/v1/statustypen?zaaktype=https%3A%2F%2Fcatalogi-2.nl%2Fapi%2Fv1%2Fzaaktypen%2F1",
status_code=200,
json={
"count": 2,
Expand All @@ -275,13 +275,13 @@ def install_mocks(self, m):
generate_oas_component(
"catalogi",
"schemas/StatusType",
url="https://catalogus-2.nl/api/v1/statustypen/2",
url="https://catalogi-2.nl/api/v1/statustypen/2",
volgnummer=2,
),
generate_oas_component(
"catalogi",
"schemas/StatusType",
url="https://catalogus-2.nl/api/v1/statustypen/1",
url="https://catalogi-2.nl/api/v1/statustypen/1",
volgnummer=1,
),
],
Expand Down Expand Up @@ -309,7 +309,11 @@ def test_the_right_api_is_used(self, m):
form_key="field1",
_component_configuration_path="components.0",
)
zgw_form_options = {"zgw_api_group": self.zgw_group2}
zgw_form_options = {
"zgw_api_group": self.zgw_group2,
"zaaktype": "https://catalogi-2.nl/api/v1/zaaktypen/1",
"informatieobjecttype": "https://catalogi-2.nl/api/v1/informatieobjecttypen/1",
}
self.install_mocks(m)

plugin = ZGWRegistration("zgw")
Expand Down Expand Up @@ -340,8 +344,8 @@ def test_per_form_overwrites(self, m):
)
zgw_form_options = dict(
zgw_api_group=self.zgw_group2, # Configure to use the second ZGW API
zaaktype="https://catalogi-2.nl/api/v1/zaaktypen/2", # Use zaaktype 2 instead of 1
informatieobjecttype="https://catalogi-2.nl/api/v1/informatieobjecttypen/2", # Use iot 2 instead of 1
zaaktype="https://catalogi-2.nl/api/v1/zaaktypen/2",
informatieobjecttype="https://catalogi-2.nl/api/v1/informatieobjecttypen/2",
organisatie_rsin="000000123",
zaak_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.confidentieel,
doc_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.geheim,
Expand Down Expand Up @@ -496,11 +500,11 @@ def test_check_config(self, m):

self.assertEqual(list_zaken_1.hostname, "zaken-1.nl")
self.assertEqual(list_documenten_1.hostname, "documenten-1.nl")
self.assertEqual(list_zaaktypen_1.hostname, "catalogus-1.nl")
self.assertEqual(list_zaaktypen_1.hostname, "catalogi-1.nl")

self.assertEqual(list_zaken_2.hostname, "zaken-2.nl")
self.assertEqual(list_documenten_2.hostname, "documenten-2.nl")
self.assertEqual(list_zaaktypen_2.hostname, "catalogus-2.nl")
self.assertEqual(list_zaaktypen_2.hostname, "catalogi-2.nl")

def test_check_config_no_zrc_service(self, m):
self.install_mocks(m)
Expand Down
Loading

0 comments on commit bc38084

Please sign in to comment.