def test_create_gebruiksrechten_limited_to_authorized_io(self): url = reverse("gebruiksrechten-list") eio1 = EnkelvoudigInformatieObjectFactory.create( vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar ) eio2 = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype=self.informatieobjecttype, vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.zeer_geheim, ) for eio in [eio1, eio2]: with self.subTest( informatieobjecttype=eio.informatieobjecttype, vertrouwelijkheidaanduiding=eio.vertrouwelijkheidaanduiding, ): response = self.client.post( url, { "informatieobject": reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid}, ), "startdatum": "2018-12-24T00:00:00Z", "omschrijvingVoorwaarden": "Een hele set onredelijke voorwaarden", }, ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_eio_list_shows_latest_versions(self): eio1 = EnkelvoudigInformatieObjectFactory.create(beschrijving="object1") eio1_url = reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": eio1.uuid} ) lock = self.client.post(f"{eio1_url}/lock").data["lock"] self.client.patch(eio1_url, {"beschrijving": "object1 versie2", "lock": lock}) eio2 = EnkelvoudigInformatieObjectFactory.create(beschrijving="object2") eio2_url = reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": eio2.uuid} ) lock = self.client.post(f"{eio2_url}/lock").data["lock"] self.client.patch(eio2_url, {"beschrijving": "object2 versie2", "lock": lock}) response = self.client.get(reverse(EnkelvoudigInformatieObject)) self.assertEqual(response.status_code, status.HTTP_200_OK) response_data = response.data["results"] self.assertEqual(len(response_data), 2) self.assertEqual(response_data[0]["beschrijving"], "object1 versie2") self.assertEqual(response_data[1]["beschrijving"], "object2 versie2")
def test_filter_by_identification(self): EnkelvoudigInformatieObjectFactory.create(identificatie="foo") EnkelvoudigInformatieObjectFactory.create(identificatie="bar") response = self.client.get(self.list_url, {"identificatie": "foo"}) self.assertEqual(response.status_code, status.HTTP_200_OK) response_data = response.json()["results"] self.assertEqual(len(response_data), 1) self.assertEqual(response_data[0]["identificatie"], "foo")
def test_read_superuser(self): """ superuser read everything """ self.applicatie.heeft_alle_autorisaties = True self.applicatie.save() EnkelvoudigInformatieObjectFactory.create( informatieobjecttype=self.informatieobjecttype, vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar, ) EnkelvoudigInformatieObjectFactory.create( vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar ) EnkelvoudigInformatieObjectFactory.create( informatieobjecttype=self.informatieobjecttype, vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.zeer_geheim, ) EnkelvoudigInformatieObjectFactory.create( vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.zeer_geheim ) url = reverse("enkelvoudiginformatieobject-list") response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) response_data = response.json() self.assertEqual(len(response_data), 4)
def test_eio_partial_update(self): eio = EnkelvoudigInformatieObjectFactory.create(beschrijving="beschrijving1") eio_url = reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid} ) lock = self.client.post(f"{eio_url}/lock").data["lock"] response = self.client.patch( eio_url, {"beschrijving": "beschrijving2", "lock": lock} ) self.assertEqual(response.status_code, status.HTTP_200_OK) response_data = response.json() self.assertEqual(response_data["beschrijving"], "beschrijving2") eios = EnkelvoudigInformatieObject.objects.filter(uuid=eio.uuid).order_by( "-versie" ) self.assertEqual(len(eios), 2) latest_version = eios.first() self.assertEqual(latest_version.versie, 2) self.assertEqual(latest_version.beschrijving, "beschrijving2") first_version = eios[1] self.assertEqual(first_version.versie, 1) self.assertEqual(first_version.beschrijving, "beschrijving1")
def test_registratiedatum_ignored(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False ) io_url = reverse(io) ZaakInformatieobjectTypeFactory.create( informatieobjecttype=io.informatieobjecttype, zaaktype=zaak.zaaktype ) content = { "informatieobject": f"http://testserver{io_url}", "zaak": f"http://testserver{zaak_url}", "registratiedatum": "2018-09-19T12:25:20+0200", } # Send to the API response = 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_create_zaakinformatieobject_audittrail(self): zaak_data = self._create_zaak() zaak = Zaak.objects.get() io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False ) io_url = reverse(io) ZaakInformatieobjectTypeFactory.create( informatieobjecttype=io.informatieobjecttype, zaaktype=zaak.zaaktype ) url = reverse(ZaakInformatieObject) response = self.client.post( url, {"zaak": zaak_data["url"], "informatieobject": io_url} ) zaakinformatieobject_response = response.data audittrails = AuditTrail.objects.filter(hoofd_object=zaak_data["url"]).order_by( "pk" ) self.assertEqual(audittrails.count(), 2) # Verify that the audittrail for the ZaakInformatieObject creation # contains the correct information zio_create_audittrail = audittrails[1] self.assertEqual(zio_create_audittrail.bron, "ZRC") self.assertEqual(zio_create_audittrail.actie, "create") self.assertEqual(zio_create_audittrail.resultaat, 201) self.assertEqual(zio_create_audittrail.oud, None) self.assertEqual(zio_create_audittrail.nieuw, zaakinformatieobject_response)
def test_create_besluitinformatieobject_audittrail(self): besluit_data = self._create_besluit() besluit = Besluit.objects.get() io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False ) io_url = reverse(io) besluit.besluittype.informatieobjecttypes.add(io.informatieobjecttype) url = reverse(BesluitInformatieObject) response = self.client.post( url, { "besluit": besluit_data["url"], "informatieobject": f"http://testserver{io_url}", }, ) besluitinformatieobject_response = response.data audittrails = AuditTrail.objects.filter(hoofd_object=besluit_data["url"]) self.assertEqual(audittrails.count(), 2) # Verify that the audittrail for the BesluitInformatieObject creation # contains the correct information bio_create_audittrail = audittrails[1] self.assertEqual(bio_create_audittrail.bron, "BRC") self.assertEqual(bio_create_audittrail.actie, "create") self.assertEqual(bio_create_audittrail.resultaat, 201) self.assertEqual(bio_create_audittrail.oud, None) self.assertEqual(bio_create_audittrail.nieuw, besluitinformatieobject_response)
def test_create(self): besluit = BesluitFactory.create() io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False) besluit.besluittype.informatieobjecttypes.add(io.informatieobjecttype) besluit_url = reverse(besluit) io_url = reverse(io) content = { "informatieobject": f"http://testserver{io_url}", "besluit": f"http://testserver{besluit_url}", } # 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(BesluitInformatieObject.objects.count(), 1) stored_object = BesluitInformatieObject.objects.get() self.assertEqual(stored_object.besluit, besluit) expected_url = reverse(stored_object) expected_response = content.copy() expected_response.update({"url": f"http://testserver{expected_url}"}) self.assertEqual(response.json(), expected_response)
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) ZaakInformatieObjectFactory.create(zaak=zaak, informatieobject=io.canonical) 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": 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_with_objecttype_zaak(self): zaak = ZaakFactory.create() eio = EnkelvoudigInformatieObjectFactory.create() # relate the two zio = ZaakInformatieObjectFactory.create( zaak=zaak, informatieobject=eio.canonical ) zaak_url = reverse(zaak) eio_url = reverse(eio) # re-use the ZIO UUID for OIO zio_url = reverse("objectinformatieobject-detail", kwargs={"uuid": zio.uuid}) response = self.client.post( self.list_url, { "object": f"http://testserver.nl{zaak_url}", "informatieobject": f"http://testserver.nl{eio_url}", "objectType": "zaak", }, HTTP_HOST="testserver.nl", ) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) self.assertEqual( response.data, { "url": f"http://testserver.nl{zio_url}", "informatieobject": f"http://testserver.nl{eio_url}", "object": f"http://testserver.nl{zaak_url}", "object_type": "zaak", }, )
def test_create_with_objecttype_besluit(self): besluit = BesluitFactory.create() eio = EnkelvoudigInformatieObjectFactory.create() # relate the two bio = BesluitInformatieObjectFactory.create( besluit=besluit, informatieobject=eio.canonical ) besluit_url = reverse(besluit) eio_url = reverse(eio) # re-use the ZIO UUID for OIO bio_url = reverse("objectinformatieobject-detail", kwargs={"uuid": bio.uuid}) response = self.client.post( self.list_url, { "object": f"http://testserver.nl{besluit_url}", "informatieobject": f"http://testserver{eio_url}", "objectType": "besluit", }, HTTP_HOST="testserver.nl", ) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual( response.data, { "url": f"http://testserver.nl{bio_url}", "object": f"http://testserver.nl{besluit_url}", "informatieobject": f"http://testserver.nl{eio_url}", "object_type": "besluit", }, )
def test_read_detail_file(self): eio = EnkelvoudigInformatieObjectFactory.create() file_url = get_operation_url("enkelvoudiginformatieobject_download", uuid=eio.uuid) response = self.client.get(file_url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.content.decode("utf-8"), "some data")
def test_destroy_no_relations_allowed(self): """ Assert that destroying is possible when there are no relations. """ eio = EnkelvoudigInformatieObjectFactory.create() url = reverse(eio) response = self.client.delete(url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
def test_besluitinformatieobject(self): io = EnkelvoudigInformatieObjectFactory.create(identificatie="12345") bio = BesluitInformatieObjectFactory( besluit__identificatie="5d940d52-ff5e-4b18-a769-977af9130c04", informatieobject=io.canonical, ) self.assertEqual( bio.unique_representation(), "(5d940d52-ff5e-4b18-a769-977af9130c04) - 12345", )
def test_io_retrieve(self): """ Assert you can only read INFORMATIEOBJECTen of the informatieobjecttype and vertrouwelijkheidaanduiding of your authorization """ eio1 = EnkelvoudigInformatieObjectFactory.create( vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar ) eio2 = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype=self.informatieobjecttype, vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.zeer_geheim, ) url1 = reverse("enkelvoudiginformatieobject-detail", kwargs={"uuid": eio1.uuid}) url2 = reverse("enkelvoudiginformatieobject-detail", kwargs={"uuid": eio2.uuid}) response1 = self.client.get(url1) response2 = self.client.get(url2) self.assertEqual(response1.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN)
def test_eio_detail_filter_by_wrong_registratie_op_gives_404(self): eio = EnkelvoudigInformatieObjectFactory.create(beschrijving="beschrijving1") eio_url = reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid} ) lock = self.client.post(f"{eio_url}/lock").data["lock"] self.client.patch(eio_url, {"beschrijving": "beschrijving2", "lock": lock}) response = self.client.get(eio_url, {"registratieOp": "2019-01-01T11:59:00"}) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_zaakinformatieobject(self): io = EnkelvoudigInformatieObjectFactory.create(identificatie="12345") zio = ZaakInformatieObjectFactory( zaak__bronorganisatie=730924658, zaak__identificatie="5d940d52-ff5e-4b18-a769-977af9130c04", informatieobject=io.canonical, ) self.assertEqual( zio.unique_representation(), "(730924658 - 5d940d52-ff5e-4b18-a769-977af9130c04) - 12345", )
def test_eio_detail_filter_by_version(self): eio = EnkelvoudigInformatieObjectFactory.create(beschrijving="beschrijving1") eio_url = reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid} ) lock = self.client.post(f"{eio_url}/lock").data["lock"] self.client.patch(eio_url, {"beschrijving": "beschrijving2", "lock": lock}) response = self.client.get(eio_url, {"versie": 1}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["beschrijving"], "beschrijving1")
def test_destroy_with_relations_not_allowed(self): """ Assert that destroying is not possible when there are relations. """ eio = EnkelvoudigInformatieObjectFactory.create() ObjectInformatieObjectFactory.create(informatieobject=eio.canonical) url = reverse(eio) response = self.client.delete(url) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "pending-relations")
def test_eio_delete(self): eio = EnkelvoudigInformatieObjectFactory.create(beschrijving="beschrijving1") eio_url = reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid} ) lock = self.client.post(f"{eio_url}/lock").data["lock"] self.client.patch(eio_url, {"beschrijving": "beschrijving2", "lock": lock}) response = self.client.delete(eio_url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertFalse(EnkelvoudigInformatieObjectCanonical.objects.exists()) self.assertFalse(EnkelvoudigInformatieObject.objects.exists())
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_and_delete_gebruiksrechten_audittrail(self): informatieobject = EnkelvoudigInformatieObjectFactory.create() content = { "informatieobject": reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": informatieobject.uuid}, ), "startdatum": datetime.now(), "omschrijvingVoorwaarden": "test", } gebruiksrechten_response = self.client.post( self.gebruiksrechten_list_url, content).data informatieobject_url = gebruiksrechten_response["informatieobject"] audittrails = AuditTrail.objects.filter( hoofd_object=informatieobject_url) self.assertEqual(audittrails.count(), 1) # Verify that the audittrail for the Gebruiksrechten creation # contains the correct information gebruiksrechten_create_audittrail = audittrails.get() self.assertEqual(gebruiksrechten_create_audittrail.bron, "DRC") self.assertEqual(gebruiksrechten_create_audittrail.actie, "create") self.assertEqual(gebruiksrechten_create_audittrail.resultaat, 201) self.assertEqual(gebruiksrechten_create_audittrail.oud, None) self.assertEqual(gebruiksrechten_create_audittrail.nieuw, gebruiksrechten_response) delete_response = self.client.delete(gebruiksrechten_response["url"]) self.assertEqual(delete_response.status_code, status.HTTP_204_NO_CONTENT) audittrails = AuditTrail.objects.filter( hoofd_object=informatieobject_url) self.assertEqual(audittrails.count(), 2) # Verify that the audittrail for the Gebruiksrechten deletion # contains the correct information gebruiksrechten_delete_audittrail = audittrails[1] self.assertEqual(gebruiksrechten_delete_audittrail.bron, "DRC") self.assertEqual(gebruiksrechten_delete_audittrail.actie, "destroy") self.assertEqual(gebruiksrechten_delete_audittrail.resultaat, 204) self.assertEqual(gebruiksrechten_delete_audittrail.oud, gebruiksrechten_response) self.assertEqual(gebruiksrechten_delete_audittrail.nieuw, None)
def test_unlock_fail_incorrect_id(self): eio = EnkelvoudigInformatieObjectFactory.create( canonical__lock=uuid.uuid4().hex, informatieobjecttype=self.informatieobjecttype, ) url = get_operation_url("enkelvoudiginformatieobject_unlock", uuid=eio.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_create(self): zaak = ZaakFactory.create() zaak_url = reverse(zaak) io = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False ) io_url = reverse(io) ZaakInformatieobjectTypeFactory.create( informatieobjecttype=io.informatieobjecttype, zaaktype=zaak.zaaktype ) titel = "some titel" beschrijving = "some beschrijving" content = { "informatieobject": f"http://testserver{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_eio_detail_filter_by_registratie_op(self): with freeze_time("2019-01-01 12:00:00"): eio = EnkelvoudigInformatieObjectFactory.create( beschrijving="beschrijving1" ) eio_url = reverse( "enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid} ) lock = self.client.post(f"{eio_url}/lock").data["lock"] with freeze_time("2019-01-01 13:00:00"): self.client.patch(eio_url, {"beschrijving": "beschrijving2", "lock": lock}) response = self.client.get(eio_url, {"registratieOp": "2019-01-01T12:00:00"}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["beschrijving"], "beschrijving1")
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") zio = ZaakInformatieObjectFactory.create(zaak=zaak, informatieobject=io.canonical) 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_unlock_success(self): lock = uuid.uuid4().hex eio = EnkelvoudigInformatieObjectFactory.create( canonical__lock=lock, informatieobjecttype=self.informatieobjecttype ) url = get_operation_url("enkelvoudiginformatieobject_unlock", uuid=eio.uuid) response = self.client.post(url, {"lock": lock}) self.assertEqual( response.status_code, status.HTTP_204_NO_CONTENT, response.data ) eio.refresh_from_db() self.assertEqual(eio.canonical.lock, "")
def test_read(self): test_object = EnkelvoudigInformatieObjectFactory.create() # Retrieve from the API detail_url = reverse(test_object) response = self.client.get(detail_url) # Test response self.assertEqual(response.status_code, status.HTTP_200_OK) file_url = get_operation_url( "enkelvoudiginformatieobject_download", uuid=test_object.uuid ) expected = { "url": f"http://testserver{detail_url}", "identificatie": test_object.identificatie, "bronorganisatie": test_object.bronorganisatie, "creatiedatum": "2018-06-27", "titel": "some titel", "auteur": "some auteur", "status": "", "formaat": "some formaat", "taal": "nld", "beginRegistratie": test_object.begin_registratie.isoformat().replace( "+00:00", "Z" ), "versie": 1, "bestandsnaam": "", "inhoud": f"http://testserver{file_url}?versie=1", "bestandsomvang": test_object.inhoud.size, "link": "", "beschrijving": "", "ontvangstdatum": None, "verzenddatum": None, "ondertekening": {"soort": "", "datum": None}, "indicatieGebruiksrecht": None, "vertrouwelijkheidaanduiding": "openbaar", "integriteit": {"algoritme": "", "waarde": "", "datum": None}, "informatieobjecttype": f"http://testserver{reverse(test_object.informatieobjecttype)}", "locked": False, } response_data = response.json() self.assertEqual(sorted(response_data.keys()), sorted(expected.keys())) for key in response_data.keys(): with self.subTest(field=key): self.assertEqual(response_data[key], expected[key])
def test_cannot_read_without_correct_scope(self): eio = EnkelvoudigInformatieObjectFactory.create() gebruiksrechten = GebruiksrechtenFactory.create() # oio = ObjectInformatieObjectFactory.create(is_besluit=True) urls = [ reverse("enkelvoudiginformatieobject-list"), reverse("enkelvoudiginformatieobject-detail", kwargs={"uuid": eio.uuid}), reverse("gebruiksrechten-list"), reverse(gebruiksrechten), # FIXME add when objectinformatieobject is implemented # reverse('objectinformatieobject-list'), # reverse('objectinformatieobject-'), ] for url in urls: with self.subTest(url=url): self.assertForbidden(url, method="get")