def test_update_in_hdx(self, configuration, post_update): resource = Resource(configuration) resource['id'] = 'NOTEXIST' with pytest.raises(HDXError): resource.update_in_hdx() resource['name'] = 'LALA' with pytest.raises(HDXError): resource.update_in_hdx() resource = Resource.read_from_hdx(configuration, 'TEST1') assert resource['id'] == 'de6549d8-268b-4dfe-adaf-a4ae5c8510d5' assert resource['format'] == 'XLSX' resource['format'] = 'CSV' resource['id'] = 'TEST1' resource['name'] = 'MyResource1' resource.update_in_hdx() assert resource['id'] == 'TEST1' assert resource['format'] == 'CSV' resource['id'] = 'NOTEXIST' with pytest.raises(HDXError): resource.update_in_hdx() del resource['id'] with pytest.raises(HDXError): resource.update_in_hdx() resource_data = copy.deepcopy(TestResource.resource_data) resource_data['name'] = 'MyResource1' resource_data['id'] = 'TEST1' resource = Resource(configuration, resource_data) resource.create_in_hdx() assert resource['id'] == 'TEST1' assert resource['format'] == 'xlsx'
def test_patch(self, configuration, post_patch): resource = Resource() resource['id'] = '74b74ae1-df0c-4716-829f-4f939a046811' resource.update_in_hdx(operation='patch', batch_mode='KEEP_OLD', skip_validation=True) assert resource['id'] == 'de6549d8-268b-4dfe-adaf-a4ae5c8510d5'
def test_update_in_hdx(self, configuration, post_update): resource = Resource() resource['id'] = 'NOTEXIST' with pytest.raises(HDXError): resource.update_in_hdx() resource['name'] = 'LALA' with pytest.raises(HDXError): resource.update_in_hdx() resource = Resource.read_from_hdx('74b74ae1-df0c-4716-829f-4f939a046811') assert resource['id'] == 'de6549d8-268b-4dfe-adaf-a4ae5c8510d5' assert resource.get_file_type() == 'csv' resource.set_file_type('XLSX') resource['id'] = '74b74ae1-df0c-4716-829f-4f939a046811' resource['name'] = 'MyResource1' resource.update_in_hdx() assert resource['id'] == '74b74ae1-df0c-4716-829f-4f939a046811' assert resource['format'] == 'xlsx' assert resource.get_file_type() == 'xlsx' assert resource['url_type'] == 'api' assert resource['resource_type'] == 'api' assert resource[ 'url'] == 'https://raw.githubusercontent.com/OCHA-DAP/hdx-python-api/master/tests/fixtures/test_data.csv' assert resource['state'] == 'active' filetoupload = join('tests', 'fixtures', 'test_data.csv') resource.set_file_to_upload(filetoupload) resource.update_in_hdx() assert resource['url_type'] == 'upload' assert resource['resource_type'] == 'file.upload' assert resource[ 'url'] == 'http://test-data.humdata.org/dataset/6f36a41c-f126-4b18-aaaf-6c2ddfbc5d4d/resource/de6549d8-268b-4dfe-adaf-a4ae5c8510d5/download/test_data.csv' assert resource['state'] == 'active' resource['id'] = 'NOTEXIST' with pytest.raises(HDXError): resource.update_in_hdx() del resource['id'] with pytest.raises(HDXError): resource.update_in_hdx() resource.data = dict() with pytest.raises(HDXError): resource.update_in_hdx() resource_data = copy.deepcopy(TestResource.resource_data) resource_data['name'] = 'MyResource1' resource_data['id'] = '74b74ae1-df0c-4716-829f-4f939a046811' resource = Resource(resource_data) resource.create_in_hdx() assert resource['id'] == '74b74ae1-df0c-4716-829f-4f939a046811' assert resource.get_file_type() == 'xlsx' assert resource['state'] == 'active'
def test_update_in_hdx(self, configuration, post_update): resource = Resource() resource['id'] = 'NOTEXIST' with pytest.raises(HDXError): resource.update_in_hdx() resource['name'] = 'LALA' with pytest.raises(HDXError): resource.update_in_hdx() resource = Resource.read_from_hdx('74b74ae1-df0c-4716-829f-4f939a046811') assert resource['id'] == 'de6549d8-268b-4dfe-adaf-a4ae5c8510d5' assert resource.get_file_type() == 'csv' resource.set_file_type('XLSX') resource['id'] = '74b74ae1-df0c-4716-829f-4f939a046811' resource['name'] = 'MyResource1' resource.update_in_hdx() assert resource['id'] == '74b74ae1-df0c-4716-829f-4f939a046811' assert resource['format'] == 'xlsx' assert resource.get_file_type() == 'xlsx' assert resource['url_type'] == 'api' assert resource['resource_type'] == 'api' assert resource[ 'url'] == 'https://raw.githubusercontent.com/OCHA-DAP/hdx-python-api/master/tests/fixtures/test_data.csv' filetoupload = join('tests', 'fixtures', 'test_data.csv') resource.set_file_to_upload(filetoupload) resource.update_in_hdx() assert resource['url_type'] == 'upload' assert resource['resource_type'] == 'file.upload' assert resource[ 'url'] == 'http://test-data.humdata.org/dataset/6f36a41c-f126-4b18-aaaf-6c2ddfbc5d4d/resource/de6549d8-268b-4dfe-adaf-a4ae5c8510d5/download/test_data.csv' resource['id'] = 'NOTEXIST' with pytest.raises(HDXError): resource.update_in_hdx() del resource['id'] with pytest.raises(HDXError): resource.update_in_hdx() resource.data = dict() with pytest.raises(HDXError): resource.update_in_hdx() resource_data = copy.deepcopy(TestResource.resource_data) resource_data['name'] = 'MyResource1' resource_data['id'] = '74b74ae1-df0c-4716-829f-4f939a046811' resource = Resource(resource_data) resource.create_in_hdx() assert resource['id'] == '74b74ae1-df0c-4716-829f-4f939a046811' assert resource.get_file_type() == 'xlsx'
def test_update_in_hdx(self, configuration, post_update): resource = Resource() resource['id'] = 'NOTEXIST' with pytest.raises(HDXError): resource.update_in_hdx() resource['name'] = 'LALA' with pytest.raises(HDXError): resource.update_in_hdx() resource = Resource.read_from_hdx('TEST1') assert resource['id'] == 'de6549d8-268b-4dfe-adaf-a4ae5c8510d5' assert resource['format'] == 'XLSX' resource['format'] = 'CSV' resource['id'] = 'TEST1' resource['name'] = 'MyResource1' resource.update_in_hdx() assert resource['id'] == 'TEST1' assert resource['format'] == 'CSV' assert resource['url_type'] == 'api' assert resource['resource_type'] == 'api' assert resource[ 'url'] == 'https://raw.githubusercontent.com/OCHA-DAP/hdx-python-api/master/tests/fixtures/test_data.csv' resource.set_file_to_upload('fixtures/test_data.csv') resource.update_in_hdx() assert resource['url_type'] == 'upload' assert resource['resource_type'] == 'file.upload' assert resource[ 'url'] == 'http://test-data.humdata.org/dataset/6f36a41c-f126-4b18-aaaf-6c2ddfbc5d4d/resource/de6549d8-268b-4dfe-adaf-a4ae5c8510d5/download/test_data.csv' resource['id'] = 'NOTEXIST' with pytest.raises(HDXError): resource.update_in_hdx() del resource['id'] with pytest.raises(HDXError): resource.update_in_hdx() resource_data = copy.deepcopy(TestResource.resource_data) resource_data['name'] = 'MyResource1' resource_data['id'] = 'TEST1' resource = Resource(resource_data) resource.create_in_hdx() assert resource['id'] == 'TEST1' assert resource['format'] == 'xlsx'