def test_ontvangen_informatieobjecten(self): """ Assert certain statuses are not allowed for received documents. RGBZ 2.00.02 deel II Concept 20180613: De waarden ?in bewerking? en ?ter vaststelling? zijn niet van toepassing op ontvangen informatieobjecten. """ invalid_statuses = (Statussen.in_bewerking, Statussen.ter_vaststelling) data = { 'bronorganisatie': '319582462', 'creatiedatum': '2018-12-24', 'titel': 'dummy', 'auteur': 'dummy', 'taal': 'dut', 'inhoud': 'aGVsbG8gd29ybGQ=', 'informatieobjecttype': 'https://example.com/ztc/api/v1/catalogus/1/informatieobjecttype/1', 'ontvangstdatum': '2018-12-24', } for invalid_status in invalid_statuses: with self.subTest(status=invalid_status): _data = data.copy() _data['status'] = invalid_status response = self.client.post(self.url, _data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, 'status') self.assertEqual(error['code'], 'invalid_for_received')
def test_update_zaak(self): eo = EnkelvoudigInformatieObjectFactory.create() zio = ObjectInformatieObjectFactory.create(is_zaak=True) eo_detail_url = reverse('enkelvoudiginformatieobject-detail', kwargs={ 'version': '1', 'uuid': eo.uuid, }) zio_detail_url = reverse('objectinformatieobject-detail', kwargs={ 'version': '1', 'uuid': zio.uuid, }) response = self.client.patch( zio_detail_url, { 'object': 'https://something.different', 'informatieobject': eo_detail_url, 'objectType': ObjectTypes.besluit, }) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) for field in ['object', 'informatieobject', 'objectType']: with self.subTest(field=field): error = get_validation_errors(response, field) self.assertEqual(error['code'], IsImmutableValidator.code)
def test_duplicate_object(self): """ Test the (informatieobject, object) unique together validation. """ oio = ObjectInformatieObjectFactory.create(is_zaak=True) enkelvoudig_informatie_url = reverse( 'enkelvoudiginformatieobject-detail', kwargs={ 'version': '1', 'uuid': oio.informatieobject.uuid, }) content = { 'informatieobject': f'http://testserver{enkelvoudig_informatie_url}', 'object': oio.object, 'objectType': ObjectTypes.zaak, } # 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 assertGegevensGroepValidation(self, url: str, field: str, base_body: dict, cases: tuple): for key, code, blank_value in cases: with self.subTest(key=key, expected_code=code): body = deepcopy(base_body) body[key] = blank_value response = self.client.post(url, {field: body}) error = get_validation_errors(response, f'{field}.{key}') self.assertEqual(error['code'], code)
def test_create_zaak_zonder_bronorganisatie(self): url = get_operation_url('zaak_create') data = { 'zaaktype': ZAAKTYPE, 'registratiedatum': '2018-06-11', } response = self.client.post(url, data, HTTP_ACCEPT_CRS='EPSG:4326') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, 'bronorganisatie') self.assertEqual(error['code'], 'required')
def test_validate_informatieobjecttype_invalid(self): url = reverse('enkelvoudiginformatieobject-list') response = self.client.post( url, { 'informatieobjecttype': 'https://example.com/informatieobjecttype/foo', }) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, 'informatieobjecttype') self.assertEqual(error['code'], URLValidator.code)
def test_informatieobjecten_niet_ontvangen(self): """ All statusses should be allowed when the informatieobject doesn't have a receive date. """ for valid_status, _ in Statussen.choices: with self.subTest(status=status): data = {'ontvangstdatum': None, 'status': valid_status} response = self.client.post(self.url, data) error = get_validation_errors(response, 'status') self.assertIsNone(error)
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_block_clearing_indication(self): """ If gebruiksrechten exist, you cannot change the indicatieGebruiksrechten anymore. """ gebruiksrechten = GebruiksrechtenFactory.create() url = reverse('enkelvoudiginformatieobject-detail', kwargs={'uuid': gebruiksrechten.informatieobject.uuid}) for invalid_value in (None, False): data = {'indicatieGebruiksrecht': invalid_value} response = self.client.patch(url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, 'indicatieGebruiksrecht') self.assertEqual(error['code'], 'existing-gebruiksrechten')
def test_uniqueness_identificatie(self): ZaakFactory.create(identificatie='strtmzk-0001', bronorganisatie='517439943') url = get_operation_url('zaak_create') data = { 'zaaktype': ZAAKTYPE, 'identificatie': 'strtmzk-0001', 'bronorganisatie': '517439943', 'verantwoordelijkeOrganisatie': VERANTWOORDELIJKE_ORGANISATIE, 'startdatum': '2018-06-11', } response = self.client.post(url, data, HTTP_ACCEPT_CRS='EPSG:4326') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data['code'], 'invalid') error = get_validation_errors(response, 'identificatie') self.assertEqual(error['code'], 'identificatie-niet-uniek')
def test_status_set_ontvangstdatum_is_set_later(self): """ Assert that setting the ontvangstdatum later, after an 'invalid' status has been set, is not possible. """ eio = EnkelvoudigInformatieObjectFactory.create(ontvangstdatum=None) url = reverse('enkelvoudiginformatieobject-detail', kwargs={'uuid': eio.uuid}) for invalid_status in (Statussen.in_bewerking, Statussen.ter_vaststelling): with self.subTest(status=invalid_status): eio.status = invalid_status eio.save() data = {'ontvangstdatum': '2018-12-24'} response = self.client.patch(url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, 'status') self.assertEqual(error['code'], 'invalid_for_received')