def test_delete_zaak_cascades_properly(self): """ Deleting a zaak causes all related objects to be deleted as well. """ zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) ZaakFactory.create(hoofdzaak=zaak, zaaktype=ZAAKTYPE) ZaakEigenschapFactory.create(zaak=zaak) StatusFactory.create(zaak=zaak) RolFactory.create(zaak=zaak) ResultaatFactory.create(zaak=zaak) ZaakObjectFactory.create(zaak=zaak) ZaakInformatieObjectFactory.create(zaak=zaak) KlantContactFactory.create(zaak=zaak) zaak_delete_url = get_operation_url('zaak_delete', uuid=zaak.uuid) response = self.client.delete(zaak_delete_url, **ZAAK_WRITE_KWARGS) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, response.data) self.assertEqual(Zaak.objects.all().count(), 0) self.assertEqual(ZaakEigenschap.objects.all().count(), 0) self.assertEqual(Status.objects.all().count(), 0) self.assertEqual(Rol.objects.all().count(), 0) self.assertEqual(Resultaat.objects.all().count(), 0) self.assertEqual(ZaakObject.objects.all().count(), 0) self.assertEqual(ZaakInformatieObject.objects.all().count(), 0) self.assertEqual(KlantContact.objects.all().count(), 0)
def test_list_zaakeigenschap_limited_to_authorized_zaken(self): # must show up eigenschap1 = ZaakEigenschapFactory.create( zaak__zaaktype="https://zaaktype.nl/ok", zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. openbaar, ) # must not show up eigenschap2 = ZaakEigenschapFactory.create( zaak__zaaktype="https://zaaktype.nl/not_ok", zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. openbaar, ) # must not show up eigenschap3 = ZaakEigenschapFactory.create( zaak__zaaktype="https://zaaktype.nl/ok", zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. vertrouwelijk, ) with self.subTest( zaaktype=eigenschap1.zaak.zaaktype, vertrouwelijkheidaanduiding=eigenschap1.zaak. vertrouwelijkheidaanduiding, ): url = reverse("zaakeigenschap-list", kwargs={"zaak_uuid": eigenschap1.zaak.uuid}) eigenschap1_url = reverse( eigenschap1, kwargs={"zaak_uuid": eigenschap1.zaak.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{eigenschap1_url}") # not allowed to see these for eigenschap in (eigenschap2, eigenschap3): with self.subTest( zaaktype=eigenschap.zaak.zaaktype, vertrouwelijkheidaanduiding=eigenschap.zaak. vertrouwelijkheidaanduiding, ): url = reverse("zaakeigenschap-list", kwargs={"zaak_uuid": eigenschap.zaak.uuid}) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_zaak_eigenschappen_update(self): zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaakeigenschap = ZaakEigenschapFactory.create( zaak=zaak, eigenschap=EIGENSCHAP, waarde="This is a value" ) zaakeigenschap_url = reverse( "zaakeigenschap-detail", kwargs={"version": 1, "zaak_uuid": zaak.uuid, "uuid": zaakeigenschap.uuid}, ) zaak_url = reverse( "zaak-detail", kwargs={"version": 1, "uuid": zaak.uuid}, ) zaakeigenschap_data = { "zaak": f"http://example.com{zaak_url}", "eigenschap": zaakeigenschap.eigenschap, "waarde": "This is a changed value", } response = self.client.put(zaakeigenschap_url, data=zaakeigenschap_data) self.assertEqual(status.HTTP_200_OK, response.status_code) zaakeigenschap.refresh_from_db() self.assertEqual("This is a changed value", zaakeigenschap.waarde)
def test_cannot_change_zaak(self): zaak1 = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak2 = ZaakFactory.create(zaaktype=ZAAKTYPE) zaakeigenschap = ZaakEigenschapFactory.create( zaak=zaak1, eigenschap=EIGENSCHAP, waarde="This is a value" ) zaakeigenschap_url = reverse( "zaakeigenschap-detail", kwargs={"version": 1, "zaak_uuid": zaak1.uuid, "uuid": zaakeigenschap.uuid}, ) zaak2_url = reverse( "zaak-detail", kwargs={"version": 1, "uuid": zaak2.uuid}, ) zaakeigenschap_data = { "zaak": f"http://example.com{zaak2_url}", "eigenschap": EIGENSCHAP, "waarde": "This is a changed value", } response = self.client.patch(zaakeigenschap_url, data=zaakeigenschap_data) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) invalid_params = response.json()["invalidParams"] self.assertEqual(1, len(invalid_params)) self.assertIn("zaak", invalid_params[0]["name"]) self.assertEqual("wijzigen-niet-toegelaten", invalid_params[0]["code"])
def test_zaakeigenschap_get_cache_header(self): zaakeigenschap = ZaakEigenschapFactory.create() response = self.client.get( reverse(zaakeigenschap, kwargs={"zaak_uuid": zaakeigenschap.zaak.uuid})) self.assertHasETag(response)
def test_lees_eigenschappen(self): zaak = ZaakFactory.create() ZaakEigenschapFactory.create_batch(3, zaak=zaak) url = get_operation_url('zaakeigenschap_list', zaak_uuid=zaak.uuid) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) response_data = response.json() self.assertEqual(len(response_data), 3) for obj in response_data: with self.subTest(obj=obj): self.assertResponseTypes(obj, ( ('url', str), ('zaak', str), ('eigenschap', str), ('waarde', str), ))
def test_add_resultaat_on_zaak_with_eigenschap_causes_archiefactiedatum_to_be_set( self): """ Add RESULTAAT that causes `archiefactiedatum` to be set. """ zaak = ZaakFactory.create() zaak_url = get_operation_url('zaak_read', uuid=zaak.uuid) ZaakEigenschapFactory.create(zaak=zaak, _naam='brondatum', waarde=isodatetime(2019, 1, 1)) resultaat_create_url = get_operation_url('resultaat_create') data = { 'zaak': zaak_url, 'resultaatType': RESULTAATTYPE, 'toelichting': '', } responses = { RESULTAATTYPE: { 'url': RESULTAATTYPE, 'archiefactietermijn': 'P10Y', 'archiefnominatie': Archiefnominatie.blijvend_bewaren, 'brondatumArchiefprocedure': { 'afleidingswijze': BrondatumArchiefprocedureAfleidingswijze.eigenschap, 'datumkenmerk': 'brondatum', 'objecttype': None, 'procestermijn': None, } } } self.assertIsNone(zaak.archiefactiedatum) with mock_client(responses): response = self.client.post(resultaat_create_url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) zaak.refresh_from_db() self.assertEqual(zaak.archiefactiedatum, date(2029, 1, 1))
def test_conditional_get_stale(self): zaak_eigenschap = ZaakEigenschapFactory.create(with_etag=True) response = self.client.get( reverse(zaak_eigenschap, kwargs={"zaak_uuid": zaak_eigenschap.zaak.uuid}), HTTP_IF_NONE_MATCH='"old"', ) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_conditional_get_304(self): zaak_eigenschap = ZaakEigenschapFactory.create(with_etag=True) response = self.client.get( reverse(zaak_eigenschap, kwargs={"zaak_uuid": zaak_eigenschap.zaak.uuid}), HTTP_IF_NONE_MATCH=f'"{zaak_eigenschap._etag}"', ) self.assertEqual(response.status_code, status.HTTP_304_NOT_MODIFIED)
def test_detail_zaakeigenschap_limited_to_authorized_zaken(self): # must show up eigenschap1 = ZaakEigenschapFactory.create( zaak__zaaktype='https://zaaktype.nl/ok', zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. openbaar) # must not show up eigenschap2 = ZaakEigenschapFactory.create( zaak__zaaktype='https://zaaktype.nl/not_ok', zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. openbaar) # must not show up eigenschap3 = ZaakEigenschapFactory.create( zaak__zaaktype='https://zaaktype.nl/ok', zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. vertrouwelijk) with self.subTest(zaaktype=eigenschap1.zaak.zaaktype, vertrouwelijkheidaanduiding=eigenschap1.zaak. vertrouwelijkheidaanduiding): url = reverse(eigenschap1, kwargs={'zaak_uuid': eigenschap1.zaak.uuid}) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) # not allowed to see these for eigenschap in (eigenschap2, eigenschap3): with self.subTest(zaaktype=eigenschap.zaak.zaaktype, vertrouwelijkheidaanduiding=eigenschap.zaak. vertrouwelijkheidaanduiding): url = reverse(eigenschap, kwargs={'zaak_uuid': eigenschap.zaak.uuid}) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_delete(self): zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaakeigenschap = ZaakEigenschapFactory.create( zaak=zaak, eigenschap=EIGENSCHAP, waarde="This is a value" ) zaakeigenschap_url = reverse( "zaakeigenschap-detail", kwargs={"version": 1, "zaak_uuid": zaak.uuid, "uuid": zaakeigenschap.uuid}, ) self.assertEqual(1, ZaakEigenschap.objects.all().count()) response = self.client.delete(zaakeigenschap_url) self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) self.assertEqual(0, ZaakEigenschap.objects.all().count())
def test_zaak_eigenschappen_partial_update_without_eigenschap(self): zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaakeigenschap = ZaakEigenschapFactory.create( zaak=zaak, eigenschap=EIGENSCHAP, waarde="This is a value" ) zaakeigenschap_url = reverse( "zaakeigenschap-detail", kwargs={"version": 1, "zaak_uuid": zaak.uuid, "uuid": zaakeigenschap.uuid}, ) zaakeigenschap_data = { "waarde": "This is a changed value", } response = self.client.patch(zaakeigenschap_url, data=zaakeigenschap_data) self.assertEqual(status.HTTP_200_OK, response.status_code) zaakeigenschap.refresh_from_db() self.assertEqual("This is a changed value", zaakeigenschap.waarde)
def test_send_notif_update_zaak_eigenschap(self, mock_client): """ Check if notifications will be send when zaak-eigenschap is updated """ client = mock_client.return_value zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak_url = get_operation_url("zaak_read", uuid=zaak.uuid) zaakeigenschap = ZaakEigenschapFactory.create(zaak=zaak, waarde="old") zaakeigenschap_url = get_operation_url("zaakeigenschap_update", uuid=zaakeigenschap.uuid, zaak_uuid=zaak.uuid) with capture_on_commit_callbacks(execute=True): response = self.client.patch(zaakeigenschap_url, data={"waarde": "new"}) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) client.create.assert_called_once_with( "notificaties", { "kanaal": "zaken", "hoofdObject": f"http://testserver{zaak_url}", "resource": "zaakeigenschap", "resourceUrl": f"http://testserver{zaakeigenschap_url}", "actie": "partial_update", "aanmaakdatum": "2012-01-14T00:00:00Z", "kenmerken": { "bronorganisatie": zaak.bronorganisatie, "zaaktype": zaak.zaaktype, "vertrouwelijkheidaanduiding": zaak.vertrouwelijkheidaanduiding, }, }, )
def test_add_resultaat_on_zaak_with_eigenschap_causes_archiefactiedatum_to_be_set( self): """ Add RESULTAAT that causes `archiefactiedatum` to be set. """ zaak = ZaakFactory.create(zaaktype=ZAAKTYPE) zaak_url = get_operation_url('zaak_read', uuid=zaak.uuid) ZaakEigenschapFactory.create(zaak=zaak, _naam='brondatum', waarde=isodatetime(2019, 1, 1)) resultaat_create_url = get_operation_url('resultaat_create') data = { 'zaak': zaak_url, 'resultaatType': RESULTAATTYPE, 'toelichting': '', } self.assertIsNone(zaak.archiefactiedatum) 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') responses = { RESULTAATTYPE: { 'url': RESULTAATTYPE, 'archiefactietermijn': 'P10Y', 'archiefnominatie': Archiefnominatie.blijvend_bewaren, 'brondatumArchiefprocedure': { 'afleidingswijze': BrondatumArchiefprocedureAfleidingswijze.eigenschap, 'datumkenmerk': 'brondatum', 'objecttype': None, 'procestermijn': None, } }, STATUSTYPE: { 'url': STATUSTYPE, 'volgnummer': 2, 'isEindstatus': True, } } data = { 'zaak': zaak_url, 'statusType': STATUSTYPE, 'datumStatusGezet': '2018-10-18T20:00:00Z', } with mock_client(responses): response = self.client.post(status_create_url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data) zaak.refresh_from_db() self.assertEqual(zaak.archiefactiedatum, date(2029, 1, 1))
def test_zaakeigenschap_head_cache_header(self): zaakeigenschap = ZaakEigenschapFactory.create() self.assertHeadHasETag( reverse(zaakeigenschap, kwargs={"zaak_uuid": zaakeigenschap.zaak.uuid}))