def test_update_datasource(token, dataset_meta, dataset_data):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    datasources = client.list_datasources()
    primary_key = datasources['results'][0]['pk']
    datasource = client.get_datasource(primary_key)
    meta = dataset_meta
    meta['info']['from_source']['pandas_reader'] = 'changed'
    data = dataset_data[:90].to_csv()
    resp = datasource.update_meta_and_data(meta=meta, data=data)
    datasource2 = client.get_datasource(primary_key)
    meta_and_data = datasource2.get_meta_and_data()
    new_meta = meta_and_data['meta']
    new_data = meta_and_data['data']
    new_data_df = pd.read_csv(StringIO(new_data))

    assert new_meta['info']['from_source']['pandas_reader'] == 'changed'
    assert resp.status_code == 200
def test_get_meta_and_data(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    datasources = client.list_datasources()
    primary_key = datasources['results'][0]['pk']
    datasource = client.get_datasource(primary_key)
    resp = datasource.get_meta_and_data()
    print(resp.keys())
    assert 'meta' in resp
    assert 'data' in resp
def test_get_combined_tables(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    datasources = client.list_datasources()
    primary_key = datasources['results'][0]['pk']
    datasource = client.get_datasource(primary_key)
    tables = datasource.get_tables(['price', 'quality'], ['gender', 'agecat'],
                                   ['counts', 'c%', 'cbase', 'stddev'],
                                   combine=True,
                                   language='en-GB')
    assert tables.shape == (24, 7)
def test_get_table_set(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    datasources = client.list_datasources()
    primary_key = datasources['results'][0]['pk']
    datasource = client.get_datasource(primary_key)
    stubs = [['distance', 'store', 'contact'], ['reason1', 'reason2', 'dept'],
             ['price', 'numitems', 'org', 'service', 'quality', 'overall']]
    banners = [['gender', 'agecat'], ['regular', 'purchase']]
    table_set = datasource.get_table_set(stubs, banners,
                                         ['base', 'counts', 'c%', 'stddev'])
    assert len(table_set) == len(stubs) * len(banners)
def test_dataset_to_excel(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    datasources = client.list_datasources()
    primary_key = datasources['results'][0]['pk']
    datasource = client.get_datasource(primary_key)
    stubs = [['distance', 'store', 'contact'], ['reason1', 'reason2', 'dept'],
             ['price', 'numitems', 'org', 'service', 'quality', 'overall']]
    banners = [['gender', 'agecat'], ['regular', 'purchase']]
    table_set = datasource.get_table_set(stubs, banners,
                                         ['base', 'counts', 'c%', 'stddev'])
    datasource.table_set_to_excel(table_set, 'myexcel.xlsx')
    assert os.path.isfile('myexcel.xlsx')
    os.remove("myexcel.xlsx")
def test_get_datasource(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    datasources = client.list_datasources()
    primary_key = datasources['results'][0]['pk']
    resp = client.get_datasource(primary_key)
    assert isinstance(resp, Datasource)