def test_delete_inactive_fails(self, test_client): self.workspace.deactivate() db.session.commit() res = test_client.delete(self.url(self.first_object)) assert res.status_code == 403 assert not was_deleted(self.first_object) assert self.model.query.count() == OBJECT_COUNT
def test_delete_from_other_workspace_fails(self, test_client, second_workspace): res = test_client.delete(self.url(self.first_object, workspace=second_workspace)) assert res.status_code == 404 # No content assert not was_deleted(self.first_object) assert self.model.query.count() == OBJECT_COUNT
def test_delete_readonly_fails(self, test_client, session): self.workspace.readonly = True session.commit() res = test_client.delete(self.url(self.first_object)) assert res.status_code == 403 # No content assert not was_deleted(self.first_object) assert self.model.query.count() == OBJECT_COUNT
def test_delete_from_other_workspace_fails(self, test_client): all_objs, all_objs_id = self.get_all_objs_and_ids() data = {"ids": all_objs_id + [10000000]} res = test_client.delete(self.url(), data=data) assert res.status_code == 204 assert all([was_deleted(obj) for obj in all_objs]) assert res.json['deleted'] == len(all_objs) assert self.model.query.count() == 0
def test_delete_inactive_fails(self, test_client): self.workspace.deactivate() db.session.commit() all_objs, all_objs_id = self.get_all_objs_and_ids() data = {"ids": all_objs_id} res = test_client.delete(self.url(), data=data) assert res.status_code == 403 # No content assert not any([was_deleted(obj) for obj in all_objs]) assert self.model.query.count() == OBJECT_COUNT
def test_bulk_delete(self, test_client): all_objs = self.model.query.all() all_objs_id = [ obj.__getattribute__(self.view_class.lookup_field) for obj in all_objs ] ignored_obj = all_objs[-1] all_objs, all_objs_id = all_objs[:-1], all_objs_id[:-1] res = test_client.delete(self.url(), data={}) assert res.status_code == 400 data = {"ids": all_objs_id} res = test_client.delete(self.url(), data=data) assert res.status_code == 200 assert all([was_deleted(obj) for obj in all_objs]) assert res.json['deleted'] == len(all_objs) assert not was_deleted(ignored_obj) assert self.model.query.count() == 1
def test_bulk_delete_wrong_content_type(self, test_client): all_objs = self.model.query.all() all_objs_id = [ obj.__getattribute__(self.view_class.lookup_field) for obj in all_objs ] count = self.model.query.count() request_data = {'ids': all_objs_id} headers = [('content-type', 'text/xml')] res = test_client.delete(self.url(), data=request_data, headers=headers) assert res.status_code == 400 assert self.model.query.count() == count assert all([not was_deleted(obj) for obj in all_objs])
def test_delete(self, test_client, logged_user): res = test_client.delete(self.url(self.first_object)) assert res.status_code == 204 # No content assert was_deleted(self.first_object) assert self.model.query.count() == OBJECT_COUNT - 1
def test_delete_host_from_other_workspace_fails(self, test_client, second_workspace): host = self.workspace.hosts[0] res = test_client.delete(self.url(host, workspace=second_workspace)) assert res.status_code == 404 # No content assert not was_deleted(host)
def test_delete_a_host(self, test_client): host = self.workspace.hosts[0] res = test_client.delete(self.url(host)) assert res.status_code == 204 # No content assert was_deleted(host)
def test_delete(self, test_client): res = test_client.delete(self.url(self.first_object)) assert res.status_code == 204 # No content assert was_deleted(self.first_object) assert self.model.query.count() == OBJECT_COUNT - 1