mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-12-03 15:28:28 +01:00
gdrive: fix multi-remote workflow, cont. cleanup (#3686)
* remote, minor: fix parameter method name for consistency * gdrive: cleanup, fix workflow with multiple gdrive remotes * config: resolve gdrive cred file parth, typo fix * grdive: address deepsource warning * gdrive: fix tests after simplifying auth flow * gdrive: address PR review, use backticks where appropriate Co-Authored-By: Jorge Orpinel <[email protected]> * gdrive: exception text improvements Co-Authored-By: Jorge Orpinel <[email protected]> * gdrive: fix exception message Co-Authored-By: Jorge Orpinel <[email protected]> * gdrive: fix root not found exception message Co-Authored-By: Jorge Orpinel <[email protected]> * gdrive: minor warnings/exceptions text improvement * gdrive: add tests for the gdrive_user_credentials_file relative path * gdrive: address review, slightly change text * gdrive: comments -> docstrings, addressing PR review Co-authored-by: Jorge Orpinel <[email protected]>
This commit is contained in:
co-authored by
Jorge Orpinel
parent
40c6b567e3
commit
8aefbac223
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
import posixpath
|
||||
|
||||
import configobj
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.main import main
|
||||
from dvc.remote import GDriveRemote
|
||||
from dvc.repo import Repo
|
||||
|
||||
|
||||
def test_relative_user_credentials_file_config_setting(tmp_dir, dvc):
|
||||
# CI sets it to test GDrive, here we want to test the work with file system
|
||||
# based, regular credentials
|
||||
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
||||
del os.environ[GDriveRemote.GDRIVE_CREDENTIALS_DATA]
|
||||
|
||||
credentials = os.path.join("secrets", "credentials.json")
|
||||
|
||||
# GDriveRemote.credentials_location helper checks for file existence,
|
||||
# create the file
|
||||
tmp_dir.gen(credentials, "{'token': 'test'}")
|
||||
|
||||
remote_name = "gdrive"
|
||||
assert (
|
||||
main(["remote", "add", "-d", remote_name, "gdrive://root/test"]) == 0
|
||||
)
|
||||
assert (
|
||||
main(
|
||||
[
|
||||
"remote",
|
||||
"modify",
|
||||
remote_name,
|
||||
"gdrive_user_credentials_file",
|
||||
credentials,
|
||||
]
|
||||
)
|
||||
== 0
|
||||
)
|
||||
|
||||
# We need to load repo again to test updates to the config
|
||||
str_path = fspath(tmp_dir)
|
||||
repo = Repo(str_path)
|
||||
|
||||
# Check that in config we got the path relative to the config file itself
|
||||
# Also, we store posix path even on Windows
|
||||
config = configobj.ConfigObj(repo.config.files["repo"])
|
||||
assert config['remote "{}"'.format(remote_name)][
|
||||
"gdrive_user_credentials_file"
|
||||
] == posixpath.join("..", "secrets", "credentials.json")
|
||||
|
||||
# Check that in the remote itself we got an absolute path
|
||||
remote = repo.cloud.get_remote(remote_name)
|
||||
assert os.path.normpath(remote.credentials_location) == os.path.join(
|
||||
str_path, credentials
|
||||
)
|
||||
@@ -1,11 +1,7 @@
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from dvc.remote.gdrive import (
|
||||
GDriveRemote,
|
||||
GDriveAccessTokenRefreshError,
|
||||
GDriveMissedCredentialKeyError,
|
||||
)
|
||||
from dvc.remote.gdrive import GDriveRemote, GDriveAuthError
|
||||
|
||||
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
|
||||
|
||||
@@ -28,7 +24,7 @@ class TestRemoteGDrive(object):
|
||||
os.environ[
|
||||
GDriveRemote.GDRIVE_CREDENTIALS_DATA
|
||||
] = USER_CREDS_TOKEN_REFRESH_ERROR
|
||||
with pytest.raises(GDriveAccessTokenRefreshError):
|
||||
with pytest.raises(GDriveAuthError):
|
||||
remote._drive
|
||||
|
||||
os.environ[GDriveRemote.GDRIVE_CREDENTIALS_DATA] = ""
|
||||
@@ -36,5 +32,5 @@ class TestRemoteGDrive(object):
|
||||
os.environ[
|
||||
GDriveRemote.GDRIVE_CREDENTIALS_DATA
|
||||
] = USER_CREDS_MISSED_KEY_ERROR
|
||||
with pytest.raises(GDriveMissedCredentialKeyError):
|
||||
with pytest.raises(GDriveAuthError):
|
||||
remote._drive
|
||||
|
||||
Reference in New Issue
Block a user