|
| 1 | +import os |
| 2 | +import posixpath |
| 3 | + |
| 4 | +import configobj |
| 5 | + |
| 6 | +from dvc.compat import fspath |
| 7 | +from dvc.main import main |
| 8 | +from dvc.remote import GDriveRemote |
| 9 | +from dvc.repo import Repo |
| 10 | + |
| 11 | + |
| 12 | +def test_relative_user_credentials_file_config_setting(tmp_dir, dvc): |
| 13 | + # CI sets it to test GDrive, here we want to test the work with file system |
| 14 | + # based, regular credentials |
| 15 | + if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA): |
| 16 | + del os.environ[GDriveRemote.GDRIVE_CREDENTIALS_DATA] |
| 17 | + |
| 18 | + credentials = os.path.join("secrets", "credentials.json") |
| 19 | + |
| 20 | + # GDriveRemote.credentials_location helper checks for file existence, |
| 21 | + # create the file |
| 22 | + tmp_dir.gen(credentials, "{'token': 'test'}") |
| 23 | + |
| 24 | + remote_name = "gdrive" |
| 25 | + assert ( |
| 26 | + main(["remote", "add", "-d", remote_name, "gdrive://root/test"]) == 0 |
| 27 | + ) |
| 28 | + assert ( |
| 29 | + main( |
| 30 | + [ |
| 31 | + "remote", |
| 32 | + "modify", |
| 33 | + remote_name, |
| 34 | + "gdrive_user_credentials_file", |
| 35 | + credentials, |
| 36 | + ] |
| 37 | + ) |
| 38 | + == 0 |
| 39 | + ) |
| 40 | + |
| 41 | + # We need to load repo again to test updates to the config |
| 42 | + str_path = fspath(tmp_dir) |
| 43 | + repo = Repo(str_path) |
| 44 | + |
| 45 | + # Check that in config we got the path relative to the config file itself |
| 46 | + # Also, we store posix path even on Windows |
| 47 | + config = configobj.ConfigObj(repo.config.files["repo"]) |
| 48 | + assert config['remote "{}"'.format(remote_name)][ |
| 49 | + "gdrive_user_credentials_file" |
| 50 | + ] == posixpath.join("..", "secrets", "credentials.json") |
| 51 | + |
| 52 | + # Check that in the remote itself we got an absolute path |
| 53 | + remote = repo.cloud.get_remote(remote_name) |
| 54 | + assert os.path.normpath(remote.credentials_location) == os.path.join( |
| 55 | + str_path, credentials |
| 56 | + ) |
0 commit comments