-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: can instantiate connectors without callbacks/secrets-keeper (TCTC-10081) #1894
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok pour moi 👍
def _call_retrieve_token(self) -> str: | ||
"""Retrieve the access token for Google Sheets | ||
|
||
Raise an GoogleSheetsInvalidConfiguration if something missing to retrieve the token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pas compris cette phrase 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx
name="test_connector", | ||
auth_id="test_auth_id", | ||
) | ||
assert gsheet_connector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make an assertion on the fields here ? For example on the token callback ?
assert gsheet_connector | ||
|
||
|
||
def test_raise_when_trying_to_retrieve_token_if_callable_missing(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_raise_when_trying_to_retrieve_token_if_callable_missing(): | |
def test_raises_when_trying_to_retrieve_token_if_callable_missing(): |
@@ -234,3 +246,20 @@ def test_get_refresh_token(mocker, oauth2_connector): | |||
mocked_load.return_value = {"refresh_token": "bla"} | |||
token = oauth2_connector.get_refresh_token() | |||
assert token == "bla" | |||
|
|||
|
|||
def test_raise_error_if_secret_keeper_not_set(oauth2_connector_without_secret_keeper: OAuth2Connector): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_raise_error_if_secret_keeper_not_set(oauth2_connector_without_secret_keeper: OAuth2Connector): | |
def test_raises_exception_if_secret_keeper_not_set(oauth2_connector_without_secret_keeper: OAuth2Connector): |
def __init__(self, retrieve_token: Callable[[str, str], str] | None = None, *args, **kwargs): | ||
super().__init__(**kwargs) | ||
self._retrieve_token = retrieve_token # Could be async |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think __init__
should be overloaded on models.. could you please remove it ?
"""Retrieve the access token for Google Sheets | ||
|
||
Raise an GoogleSheetsInvalidConfiguration if retrieve_token callback is not set | ||
Raise an GoogleSheetsRetrieveTokenError if an error is encountered while retrieving the token | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Retrieve the access token for Google Sheets | |
Raise an GoogleSheetsInvalidConfiguration if retrieve_token callback is not set | |
Raise an GoogleSheetsRetrieveTokenError if an error is encountered while retrieving the token | |
""" | |
"""Retrieves the access token for Google Sheets | |
Raises a GoogleSheetsInvalidConfiguration if retrieve_token callback is not set | |
Raises a GoogleSheetsRetrieveTokenError if an error is encountered while retrieving the token | |
""" |
if self.secrets_keeper is None: | ||
raise ValueError("Secret Keeper not initialized.") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please make a method for that ? + Add a custom exception ?
def _check_secret_keeper_exists(self) -> None: | ||
if self.secrets_keeper is None: | ||
raise SecretKeeperMissingError("Secret keeper is not set on oauth2 connector.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _check_secret_keeper_exists(self) -> None: | |
if self.secrets_keeper is None: | |
raise SecretKeeperMissingError("Secret keeper is not set on oauth2 connector.") | |
def _secrets_keeper(self) -> SecretsKeeper: | |
if self.secrets_keeper is None: | |
raise SecretKeeperMissingError("Secret keeper is not set on oauth2 connector.") | |
return self.secrets_keeper |
It'd allow you to do self._secrets_keeper().something
everywhere in the code
No description provided.