コード例 #1
0
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
コード例 #2
0
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)
コード例 #3
0
def test_create_report_and_add_chart(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    datasource_pk = client.list_datasources()['results'][0]['pk']
    report = client.create_report('my test')
    original_length = len(report.elements)
    resp = report.add_chart(datasource_pk, ['numitems', 'org'], y='agecat')
    report2 = client.get_report(report._pk)
    report.delete()
    assert len(report2.elements) == original_length + 1
    assert 'Type' in resp
コード例 #4
0
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)
コード例 #5
0
def test_add_chart(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    reports = client.list_reports()
    datasources = client.list_datasources()
    datasource_id = datasources['results'][0]['pk']
    report = client.get_report(reports['results'][0]['pk'])
    original_length = len(report.elements)
    report.add_chart(datasource_primary_key=datasource_id,
                     x=['service', 'quality'])
    report = client.get_report(reports['results'][0]['pk'])
    assert len(report.elements) == original_length + 1
コード例 #6
0
def test_update_meta_element(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    reports = client.list_reports()
    datasources = client.list_datasources()
    datasource_id = datasources['results'][0]['pk']
    report = client.get_report(reports['results'][0]['pk'])
    meta = report.meta
    resp = report.update_meta_element('title', 'new title')
    assert resp.status_code == 200
    report = client.get_report(reports['results'][0]['pk'])
    assert report.meta['title'] == 'new title'
コード例 #7
0
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")
コード例 #8
0
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
コード例 #9
0
def test_add_multiple_charts(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    reports = client.list_reports()
    datasources = client.list_datasources()
    datasource_id = datasources['results'][0]['pk']
    report = client.get_report(reports['results'][0]['pk'])
    original_length = len(report.elements)
    report.add_charts(datasource_primary_key=datasource_id,
                      x_y_pairs=[('price', 'gender'), ('quality', '@'),
                                 ('service', '@'), ('distance', '@'),
                                 ('quality', '@'), ('quality', '@'),
                                 ('quality', '@'), ('quality', '@')],
                      user_filters=['gender', 'agecat'],
                      filter=['gender == 1'],
                      comparison_variables=['agecat'],
                      charts_per_row=3)
    report = client.get_report(report._pk)
    assert len(report.elements) == original_length + 8
コード例 #10
0
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)
コード例 #11
0
def test_list_datasources(token):
    client = Client(api_key=token, host="localhost:8030/api2", ssl=False)
    resp = client.list_datasources()
    assert 'results' in resp