def test_partial_update_zaak_and_informatieobject_fails(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) eio1 = EnkelvoudigInformatieObjectFactory.create() eio1_url = eio1.get_url() self.adapter.get(eio1_url, json=serialise_eio(eio1, eio1_url)) zio = ZaakInformatieObjectFactory.create(informatieobject=eio1_url) zio_detail_url = reverse(zio) eio2 = EnkelvoudigInformatieObjectFactory.create() eio2_url = f"http://testserver{reverse(eio2)}" self.adapter.get(eio2_url, json=serialise_eio(eio2, eio2_url)) response = self.client.patch( zio_detail_url, { "zaak": f"http://testserver{zaak_url}", "informatieobject": eio2_url, }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) for field in ["zaak", "informatieobject"]: with self.subTest(field=field): error = get_validation_errors(response, field) self.assertEqual(error["code"], IsImmutableValidator.code)
def test_registratiedatum_ignored(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False) io_url = f"http://testserver{reverse(io)}" self.adapter.get(io_url, json=serialise_eio(io, io_url)) ZaakTypeInformatieObjectTypeFactory.create( informatieobjecttype=io.informatieobjecttype, zaaktype=zaak.zaaktype) content = { "informatieobject": io_url, "zaak": f"http://testserver{zaak_url}", "registratiedatum": "2018-09-19T12:25:20+0200", } # Send to the API self.client.post(self.list_url, content) oio = ZaakInformatieObject.objects.get() self.assertEqual( oio.registratiedatum, datetime(2018, 9, 20, 12, 0, 0).replace(tzinfo=timezone.utc), )
def test_partial_update_zio_metadata(self): zaak = ZaakFactory.create() io = EnkelvoudigInformatieObjectFactory.create() io_url = io.get_url() self.adapter.get(io_url, json=serialise_eio(io, io_url)) ZaakTypeInformatieObjectTypeFactory.create( zaaktype=zaak.zaaktype, informatieobjecttype=io.informatieobjecttype) zio = ZaakInformatieObjectFactory.create(zaak=zaak, informatieobject=io_url) zio_detail_url = reverse(zio) response = self.client.patch(zio_detail_url, { "titel": "updated title", "beschrijving": "same" }) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) self.assertEqual(response.data["titel"], "updated title") self.assertEqual(response.data["beschrijving"], "same") zio.refresh_from_db() self.assertEqual(zio.titel, "updated title") self.assertEqual(zio.beschrijving, "same")
def test_duplicate_object(self): """ Test the (informatieobject, object) unique together validation. """ eio = EnkelvoudigInformatieObjectFactory.create() eio_url = f"http://testserver{reverse(eio)}" self.adapter.get(eio_url, json=serialise_eio(eio, eio_url)) zio_type = ZaakTypeInformatieObjectTypeFactory.create( informatieobjecttype__concept=False, zaaktype__concept=False) zio = ZaakInformatieObjectFactory.create( informatieobject=eio_url, zaak__zaaktype=zio_type.zaaktype, informatieobject__latest_version__informatieobjecttype=zio_type. informatieobjecttype, ) zaak_url = reverse(zio.zaak) content = { "informatieobject": eio_url, "zaak": f"http://testserver{zaak_url}", } # Send to the API response = self.client.post(self.list_url, content) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "unique")
def test_read_zaak(self): eio = EnkelvoudigInformatieObjectFactory.create() eio_url = f"http://testserver{reverse(eio)}" self.adapter.get(eio_url, json=serialise_eio(eio, eio_url)) zio = ZaakInformatieObjectFactory.create(informatieobject=eio_url) zio_detail_url = reverse(zio) response = self.client.get(zio_detail_url) # Test response self.assertEqual(response.status_code, status.HTTP_200_OK) zaak_url = reverse(zio.zaak) expected = { "url": f"http://testserver{zio_detail_url}", "uuid": str(zio.uuid), "informatieobject": eio_url, "zaak": f"http://testserver{zaak_url}", "aardRelatieWeergave": RelatieAarden.labels[RelatieAarden.hoort_bij], "titel": "", "beschrijving": "", "registratiedatum": "2018-09-20T12:00:00Z", } self.assertEqual(response.json(), expected)
def test_status_with_informatieobject_indicatie_gebruiksrecht_null(self): zaak = ZaakFactory.create(zaaktype=self.zaaktype) zaak_url = reverse(zaak) io = EnkelvoudigInformatieObjectFactory.create( indicatie_gebruiksrecht=None) io_url = io.get_url() self.adapter.get(io_url, json=serialise_eio(io, io_url)) ZaakInformatieObjectFactory.create(zaak=zaak, informatieobject=io_url) resultaattype = ResultaatTypeFactory.create( archiefactietermijn="P10Y", archiefnominatie=Archiefnominatie.blijvend_bewaren, brondatum_archiefprocedure_afleidingswijze= BrondatumArchiefprocedureAfleidingswijze.afgehandeld, zaaktype=self.zaaktype, ) ResultaatFactory.create(zaak=zaak, resultaattype=resultaattype) list_url = reverse("status-list") response = self.client.post( list_url, { "zaak": zaak_url, "statustype": f"http://testserver{self.statustype_end_url}", "datumStatusGezet": isodatetime(2019, 7, 22, 13, 00, 00), }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) validation_error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(validation_error["code"], "indicatiegebruiksrecht-unset")
def test_create(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False) io_url = f"http://testserver{reverse(io)}" self.adapter.get(io_url, json=serialise_eio(io, io_url)) ZaakTypeInformatieObjectTypeFactory.create( informatieobjecttype=io.informatieobjecttype, zaaktype=zaak.zaaktype) titel = "some titel" beschrijving = "some beschrijving" content = { "informatieobject": io_url, "zaak": f"http://testserver{zaak_url}", "titel": titel, "beschrijving": beschrijving, "aardRelatieWeergave": "bla", # Should be ignored by the API } # Send to the API response = self.client.post(self.list_url, content) # Test response self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) # Test database self.assertEqual(ZaakInformatieObject.objects.count(), 1) stored_object = ZaakInformatieObject.objects.get() self.assertEqual(stored_object.zaak, zaak) self.assertEqual(stored_object.aard_relatie, RelatieAarden.hoort_bij) expected_url = reverse(stored_object) expected_response = content.copy() expected_response.update({ "url": f"http://testserver{expected_url}", "uuid": str(stored_object.uuid), "titel": titel, "beschrijving": beschrijving, "registratiedatum": "2018-09-19T10:25:19Z", "aardRelatieWeergave": RelatieAarden.labels[RelatieAarden.hoort_bij], }) self.assertEqual(response.json(), expected_response)
def test_zaakinformatieobject(self): eio = EnkelvoudigInformatieObjectFactory.create(identificatie="12345") eio_url = eio.get_url() self.adapter.get(eio_url, json=serialise_eio(eio, eio_url)) zio = ZaakInformatieObjectFactory( zaak__bronorganisatie=730924658, zaak__identificatie="5d940d52-ff5e-4b18-a769-977af9130c04", informatieobject=eio_url, ) self.assertEqual( zio.unique_representation(), "(730924658 - 5d940d52-ff5e-4b18-a769-977af9130c04) - 12345", )
def test_can_set_archiefstatus_when_all_documents_are_gearchiveerd(self): zaak = ZaakFactory.create( archiefnominatie=Archiefnominatie.vernietigen, archiefactiedatum=date.today(), ) io = EnkelvoudigInformatieObjectFactory.create(status="gearchiveerd") io_url = f"http://testserver{reverse(io)}" self.adapter.get(io_url, json=serialise_eio(io, io_url)) ZaakInformatieObjectFactory.create(zaak=zaak, informatieobject=io_url) zaak_patch_url = get_operation_url("zaak_partial_update", uuid=zaak.uuid) data = {"archiefstatus": Archiefstatus.gearchiveerd} response = self.client.patch(zaak_patch_url, data, **ZAAK_WRITE_KWARGS) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
def test_delete(self): eio = EnkelvoudigInformatieObjectFactory.create() eio_url = eio.get_url() self.adapter.get(eio_url, json=serialise_eio(eio, eio_url)) zio = ZaakInformatieObjectFactory.create(informatieobject=eio_url) zio_url = reverse(zio) response = self.client.delete(zio_url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, response.data) # Relation is gone, zaak still exists. self.assertFalse(ZaakInformatieObject.objects.exists()) self.assertTrue(Zaak.objects.exists())
def test_validate_zaakinformatieobject_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)) ZaakInformatieObjectFactory.create(informatieobject=eio_url) url = reverse(ZaakInformatieObject) 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_filter_by_informatieobject(self): eio = EnkelvoudigInformatieObjectFactory.create() eio_url = f"http://openzaak.nl{reverse(eio)}" self.adapter.get(eio_url, json=serialise_eio(eio, eio_url)) ZaakInformatieObjectFactory.create(informatieobject=eio_url) zio_list_url = reverse("zaakinformatieobject-list") response = self.client.get( zio_list_url, {"informatieobject": eio_url}, HTTP_HOST="openzaak.nl", ) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]["informatieobject"], eio_url)
def test_update_informatieobject_fails(self): io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False) io_url = f"http://testserver{reverse(io)}" self.adapter.get(io_url, json=serialise_eio(io, io_url)) zio = ZaakInformatieObjectFactory.create( informatieobject=io_url, informatieobject__informatieobjecttype=io.informatieobjecttype, ) zio_url = reverse(zio) response = self.client.patch(zio_url, {"informatieobject": io_url}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) validation_error = get_validation_errors(response, "informatieobject") self.assertEqual(validation_error["code"], IsImmutableValidator.code)
def test_informatieobject_create(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False) io_url = f"http://testserver{reverse(io)}" self.adapter.get(io_url, json=serialise_eio(io, io_url)) ZaakTypeInformatieObjectTypeFactory.create( informatieobjecttype=io.informatieobjecttype, zaaktype=zaak.zaaktype) url = reverse(ZaakInformatieObject) response = self.client.post( url, { "zaak": f"http://testserver{zaak_url}", "informatieobject": io_url, }, ) self.assertEqual(response.status_code, status.HTTP_201_CREATED)