From ead3a2222175a21f5feb18ff059fcb4678495796 Mon Sep 17 00:00:00 2001 From: testinnplayin Date: Wed, 26 Aug 2020 17:25:43 +0200 Subject: [PATCH] feat(googlesheets2): first pass at passing token 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 --- tests/google_sheets_2/test_google_sheets_2.py | 20 ++++++++++++++++--- .../google_sheets_2_connector.py | 9 +++++++-- toucan_connectors/toucan_connector.py | 5 ++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/google_sheets_2/test_google_sheets_2.py b/tests/google_sheets_2/test_google_sheets_2.py index 2399a3765..58d2f002f 100644 --- a/tests/google_sheets_2/test_google_sheets_2.py +++ b/tests/google_sheets_2/test_google_sheets_2.py @@ -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 @@ -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) diff --git a/toucan_connectors/google_sheets_2/google_sheets_2_connector.py b/toucan_connectors/google_sheets_2/google_sheets_2_connector.py index 8a9a055f2..b7faa3049 100644 --- a/toucan_connectors/google_sheets_2/google_sheets_2_connector.py +++ b/toucan_connectors/google_sheets_2/google_sheets_2_connector.py @@ -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 @@ -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 diff --git a/toucan_connectors/toucan_connector.py b/toucan_connectors/toucan_connector.py index 25ebd12cc..0990f0bb5 100644 --- a/toucan_connectors/toucan_connector.py +++ b/toucan_connectors/toucan_connector.py @@ -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)