Skip to content

Commit

Permalink
feat(googlesheets2): first pass at passing token
Browse files Browse the repository at this point in the history
put in conditional to prevent bug

replaced specific variable to kwargs

Fixed function signature inspection

- Now works for 3.6 and 3.8
- Removed version checker function from test helpers to common

added test

added test for codecov
  • Loading branch information
testinnplayin committed Sep 1, 2020
1 parent 4203b86 commit ead3a22
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
20 changes: 17 additions & 3 deletions tests/google_sheets_2/test_google_sheets_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@fixture
def con():
return GoogleSheets2Connector(name='test_name', access_token='qweqwe-1111-1111-1111-qweqweqwe')
return GoogleSheets2Connector(name='test_name')


@fixture
Expand All @@ -21,5 +21,19 @@ def ds():
)


def test_retrieve_data():
pass
def test__set_secrets(mocker, con):
"""It should set secrets on the connector."""
spy = mocker.spy(GoogleSheets2Connector, 'set_secrets')
fake_secrets = {
'access_token': 'myaccesstoken',
'refresh_token': 'myrefreshtoken',
}
con.set_secrets(fake_secrets)

assert con.secrets == fake_secrets
spy.assert_called_once_with(con, fake_secrets)


def test_retrieve_data(con, ds):
"""It should just work for now."""
con._retrieve_data(ds)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Google Sheets connector with oauth-manager setup."""

# This will replace the old Google Sheets connector that works with the Bearer API
from typing import Optional
from typing import Dict, Optional

import pandas as pd
from pydantic import Field
Expand All @@ -28,7 +28,12 @@ class GoogleSheets2Connector(ToucanConnector):
data_source_model: GoogleSheets2DataSource

auth_flow = 'oauth2'
access_token: str

secrets: Optional[Dict[str, str]]

def set_secrets(self, secrets: Dict[str, str]):
"""Set the secrets from inside the main service."""
self.secrets = secrets

def _retrieve_data(self, data_source: GoogleSheets2DataSource) -> pd.DataFrame:
pass
5 changes: 4 additions & 1 deletion toucan_connectors/toucan_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,16 @@ def _retrieve_data(self, data_source: ToucanDataSource):

@decorate_func_with_retry
def get_df(
self, data_source: ToucanDataSource, permissions: Optional[dict] = None
self,
data_source: ToucanDataSource,
permissions: Optional[dict] = None,
) -> pd.DataFrame:
"""
Method to retrieve the data as a pandas dataframe
filtered by permissions
"""
res = self._retrieve_data(data_source)

if permissions is not None:
permissions_query = PandasConditionTranslator.translate(permissions)
permissions_query = apply_query_parameters(permissions_query, data_source.parameters)
Expand Down

0 comments on commit ead3a22

Please sign in to comment.