def test_cannot_use_self_as_hoofdzaak(self): """ Hoofdzaak moet een andere zaak zijn dan de deelzaak zelf. """ zaak = ZaakFactory.create(zaaktype="https://example.com/foo/bar") detail_url = reverse(zaak) response = self.client.patch( detail_url, {"hoofdzaak": detail_url}, **ZAAK_WRITE_KWARGS ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "hoofdzaak") self.assertEqual(error["code"], "self-forbidden")
def test_partial_update_eigenschap_add_relation_to_non_concept_zaaktype_fails( self): zaaktype = ZaakTypeFactory.create(concept=False) zaaktype_url = reverse(zaaktype) eigenschap = EigenschapFactory.create() eigenschap_url = reverse(eigenschap) response = self.client.patch(eigenschap_url, {"zaaktype": zaaktype_url}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], ZaakTypeConceptValidator.code)
def test_validate_verlenging_required_fields_partial_update(self): zaak = ZaakFactory.create(zaaktype="https://example.com/foo/bar") zaak_url = reverse(zaak) response = self.client.patch( zaak_url, {"verlenging": {"wrongfield": "bla"}}, **ZAAK_WRITE_KWARGS ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) for field in ["verlenging.reden", "verlenging.duur"]: with self.subTest(field=field): error = get_validation_errors(response, field) self.assertEqual(error["code"], "required")
def test_update_fail_wrong_id(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create( lock=uuid.uuid4().hex) url = get_operation_url("enkelvoudiginformatieobject_update", uuid=eio.latest_version.uuid) response = self.client.patch(url, {"titel": "changed", "lock": 12345}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "incorrect-lock-id")
def test_create_fail_sync(self, *m): self.mocked_sync_create_zv.side_effect = SyncError("Sync failed") zaak = ZaakFactory.create() url = reverse("zaakverzoek-list") response = self.client.post(url, {"verzoek": VERZOEK, "zaak": reverse(zaak)}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["reason"], "Sync failed") self.assertEqual(ZaakVerzoek.objects.count(), 0)
def test_eigenschap_invalid_url(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) list_url = reverse("zaakeigenschap-list", kwargs={"zaak_uuid": zaak.uuid}) response = self.client.post( list_url, {"zaak": zaak_url, "eigenschap": "bla", "waarde": "test"} ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) validation_error = get_validation_errors(response, "eigenschap") self.assertEqual(validation_error["code"], "bad-url")
def test_validate_unknown_query_params(self): for counter in range(2): eio = EnkelvoudigInformatieObjectFactory.create() eio_url = eio.get_url() self.adapter.get(eio_url, json=serialise_eio(eio, eio_url)) BesluitInformatieObjectFactory.create(informatieobject=eio_url) url = reverse(BesluitInformatieObject) response = self.client.get(url, {"someparam": "somevalue"}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "unknown-parameters")
def test_lock_fail_locked_doc(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create(lock=uuid.uuid4().hex) url = get_operation_url( "enkelvoudiginformatieobject_lock", uuid=eio.latest_version.uuid ) response = self.client.post(url) self.assertEqual( response.status_code, status.HTTP_400_BAD_REQUEST, response.data ) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "existing-lock")
def test_validate_unknown_query_params(self): for i in range(2): eio = EnkelvoudigInformatieObjectFactory.create() eio_url = reverse(eio) GebruiksrechtenCMISFactory(informatieobject=eio_url) url = reverse(Gebruiksrechten) response = self.client.get(url, {"someparam": "somevalue"}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "unknown-parameters")
def test_update_fail_unlocked_doc(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create() assert eio.lock == "" url = get_operation_url("enkelvoudiginformatieobject_update", uuid=eio.latest_version.uuid) response = self.client.patch(url, {"titel": "changed"}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "unlocked")
def test_resultaattype_invalid_resource(self): zaak = ZaakFactory.create() zaak_url = reverse("zaak-detail", kwargs={"uuid": zaak.uuid}) list_url = reverse("resultaat-list") response = self.client.post(list_url, { "zaak": zaak_url, "resultaattype": "https://example.com" }) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) validation_error = get_validation_errors(response, "resultaattype") self.assertEqual(validation_error["code"], "invalid-resource")
def test_selectielijstprocestype_invalid_resource(self): besluittype = BesluitTypeFactory.create(catalogus=self.catalogus) besluittype_url = get_operation_url("besluittype_read", uuid=besluittype.uuid) responses = { "http://referentielijsten.nl/procestypen/1234": { "some": "incorrect property" } } zaaktype_list_url = get_operation_url("zaaktype_list") data = { "identificatie": 0, "doel": "some test", "aanleiding": "some test", "indicatieInternOfExtern": InternExtern.extern, "handelingInitiator": "indienen", "onderwerp": "Klacht", "handelingBehandelaar": "uitvoeren", "doorlooptijd": "P30D", "opschortingEnAanhoudingMogelijk": False, "verlengingMogelijk": True, "verlengingstermijn": "P30D", "publicatieIndicatie": True, "verantwoordingsrelatie": [], "productenOfDiensten": ["https://example.com/product/123"], "vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar, "omschrijving": "some test", "gerelateerdeZaaktypen": [ { "zaaktype": "http://example.com/zaaktype/1", "aard_relatie": AardRelatieChoices.bijdrage, "toelichting": "test relations", } ], "referentieproces": {"naam": "ReferentieProces 0", "link": ""}, "catalogus": f"http://testserver{self.catalogus_detail_url}", "besluittypen": [f"http://testserver{besluittype_url}"], "beginGeldigheid": "2018-01-01", "versiedatum": "2018-01-01", "selectielijstProcestype": "http://referentielijsten.nl/procestypen/1234", } with mock_client(responses): response = self.client.post(zaaktype_list_url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "selectielijstProcestype") self.assertEqual(error["code"], "invalid-resource")
def test_block_setting_indication_true(self): """ Assert that it's not possible to set the indication to true if there are no gebruiksrechten. """ eio = EnkelvoudigInformatieObjectFactory.create() url = reverse("enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid}) response = self.client.patch(url, {"indicatieGebruiksrecht": True}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "indicatieGebruiksrecht") self.assertEqual(error["code"], "missing-gebruiksrechten")
def test_create_external_besluittype_fail_invalid_schema(self): catalogus = "https://externe.catalogus.nl/api/v1/catalogussen/1c8e36be-338c-4c07-ac5e-1adf55bec04a" besluittype = "https://externe.catalogus.nl/api/v1/besluittypen/b71f72ef-198d-44d8-af64-ae1932df830a" url = get_operation_url("besluit_create") with requests_mock.Mocker(real_http=True) as m: m.register_uri( "GET", besluittype, json={ "url": besluittype, "catalogus": catalogus, "zaaktypen": [], "informatieobjecttypen": [], "beginGeldigheid": "2018-01-01", "eindeGeldigheid": None, "concept": False, }, ) m.register_uri( "GET", catalogus, json={ "url": catalogus, "domein": "PUB", "informatieobjecttypen": [], "zaaktypen": [], "besluittypen": [besluittype], }, ) response = self.client.post( url, { "verantwoordelijke_organisatie": "517439943", # RSIN "identificatie": "123123", "besluittype": besluittype, "datum": "2018-09-06", "toelichting": "Vergunning verleend.", "ingangsdatum": "2018-10-01", "vervaldatum": "2018-11-01", "vervalreden": VervalRedenen.tijdelijk, }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "besluittype") self.assertEqual(error["code"], "invalid-resource")
def test_laatste_betaaldatum_betaalindicatie_nvt(self): """ Assert that the field laatsteBetaaldatum may not be set for the NVT indication. """ url = reverse("zaak-list") # all valid values for value in BetalingsIndicatie.values: if value == BetalingsIndicatie.nvt: continue with self.subTest(betalingsindicatie=value): response = self.client.post( url, { "zaaktype": f"http://testserver{self.zaaktype_url}", "vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar, "bronorganisatie": "517439943", "verantwoordelijkeOrganisatie": "517439943", "registratiedatum": "2018-06-11", "startdatum": "2018-06-11", "betalingsindicatie": value, "laatsteBetaaldatum": "2019-01-01T14:03:00Z", }, **ZAAK_WRITE_KWARGS, ) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # invalid value with self.subTest(betalingsindicatie=BetalingsIndicatie.nvt): response = self.client.post( url, { "zaaktype": f"http://testserver{self.zaaktype_url}", "vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar, "bronorganisatie": "517439943", "verantwoordelijkeOrganisatie": "517439943", "registratiedatum": "2018-06-11", "startdatum": "2018-06-11", "betalingsindicatie": BetalingsIndicatie.nvt, "laatsteBetaaldatum": "2019-01-01T14:03:00Z", }, **ZAAK_WRITE_KWARGS, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) validation_error = get_validation_errors(response, "laatsteBetaaldatum") self.assertEqual(validation_error["code"], "betaling-nvt")
def test_add_resultaat_on_zaak_with_afleidingswijze_gerelateerde_zaak_without_relevante_zaken_gives_400( self, ): """ Add RESULTAAT that causes `archiefactiedatum` to be set. """ zaak = ZaakFactory.create() zaak_url = get_operation_url("zaak_read", uuid=zaak.uuid) resultaattype = ResultaatTypeFactory.create( archiefactietermijn="P5Y", archiefnominatie=Archiefnominatie.blijvend_bewaren, brondatum_archiefprocedure_afleidingswijze= BrondatumArchiefprocedureAfleidingswijze.gerelateerde_zaak, brondatum_archiefprocedure_procestermijn=None, zaaktype=zaak.zaaktype, ) resultaattype_url = reverse(resultaattype) resultaat_create_url = get_operation_url("resultaat_create") data = { "zaak": zaak_url, "resultaattype": f"http://testserver{resultaattype_url}", "toelichting": "", } response = self.client.post(resultaat_create_url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) # add final status to the case to close it and to calculate archive parameters status_create_url = get_operation_url("status_create") statustype = StatusTypeFactory.create(zaaktype=zaak.zaaktype) statustype_url = reverse(statustype) data = { "zaak": zaak_url, "statustype": f"http://testserver{statustype_url}", "datumStatusGezet": "2018-10-18T20:00:00Z", } response = self.client.post(status_create_url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "archiefactiedatum-error") zaak.refresh_from_db() self.assertEqual(zaak.archiefactiedatum, None)
def test_cannot_have_multiple_levels(self): """ Deelzaak kan enkel deelzaak zijn van hoofdzaak en niet andere deelzaken. """ url = reverse("zaak-list") hoofdzaak = ZaakFactory.create() deelzaak = ZaakFactory.create(hoofdzaak=hoofdzaak) deelzaak_url = reverse(deelzaak) response = self.client.post(url, {"hoofdzaak": deelzaak_url}, **ZAAK_WRITE_KWARGS) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "hoofdzaak") self.assertEqual(error["code"], "deelzaak-als-hoofdzaak")
def test_validate_opschorting_required_fields_partial_update(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) response = self.client.patch(zaak_url, {"opschorting": { "wrongfield": "bla" }}, **ZAAK_WRITE_KWARGS) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) for field in ["opschorting.indicatie", "opschorting.reden"]: with self.subTest(field=field): error = get_validation_errors(response, field) self.assertEqual(error["code"], "required")
def test_create_external_eigenschap_fail_bad_url(self): zaak = ZaakFactory() zaak_url = reverse(zaak) url = get_operation_url("zaakeigenschap_list", zaak_uuid=zaak.uuid) response = self.client.post( url, {"zaak": zaak_url, "eigenschap": "abcd", "waarde": "overlast_water",}, ) self.assertEqual( response.status_code, status.HTTP_400_BAD_REQUEST, response.data ) error = get_validation_errors(response, "eigenschap") self.assertEqual(error["code"], "bad-url")
def test_create_catalogus_rsin_invalid_length(self): data = { "domein": "TEST", "contactpersoonBeheerTelefoonnummer": "0612345679", "rsin": "0000", "contactpersoonBeheerNaam": "test", "contactpersoonBeheerEmailadres": "*****@*****.**", } response = self.client.post(self.catalogus_list_url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "rsin") self.assertEqual(error["code"], "invalid-length")
def test_partial_update_ziot_not_concept_zaaktype_and_informatieobjecttype_fails( self, ): zaaktype = ZaakTypeFactory.create(concept=False) informatieobjecttype = InformatieObjectTypeFactory.create( catalogus=zaaktype.catalogus, concept=False) ziot = ZaakTypeInformatieObjectTypeFactory.create( zaaktype=zaaktype, informatieobjecttype=informatieobjecttype) ziot_url = reverse(ziot) response = self.client.patch(ziot_url, {"volgnummer": 12}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "non-concept-relation")
def test_cannot_have_multiple_levels(self): """ Deelzaak kan enkel deelzaak zijn van hoofdzaak en niet andere deelzaken. """ url = reverse('zaak-list') hoofdzaak = ZaakFactory.create() deelzaak = ZaakFactory.create(hoofdzaak=hoofdzaak) deelzaak_url = reverse('zaak-detail', kwargs={'uuid': deelzaak.uuid}) response = self.client.post(url, {'hoofdzaak': deelzaak_url}, **ZAAK_WRITE_KWARGS) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, 'hoofdzaak') self.assertEqual(error['code'], 'deelzaak-als-hoofdzaak')
def test_create_zaak_invalide_rsin(self): zaaktype = ZaakTypeFactory.create() zaaktype_url = reverse(zaaktype) url = get_operation_url("zaak_create") data = { "zaaktype": zaaktype_url, "bronorganisatie": "123456789", "registratiedatum": "2018-06-11", } response = self.client.post(url, data, **ZAAK_WRITE_KWARGS) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "bronorganisatie") self.assertEqual(error["code"], "invalid")
def test_kanalen_invalid_documentatie_link_url(self): abonnement_create_url = get_operation_url("kanaal_create") data = { "naam": "testkanaal", "documentatieLink": "https://some-bad-url.com/" } response = self.client.post(abonnement_create_url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, "documentatieLink") self.assertEqual(error["code"], "bad-url")
def test_informatieobject_invalid(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) url = reverse(ZaakInformatieObject) response = self.client.post( url, {"zaak": zaak_url, "informatieobject": "https://drc.nl/api/v1"} ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) validation_error = get_validation_errors(response, "informatieobject") self.assertEqual(validation_error["code"], "bad-url") self.assertEqual(validation_error["name"], "informatieobject")
def test_delete_informatieobjecttype_related_to_non_concept_besluittype_fails( self): informatieobjecttype = InformatieObjectTypeFactory.create() BesluitTypeFactory.create(informatieobjecttypen=[informatieobjecttype], concept=False) informatieobjecttype_url = reverse(informatieobjecttype) response = self.client.delete(informatieobjecttype_url) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "non-concept-relation")
def test_validate_verlenging_required_fields_partial_update(self): zaak = ZaakFactory.create(zaaktype='https://example.com/foo/bar') zaak_url = reverse(zaak) response = self.client.patch(zaak_url, {'verlenging': { 'wrongfield': 'bla' }}, **ZAAK_WRITE_KWARGS) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) for field in ['verlenging.reden', 'verlenging.duur']: with self.subTest(field=field): error = get_validation_errors(response, field) self.assertEqual(error['code'], 'required')
def test_create_external_resultaattype_fail_not_json_url(self): zaak = ZaakFactory() zaak_url = reverse(zaak) response = self.client.post( self.list_url, { "zaak": f"http://testserver{zaak_url}", "resultaattype": "http://example.com", "toelichting": "some desc", }, ) error = get_validation_errors(response, "resultaattype") self.assertEqual(error["code"], "invalid-resource")
def test_unlock_fail_incorrect_id(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create( latest_version__informatieobjecttype=INFORMATIEOBJECTTYPE, lock=uuid.uuid4().hex, ) url = get_operation_url("enkelvoudiginformatieobject_unlock", uuid=eio.latest_version.uuid) response = self.client.post(url) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "incorrect-lock-id")
def test_update_fail_wrong_id(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create(lock=uuid.uuid4().hex) url = get_operation_url('enkelvoudiginformatieobject_update', uuid=eio.latest_version.uuid) response = self.client.patch( url, {'titel': 'changed', 'lock': 12345} ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, 'nonFieldErrors') self.assertEqual(error['code'], 'incorrect-lock-id')