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_zaak_heropen_reset_einddatum(self): token = generate_jwt([SCOPE_STATUSSEN_TOEVOEGEN]) self.client.credentials(HTTP_AUTHORIZATION=token) zaak = ZaakFactory.create(einddatum='2019-01-07') StatusFactory.create( zaak=zaak, status_type= 'http://example.com/ztc/api/v1/catalogussen/1/zaaktypen/1/statustypen/2', datum_status_gezet='2019-01-07T12:51:41+0000', ) zaak_url = reverse('zaak-detail', kwargs={'uuid': zaak.uuid}) status_list_url = reverse('status-list') # Set status other than eindstatus datum_status_gezet = utcdatetime(2019, 1, 7, 12, 53, 25) response = self.client.post( status_list_url, { 'zaak': zaak_url, 'statusType': 'http://example.com/ztc/api/v1/catalogussen/1/zaaktypen/1/statustypen/1', 'datumStatusGezet': datum_status_gezet.isoformat(), }) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content) zaak.refresh_from_db() self.assertIsNone(zaak.einddatum)
def test_zaak_heropen_reset_einddatum(self): self.autorisatie.scopes = self.autorisatie.scopes + [ SCOPEN_ZAKEN_HEROPENEN ] self.autorisatie.save() zaak = ZaakFactory.create(einddatum='2019-01-07', zaaktype=ZAAKTYPE) StatusFactory.create( zaak=zaak, status_type= 'http://example.com/ztc/api/v1/catalogussen/1/zaaktypen/1/statustypen/2', datum_status_gezet='2019-01-07T12:51:41+0000', ) zaak_url = reverse('zaak-detail', kwargs={'uuid': zaak.uuid}) status_list_url = reverse('status-list') # Set status other than eindstatus datum_status_gezet = utcdatetime(2019, 1, 7, 12, 53, 25) response = self.client.post( status_list_url, { 'zaak': zaak_url, 'statusType': 'http://example.com/ztc/api/v1/catalogussen/1/zaaktypen/1/statustypen/1', 'datumStatusGezet': datum_status_gezet.isoformat(), }) self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content) zaak.refresh_from_db() self.assertIsNone(zaak.einddatum)
def test_list_resultaat_limited_to_authorized_zaken(self): url = reverse('status-list') # must show up status1 = StatusFactory.create( zaak__zaaktype='https://zaaktype.nl/ok', zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. openbaar) # must not show up StatusFactory.create( zaak__zaaktype='https://zaaktype.nl/ok', zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. vertrouwelijk) # must not show up StatusFactory.create( zaak__zaaktype='https://zaaktype.nl/not_ok', zaak__vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding. openbaar) 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{reverse(status1)}")
def test_invalidate_new_status(self): """ Status URL is part of the resource, so new status invalidates the ETag. """ zaak = ZaakFactory.create(with_etag=True) etag = zaak._etag # create new status StatusFactory.create(zaak=zaak) response = self.client.get(reverse(zaak), HTTP_IF_NONE_MATCH=f'"{etag}"', **ZAAK_READ_KWARGS) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_conditional_get_stale(self): status_ = StatusFactory.create(with_etag=True) response = self.client.get(reverse(status_), HTTP_IF_NONE_MATCH='"not-an-md5"') self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_create_status_existing_combination_zaak_datum_status_gezet(self, *mocks): zaak = ZaakFactory.create() status = StatusFactory.create( zaak=zaak, datum_status_gezet="2019-01-01T12:00:00Z" ) list_url = reverse("status-list") STATUSTYPE = "https://www.ztc.nl/statustypen/1234" responses = { STATUSTYPE: { "url": STATUSTYPE, "zaaktype": zaak.zaaktype, "volgnummer": 1, "isEindstatus": False, } } data = { "zaak": reverse(zaak), "statustype": STATUSTYPE, "datumStatusGezet": "2019-01-01T12:00:00Z", } with mock_client(responses): response = self.client.post(list_url, data) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "unique")
def test_filter_statussen_on_zaak_external_url(self): StatusFactory.create() list_url = reverse("status-list") bad_urls = [ "https://google.nl", "https://example.com/", "https://example.com/404", ] for bad_url in bad_urls: with self.subTest(bad_url=bad_url): response = self.client.get(list_url, {"zaak": bad_url}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["count"], 0)
def test_not_allowed_to_change_statustype(self): _status = StatusFactory.create() url = reverse(_status) response = self.client.patch( url, {"statustype": "https://ander.statustype.nl/foo/bar"} ) self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
def test_conditional_get_304(self): """ Test that, if I have a cached copy, the API returns an HTTP 304. """ status_ = StatusFactory.create(with_etag=True) response = self.client.get(reverse(status_), HTTP_IF_NONE_MATCH=f'"{status_._etag}"') self.assertEqual(response.status_code, status.HTTP_304_NOT_MODIFIED)
def test_filter_statussen_op_zaak(self): status1, status2 = StatusFactory.create_batch(2) assert status1.zaak != status2.zaak status1_url = reverse('status-detail', kwargs={'uuid': status1.uuid}) status2_url = reverse('status-detail', kwargs={'uuid': status2.uuid}) list_url = reverse('status-list') response = self.client.get(list_url, { 'zaak': reverse('zaak-detail', kwargs={'uuid': status1.zaak.uuid}) }) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['url'], f"http://testserver{status1_url}") self.assertNotEqual(response.data[0]['url'], f"http://testserver{status2_url}")
def test_cannot_read_without_correct_scope(self): zaak = ZaakFactory.create() status = StatusFactory.create() zaak_object = ZaakObjectFactory.create() resultaat = ResultaatFactory.create() urls = [ reverse('zaak-list'), reverse(zaak), reverse('status-list'), reverse(status), reverse('status-list'), reverse(resultaat), reverse('zaakobject-list'), reverse(zaak_object), ] for url in urls: with self.subTest(url=url): self.assertForbidden(url, method='get', request_kwargs=ZAAK_READ_KWARGS)
def test_filter_statussen_op_zaak(self): status1, status2 = StatusFactory.create_batch(2) assert status1.zaak != status2.zaak status1_url = reverse("status-detail", kwargs={"uuid": status1.uuid}) status2_url = reverse("status-detail", kwargs={"uuid": status2.uuid}) list_url = reverse("status-list") zaak_path = reverse(status1.zaak) response = self.client.get( list_url, {"zaak": f"http://testserver.com{zaak_path}"}, HTTP_HOST="testserver.com", ) response_data = response.json()["results"] self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response_data), 1) self.assertEqual(response_data[0]["url"], f"http://testserver.com{status1_url}") self.assertNotEqual(response_data[0]["url"], f"http://testserver.com{status2_url}")
def test_status_get_cache_header(self): status_ = StatusFactory.create() response = self.client.get(reverse(status_)) self.assertHasETag(response)
def test_status_head_cache_header(self): status_ = StatusFactory.create() self.assertHeadHasETag(reverse(status_))