def test_ckan_storage_write_resource_existent_error(options): url = options.pop("url") dialect = CkanDialect(**options) storage = CkanStorage(url, dialect=dialect) resource = Resource(path="data/table.csv") storage.write_resource(resource, force=True) with pytest.raises(FrictionlessException) as excinfo: storage.write_resource(resource) error = excinfo.value.error assert error.code == "storage-error" assert error.note.count("already exists") # Cleanup storage storage.delete_package(list(storage))
class TestDelete: def setup_method(self): self.resource_id = "79843e49-7974-411c-8eb5-fb2d1111d707" self.base_url = "https://demo.ckan.org" self.storage = CkanStorage(base_url=self.base_url) self.storage._CkanStorage__bucket_cache = [self.resource_id] _mock_json_call( f"{self.base_url}/api/3/action/datastore_delete", "data/ckan_mock_responses/doesnt_matter.json", method=responses.POST, ) @responses.activate def test_delete_resource_exists(self): self.storage.delete_package([self.resource_id]) assert responses.assert_call_count( f"{self.base_url}/api/3/action/datastore_delete", 1) @responses.activate def test_delete_package_exists(self): with pytest.raises(exceptions.FrictionlessException) as excinfo: self.storage.delete_package(["bad-id"]) error = excinfo.value.error assert error.code == "storage-error" assert error.note.count('Table "bad-id" does not exist') @responses.activate def test_delete_resource_does_not_exist(self): self.storage.delete_resource(self.resource_id) assert responses.assert_call_count( f"{self.base_url}/api/3/action/datastore_delete", 1) @responses.activate def test_delete_package_does_not_exist(self): with pytest.raises(exceptions.FrictionlessException) as excinfo: self.storage.delete_resource("bad-id") error = excinfo.value.error assert error.code == "storage-error" assert error.note.count('Table "bad-id" does not exist')