Beispiel #1
0
def ds():
    return GoogleSheets2DataSource(
        name='test_name',
        domain='test_domain',
        sheet='Constants',
        spreadsheet_id='1SMnhnmBm-Tup3SfhS03McCf6S4pS2xqjI6CAXSSBpHU',
    )
Beispiel #2
0
def test_schema_fields_order(con, ds):
    schema_props_keys = list(
        JsonWrapper.loads(
            GoogleSheets2DataSource.schema_json())['properties'].keys())
    assert schema_props_keys[0] == 'domain'
    assert schema_props_keys[1] == 'spreadsheet_id'
    assert schema_props_keys[2] == 'sheet'
Beispiel #3
0
def test_parse_datetime(mocker, con):
    ds = GoogleSheets2DataSource(
        name='test_name',
        domain='test_domain',
        sheet='Constants',
        spreadsheet_id='1SMnhnmBm-Tup3SfhS03McCf6S4pS2xqjI6CAXSSBpHU',
        parse_dates=['a_date'],
    )
    fake_result = {
        'metadata':
        '...',
        'values': [
            ['country', 'city', 'a_date'],
            ['France', 'Paris', '2001-02-02'],
            ['England', 'London', '2010-08-09'],
        ],
    }
    mocker.patch(f'{import_path}.fetch', return_value=fake_result)
    ds = con.get_slice(ds, limit=2)
    assert ds.df['a_date'].iloc[0] == datetime.datetime(year=2001,
                                                        month=2,
                                                        day=2)
Beispiel #4
0
from .helpers import JsonFileSecretsKeeper, get_authorization_response

# Get these info from the provider
CLIENT_ID = ''
CLIENT_SECRET = ''
# ...and give this one to the provider
REDIRECT_URI = 'http://localhost:34097/'

google_sheets_conn = GoogleSheets2Connector(
    name='test',
    auth_flow_id='test',
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    redirect_uri=REDIRECT_URI,
    secrets_keeper=JsonFileSecretsKeeper(filename='secrets.json'),
)
sample_data_source_ss = GoogleSheets2DataSource(
    name='test',
    domain='test-connector',
    spreadsheet_id='1L5YraXEToFv7p0HMke7gXI4IhJotdT0q5bk_PInI1hA',
)

# The OAuth2 authorization process
authorization_response = get_authorization_response(
    google_sheets_conn.build_authorization_url(), 'localhost', 34097)
google_sheets_conn.retrieve_tokens(authorization_response)

# The actual data request
df = google_sheets_conn.get_df(data_source=sample_data_source_ss)
print(df)