Files
dvc/tests/unit/remote/test_gs.py
T
Alexander Schepanovski d80293c44d dvc: path info refactoring
Replaced Path* dataclasses with PathInfo/URLInfo/CloudURLInfo, which
know how parse, serialize, stringify and join themselves. They also
provide useful accessors like part of an url or pathlib.Path like
.parent or .name.

Along the way two families of bugs where fixed and should never occur in
the future:
- paths not matched as strings anymore, e.g. using str.startswith()
- Output.path is eliminated as ambiguous

Both families might had caused undefined surprising behavior when local
and remote paths clash.
2019-06-11 19:19:17 +07:00

39 lines
1.2 KiB
Python

import mock
from unittest import TestCase
from dvc.remote.gs import RemoteGS
class TestRemoteGS(TestCase):
BUCKET = "bucket"
PREFIX = "prefix"
URL = "gs://{}/{}".format(BUCKET, PREFIX)
CREDENTIALPATH = "/path/to/gcp_credentials.json"
PROJECT = "PROJECT"
CONFIG = {
"projectname": PROJECT,
"url": URL,
"credentialpath": CREDENTIALPATH,
}
def test_init(self):
remote = RemoteGS(None, self.CONFIG)
self.assertEqual(remote.path_info, self.URL)
self.assertEqual(remote.projectname, self.PROJECT)
self.assertEqual(remote.credentialpath, self.CREDENTIALPATH)
@mock.patch("google.cloud.storage.Client.from_service_account_json")
def test_gs(self, mock_client):
remote = RemoteGS(None, self.CONFIG)
self.assertTrue(remote.credentialpath)
remote.gs()
mock_client.assert_called_once_with(self.CREDENTIALPATH)
@mock.patch("google.cloud.storage.Client")
def test_gs_no_credspath(self, mock_client):
config = self.CONFIG.copy()
del config["credentialpath"]
remote = RemoteGS(None, config)
remote.gs()
mock_client.assert_called_with(self.PROJECT)