-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Improve Google Drive auth failure error reporting #2991
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,46 @@ | ||
| import mock | ||
| from dvc.remote.gdrive import RemoteGDrive | ||
| from unittest import TestCase | ||
|
|
||
| import pytest | ||
| import os | ||
|
|
||
| @mock.patch("dvc.remote.gdrive.RemoteGDrive.init_drive") | ||
| def test_init(repo): | ||
| url = "gdrive://root/data" | ||
| gdrive = RemoteGDrive(repo, {"url": url}) | ||
| assert str(gdrive.path_info) == url | ||
| from dvc.remote.gdrive import ( | ||
| RemoteGDrive, | ||
| GDriveAccessTokenRefreshError, | ||
| GDriveMissedCredentialKeyError, | ||
| ) | ||
|
|
||
| USER_CREDS_TOKEN_REFRESH_ERROR = '{"access_token": "", "client_id": "", "client_secret": "", "refresh_token": "", "token_expiry": "", "token_uri": "https://oauth2.googleapis.com/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "", "expires_in": 3600, "scope": "https://www.googleapis.com/auth/drive.appdata https://www.googleapis.com/auth/drive", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.appdata"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": true, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}' # noqa: E501 | ||
|
|
||
| USER_CREDS_MISSED_KEY_ERROR = "{}" | ||
|
|
||
|
|
||
| class Repo(object): | ||
| tmp_dir = "" | ||
|
|
||
|
|
||
| class TestRemoteGDrive(TestCase): | ||
| CONFIG = { | ||
| "url": "gdrive://root/data", | ||
| "gdrive_client_id": "client", | ||
| "gdrive_client_secret": "secret", | ||
| } | ||
|
|
||
| def test_init(self): | ||
| remote = RemoteGDrive(Repo(), self.CONFIG) | ||
| assert str(remote.path_info) == self.CONFIG["url"] | ||
|
|
||
| def test_drive(self): | ||
| remote = RemoteGDrive(Repo(), self.CONFIG) | ||
| os.environ[ | ||
| RemoteGDrive.GDRIVE_USER_CREDENTIALS_DATA | ||
| ] = USER_CREDS_TOKEN_REFRESH_ERROR | ||
| with pytest.raises(GDriveAccessTokenRefreshError): | ||
| remote.drive | ||
|
|
||
| os.environ[RemoteGDrive.GDRIVE_USER_CREDENTIALS_DATA] = "" | ||
| remote = RemoteGDrive(Repo(), self.CONFIG) | ||
| os.environ[ | ||
| RemoteGDrive.GDRIVE_USER_CREDENTIALS_DATA | ||
| ] = USER_CREDS_MISSED_KEY_ERROR | ||
| with pytest.raises(GDriveMissedCredentialKeyError): | ||
| remote.drive |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.