def test_list(self): """ Assert that it's possible to list besluiten for zaken. """ zaak = ZaakFactory.create() besluit = BesluitFactory.create(zaak=zaak) BesluitFactory.create(zaak=None) # unrelated besluit url = reverse("zaakbesluit-list", kwargs={"zaak_uuid": zaak.uuid}) zaakbesluit_url = reverse("zaakbesluit-detail", kwargs={ "zaak_uuid": zaak.uuid, "uuid": besluit.uuid }) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( response.data, [{ "url": f"http://testserver{zaakbesluit_url}", "uuid": str(besluit.uuid), "besluit": f"http://testserver{reverse(besluit)}", }], )
def test_change_immutable_fields(self): besluit = BesluitFactory.create(identificatie="123456") besluit2 = BesluitFactory.create(identificatie="123456") url = reverse(besluit) response = self.client.patch( url, { "verantwoordelijkeOrganisatie": besluit2.verantwoordelijke_organisatie, "identificatie": "123456789", }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) identificatie_error = get_validation_errors(response, "identificatie") self.assertEqual(identificatie_error["code"], IsImmutableValidator.code) verantwoordelijke_organisatie_error = get_validation_errors( response, "verantwoordelijkeOrganisatie" ) self.assertEqual( verantwoordelijke_organisatie_error["code"], IsImmutableValidator.code )
def test_besluit_retreive(self): """ Assert you can only read BESLUITen of the besluittypes of your authorization """ besluit1 = BesluitFactory.create(besluittype=self.besluittype) besluit2 = BesluitFactory.create() url1 = reverse(besluit1) url2 = reverse(besluit2) response1 = self.client.get(url1) response2 = self.client.get(url2) self.assertEqual(response1.status_code, status.HTTP_200_OK) self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN)
def test_list_zaakbesluit_limited_to_authorized_zaken(self): # must show up besluit1 = BesluitFactory.create( for_zaak=True, zaak__zaaktype=self.zaaktype, zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar, ) # must not show up besluit2 = BesluitFactory.create( for_zaak=True, zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar, ) # must not show up besluit3 = BesluitFactory.create( for_zaak=True, zaak__zaaktype=self.zaaktype, zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.vertrouwelijk, ) with self.subTest( zaaktype=besluit1.zaak.zaaktype, vertrouwelijkheidaanduiding=besluit1.zaak.vertrouwelijkheidaanduiding, ): url = reverse("zaakbesluit-list", kwargs={"zaak_uuid": besluit1.zaak.uuid}) zio1_url = get_operation_url( "zaakbesluit_read", zaak_uuid=besluit1.zaak.uuid, uuid=besluit1.uuid ) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) response_data = response.json() self.assertEqual(len(response_data), 1) self.assertEqual(response_data[0]["url"], f"http://testserver{zio1_url}") # not allowed to see these for besluit in (besluit2, besluit3): with self.subTest( zaaktype=besluit.zaak.zaaktype, vertrouwelijkheidaanduiding=besluit.zaak.vertrouwelijkheidaanduiding, ): url = reverse( "zaakbesluit-list", kwargs={"zaak_uuid": besluit.zaak.uuid} ) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
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_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_send_notif_delete_resultaat(self, mock_client): """ Check if notifications will be send when resultaat is deleted """ client = mock_client.return_value besluit = BesluitFactory.create() besluit_url = get_operation_url("besluit_read", uuid=besluit.uuid) besluittype_url = reverse(besluit.besluittype) bio = BesluitInformatieObjectFactory.create(besluit=besluit) bio_url = get_operation_url("besluitinformatieobject_delete", uuid=bio.uuid) response = self.client.delete(bio_url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, response.data) client.create.assert_called_once_with( "notificaties", { "kanaal": "besluiten", "hoofdObject": f"http://testserver{besluit_url}", "resource": "besluitinformatieobject", "resourceUrl": f"http://testserver{bio_url}", "actie": "destroy", "aanmaakdatum": "2018-09-07T00:00:00Z", "kenmerken": { "verantwoordelijkeOrganisatie": besluit.verantwoordelijke_organisatie, "besluittype": f"http://testserver{besluittype_url}", }, }, )
def test_besluit_list(self): """ Assert you can only list BESLUITen of the besluittypes of your authorization """ BesluitFactory.create(besluittype=self.besluittype) BesluitFactory.create() url = reverse("besluit-list") response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) results = response.data["results"] self.assertEqual(len(results), 1) self.assertEqual(results[0]["besluittype"], f"http://testserver{reverse(self.besluittype)}")
def test_read_superuser(self): """ superuser read everything """ self.applicatie.heeft_alle_autorisaties = True self.applicatie.save() BesluitFactory.create(besluittype=self.besluittype) BesluitFactory.create() url = reverse("besluit-list") response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) response_data = response.json()["results"] self.assertEqual(len(response_data), 2)
def test_create(self): besluit = BesluitFactory.create(for_zaak=True) besluit_url = reverse(besluit) url = reverse("zaakbesluit-list", kwargs={"zaak_uuid": besluit.zaak.uuid}) response = self.client.post(url, {"besluit": besluit_url}) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_detail_zaakbesluit_limited_to_authorized_zaken(self): # must show up besluit1 = BesluitFactory.create( for_zaak=True, zaak__zaaktype=self.zaaktype, zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar, ) # must not show up besluit2 = BesluitFactory.create( for_zaak=True, zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar, ) # must not show up besluit3 = BesluitFactory.create( for_zaak=True, zaak__zaaktype=self.zaaktype, zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.vertrouwelijk, ) with self.subTest( zaaktype=besluit1.zaak.zaaktype, vertrouwelijkheidaanduiding=besluit1.zaak.vertrouwelijkheidaanduiding, ): url = get_operation_url( "zaakbesluit_read", zaak_uuid=besluit1.zaak.uuid, uuid=besluit1.uuid ) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) # not allowed to see these for besluit in (besluit2, besluit3): with self.subTest( zaaktype=besluit.zaak.zaaktype, vertrouwelijkheidaanduiding=besluit.zaak.vertrouwelijkheidaanduiding, ): url = get_operation_url( "zaakbesluit_read", zaak_uuid=besluit.zaak.uuid, uuid=besluit.uuid ) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_detail(self): zaak = ZaakFactory.create() besluit = BesluitFactory.create(zaak=zaak) BesluitFactory.create(zaak=None) # unrelated besluit url = reverse("zaakbesluit-detail", kwargs={ "zaak_uuid": zaak.uuid, "uuid": besluit.uuid }) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( response.data, { "url": f"http://testserver{url}", "uuid": str(besluit.uuid), "besluit": f"http://testserver{reverse(besluit)}", }, )
def test_cannot_read_without_correct_scope(self): besluit = BesluitFactory.create() bio = BesluitInformatieObjectFactory.create(besluit=besluit) urls = [ reverse("besluit-list"), reverse(besluit), reverse("besluitinformatieobject-list"), reverse(bio), ] for url in urls: with self.subTest(url=url): self.assertForbidden(url, method="get")
def test_list_bio_limited_to_authorized_zaken(self): besluit1 = BesluitFactory.create(besluittype=self.besluittype) besluit2 = BesluitFactory.create() url = reverse(BesluitInformatieObject) # must show up bio1 = BesluitInformatieObjectFactory.create(besluit=besluit1) # must not show up bio2 = BesluitInformatieObjectFactory.create(besluit=besluit2) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) response_data = response.json() self.assertEqual(len(response_data), 1) besluit_url = reverse(bio1.besluit) self.assertEqual(response_data[0]["besluit"], f"http://testserver{besluit_url}")
def test_create_bio_limited_to_authorized_besluiten(self): informatieobject = EnkelvoudigInformatieObjectFactory.create( informatieobjecttype__concept=False) informatieobject_url = reverse(informatieobject) besluit1 = BesluitFactory.create(besluittype=self.besluittype) besluit2 = BesluitFactory.create() self.besluittype.informatieobjecttypes.add( informatieobject.informatieobjecttype) besluit2.besluittype.informatieobjecttypes.add( informatieobject.informatieobjecttype) besluit_uri1 = reverse(besluit1) besluit_url1 = f"http://testserver{besluit_uri1}" besluit_uri2 = reverse(besluit2) besluit_url2 = f"http://testserver{besluit_uri2}" url1 = reverse("besluitinformatieobject-list") url2 = reverse("besluitinformatieobject-list") data1 = { "informatieobject": informatieobject_url, "besluit": besluit_url1 } data2 = { "informatieobject": informatieobject_url, "besluit": besluit_url2 } response1 = self.client.post(url1, data1) response2 = self.client.post(url2, data2) self.assertEqual(response1.status_code, status.HTTP_201_CREATED, response1.data) self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN, response2.data)
def test_delete_besluit_cascades_properly(self): """ Deleting a Besluit causes all related objects to be deleted as well. """ besluit = BesluitFactory.create() BesluitInformatieObjectFactory.create(besluit=besluit) besluit_delete_url = get_operation_url("besluit_delete", uuid=besluit.uuid) response = self.client.delete(besluit_delete_url) self.assertEqual( response.status_code, status.HTTP_204_NO_CONTENT, response.data ) self.assertFalse(Besluit.objects.exists()) self.assertFalse(BesluitInformatieObject.objects.exists())
def test_validate_informatieobject_invalid(self): besluit = BesluitFactory.create() besluit_url = reverse("besluit-detail", kwargs={"uuid": besluit.uuid}) url = reverse("besluitinformatieobject-list") response = self.client.post( url, { "besluit": f"http://testserver{besluit_url}", "informatieobject": "https://foo.bar/123", }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "informatieobject") self.assertEqual(error["code"], "no_match")
def test_delete(self): besluit = BesluitFactory.create(for_zaak=True) url = reverse( "zaakbesluit-detail", kwargs={ "zaak_uuid": besluit.zaak.uuid, "uuid": besluit.uuid }, ) besluit.zaak = None # it must already be disconnected from zaak besluit.save() response = self.client.delete(url) # because the reference between zaak/besluit is broken, this 404s, as # it should self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_duplicate_rsin_identificatie(self): besluit = BesluitFactory.create(identificatie="123456") besluittype_url = reverse(besluit.besluittype) response = self.client.post( self.url, { "verantwoordelijkeOrganisatie": besluit.verantwoordelijke_organisatie, "identificatie": "123456", "besluittype": f"http://testserver{besluittype_url}", "datum": "2018-09-06", "ingangsdatum": "2018-10-01", }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "identificatie") self.assertEqual(error["code"], "identificatie-niet-uniek")
def test_validate_no_informatieobjecttype_zaaktype_relation(self): zaak = ZaakFactory.create() besluit = BesluitFactory.create(zaak=zaak) besluit_url = reverse(besluit) io = EnkelvoudigInformatieObjectFactory.create() io_url = reverse(io) url = reverse("besluitinformatieobject-list") response = self.client.post( url, { "besluit": f"http://testserver{besluit_url}", "informatieobject": f"http://testserver{io_url}", }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual( error["code"], "missing-zaaktype-informatieobjecttype-relation" )
def test_update_besluit(self): bio = BesluitInformatieObjectFactory.create() bio_detail_url = reverse(bio) besluit = BesluitFactory.create() besluit_url = reverse(besluit) io = EnkelvoudigInformatieObjectFactory.create() io_url = reverse(io) response = self.client.patch( bio_detail_url, { "besluit": f"http://testserver{besluit_url}", "informatieobject": f"http://testserver{io_url}", }, ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) for field in ["besluit", "informatieobject"]: with self.subTest(field=field): error = get_validation_errors(response, field) self.assertEqual(error["code"], IsImmutableValidator.code)
def test_zaak_archiefactiedatum_afleidingswijze_ingangsdatum_besluit(self): zaaktype = ZaakTypeFactory.create() zaak = ZaakFactory.create(zaaktype=zaaktype) zaak_url = reverse(zaak) statustype1 = StatusTypeFactory.create(zaaktype=zaaktype) statustype1_url = reverse(statustype1) statustype2 = StatusTypeFactory.create(zaaktype=zaaktype) statustype2_url = reverse(statustype2) resultaattype = ResultaatTypeFactory.create( zaaktype=zaaktype, archiefactietermijn=relativedelta(years=10), archiefnominatie=Archiefnominatie.blijvend_bewaren, brondatum_archiefprocedure_afleidingswijze= BrondatumArchiefprocedureAfleidingswijze.ingangsdatum_besluit, ) resultaattype_url = reverse(resultaattype) BesluitFactory.create(zaak=zaak, ingangsdatum="2020-05-03") # Set initial status status_list_url = reverse("status-list") response = self.client.post( status_list_url, { "zaak": zaak_url, "statustype": f"http://testserver{statustype1_url}", "datumStatusGezet": isodatetime(2018, 10, 1, 10, 00, 00), }, ) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content) zaak.refresh_from_db() self.assertIsNone(zaak.einddatum) # add a result for the case 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) # Set eindstatus datum_status_gezet = utcdatetime(2018, 10, 22, 10, 00, 00) response = self.client.post( status_list_url, { "zaak": zaak_url, "statustype": f"http://testserver{statustype2_url}", "datumStatusGezet": datum_status_gezet.isoformat(), }, ) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content) zaak.refresh_from_db() self.assertEqual(zaak.einddatum, datum_status_gezet.date()) self.assertEqual( zaak.archiefactiedatum, date(2030, 5, 3) # 2020-05-03 + 10 years )