def test_lock_fail_locked_doc(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create(lock=uuid.uuid4().hex) url = get_operation_url('enkelvoudiginformatieobject_lock', uuid=eio.latest_version.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'], 'existing-lock')
def test_update_fail_unlocked_doc(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create() assert eio.lock == '' url = get_operation_url('enkelvoudiginformatieobject_update', uuid=eio.latest_version.uuid) response = self.client.patch(url, {'titel': 'changed'}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, 'nonFieldErrors') self.assertEqual(error['code'], 'unlocked')
def test_unlock_fail_incorrect_id(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create( latest_version__informatieobjecttype=INFORMATIEOBJECTTYPE, lock=uuid.uuid4().hex ) url = get_operation_url('enkelvoudiginformatieobject_unlock', uuid=eio.latest_version.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_update_fail_unlocked_doc(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create() assert eio.lock == "" url = get_operation_url("enkelvoudiginformatieobject_update", uuid=eio.latest_version.uuid) response = self.client.patch(url, {"titel": "changed"}) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "unlocked")
def test_update_success(self): lock = uuid.uuid4().hex eio = EnkelvoudigInformatieObjectCanonicalFactory.create(lock=lock) url = get_operation_url("enkelvoudiginformatieobject_update", uuid=eio.latest_version.uuid) response = self.client.patch(url, {"titel": "changed", "lock": lock}) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) eio.refresh_from_db() self.assertEqual(eio.latest_version.titel, "changed")
def test_update_fail_wrong_id(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create( lock=uuid.uuid4().hex) url = get_operation_url("enkelvoudiginformatieobject_update", uuid=eio.latest_version.uuid) response = self.client.patch(url, {"titel": "changed", "lock": 12345}) 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_lock_success(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create() assert eio.lock == '' url = get_operation_url('enkelvoudiginformatieobject_lock', uuid=eio.latest_version.uuid) response = self.client.post(url) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) data = response.json() eio.refresh_from_db() self.assertEqual(data['lock'], eio.lock) self.assertNotEqual(data['lock'], '')
def test_update_fail_wrong_id(self): eio = EnkelvoudigInformatieObjectCanonicalFactory.create(lock=uuid.uuid4().hex) url = get_operation_url('enkelvoudiginformatieobject_update', uuid=eio.latest_version.uuid) response = self.client.patch( url, {'titel': 'changed', 'lock': 12345} ) 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_unlock_success(self): lock = uuid.uuid4().hex eio = EnkelvoudigInformatieObjectCanonicalFactory.create( latest_version__informatieobjecttype=INFORMATIEOBJECTTYPE, lock=lock ) url = get_operation_url('enkelvoudiginformatieobject_unlock', uuid=eio.latest_version.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.lock, '')
def test_unlock_force(self): self.autorisatie.scopes = [SCOPE_DOCUMENTEN_GEFORCEERD_UNLOCK] self.autorisatie.save() eio = EnkelvoudigInformatieObjectCanonicalFactory.create( latest_version__informatieobjecttype=INFORMATIEOBJECTTYPE, lock=uuid.uuid4().hex ) url = get_operation_url('enkelvoudiginformatieobject_unlock', uuid=eio.latest_version.uuid) response = self.client.post(url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, response.data) eio.refresh_from_db() self.assertEqual(eio.lock, '')
def test_delete_document_cascades_properly(self): """ Deleting a EnkelvoudigInformatieObject causes all related objects to be deleted as well. """ informatieobject = EnkelvoudigInformatieObjectCanonicalFactory.create( latest_version__informatieobjecttype=INFORMATIEOBJECTTYPE) GebruiksrechtenFactory.create(informatieobject=informatieobject) informatieobject_delete_url = get_operation_url( 'enkelvoudiginformatieobject_delete', uuid=informatieobject.latest_version.uuid) response = self.client.delete(informatieobject_delete_url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, response.data) self.assertEqual(EnkelvoudigInformatieObject.objects.all().count(), 0) self.assertFalse(Gebruiksrechten.objects.all().exists())
def test_list_file(self): self.autorisatie.scopes = [SCOPE_DOCUMENTEN_ALLES_LEZEN] self.autorisatie.save() eio = EnkelvoudigInformatieObjectCanonicalFactory.create( latest_version__informatieobjecttype=INFORMATIEOBJECTTYPE ) list_url = get_operation_url('enkelvoudiginformatieobject_list') response = self.client.get(list_url) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.data['results'] download_url = urlparse(data[0]['inhoud']) self.assertEqual( download_url.path, get_operation_url('enkelvoudiginformatieobject_download', uuid=eio.latest_version.uuid) )
def test_lock_create_new_version(self): """test that locking file creates the new version of document """ canonical = EnkelvoudigInformatieObjectCanonicalFactory.create() eio = canonical.latest_version assert eio.versie == 1 assert canonical.enkelvoudiginformatieobject_set.count() == 1 url = get_operation_url("enkelvoudiginformatieobject_lock", uuid=eio.uuid) response = self.client.post(url) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) canonical.refresh_from_db() eio_new = canonical.latest_version self.assertEqual(canonical.enkelvoudiginformatieobject_set.count(), 2) self.assertEqual(eio_new.versie, 2) self.assertEqual(eio.inhoud, eio_new.inhoud) self.assertNotEqual(eio.pk, eio_new.pk)