Ejemplo n.º 1
0
    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'
Ejemplo n.º 2
0
    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'
Ejemplo n.º 3
0
    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'
Ejemplo n.º 4
0
    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'
Ejemplo n.º 5
0
    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'
Ejemplo n.º 6
0
    def test_create_in_hdx(self, configuration, post_create):
        resource = Resource(configuration)
        with pytest.raises(HDXError):
            resource.create_in_hdx()
        resource['id'] = 'TEST1'
        resource['name'] = 'LALA'
        with pytest.raises(HDXError):
            resource.create_in_hdx()

        resource_data = copy.deepcopy(TestResource.resource_data)
        resource = Resource(configuration, resource_data)
        resource.create_in_hdx()
        assert resource['id'] == 'de6549d8-268b-4dfe-adaf-a4ae5c8510d5'

        resource_data['name'] = 'MyResource2'
        resource = Resource(configuration, resource_data)
        with pytest.raises(HDXError):
            resource.create_in_hdx()

        resource_data['name'] = 'MyResource3'
        resource = Resource(configuration, resource_data)
        with pytest.raises(HDXError):
            resource.create_in_hdx()
Ejemplo n.º 7
0
    def test_create_in_hdx(self, configuration, post_create):
        resource = Resource(configuration)
        with pytest.raises(HDXError):
            resource.create_in_hdx()
        resource['id'] = 'TEST1'
        resource['name'] = 'LALA'
        with pytest.raises(HDXError):
            resource.create_in_hdx()

        resource_data = copy.deepcopy(TestResource.resource_data)
        resource = Resource(configuration, resource_data)
        resource.create_in_hdx()
        assert resource['id'] == 'de6549d8-268b-4dfe-adaf-a4ae5c8510d5'

        resource_data['name'] = 'MyResource2'
        resource = Resource(configuration, resource_data)
        with pytest.raises(HDXError):
            resource.create_in_hdx()

        resource_data['name'] = 'MyResource3'
        resource = Resource(configuration, resource_data)
        with pytest.raises(HDXError):
            resource.create_in_hdx()
Ejemplo n.º 8
0
    def test_create_in_hdx(self, configuration, post_create):
        resource = Resource()
        with pytest.raises(HDXError):
            resource.create_in_hdx()
        resource['id'] = 'TEST1'
        resource['name'] = 'LALA'
        with pytest.raises(HDXError):
            resource.create_in_hdx()

        resource_data = copy.deepcopy(TestResource.resource_data)
        resource = Resource(resource_data)
        resource.create_in_hdx()
        assert resource['id'] == 'de6549d8-268b-4dfe-adaf-a4ae5c8510d5'
        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_data = copy.deepcopy(TestResource.resource_data)
        resource = Resource(resource_data)
        filetoupload = join('tests', 'fixtures', 'test_data.csv')
        resource.set_file_to_upload(filetoupload)
        assert resource.get_file_to_upload() == filetoupload
        resource.create_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_data['name'] = 'MyResource2'
        resource = Resource(resource_data)
        with pytest.raises(HDXError):
            resource.create_in_hdx()

        resource_data['name'] = 'MyResource3'
        resource = Resource(resource_data)
        with pytest.raises(HDXError):
            resource.create_in_hdx()