mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
* remote: Optimize traverse/no_traverse behavior - estimate remote file count by fetching a single parent cache dir, then determine whether or not to use no_traverse method for checking remainder of cache entries in `cache_exists` - thread requests when traversing full remote file lists (by fetching one parent cache dir per thread) * Use arbitrary prefix length for traverse remote cache queries - default to 3 - for remotes that only support per-directory query use 2 (gdrive, hdfs) * Add unit tests for new traverse/no_traverse behavior * Fix deepsource warning * Fix review issues * fix CI * Fix review issues * obsolete no_traverse config option - remove RemoteBASE.DEFAULT_NO_TRAVERSE and replace it with RemoteBASE.CAN_TRAVERSE (True for all remotes except http) * review issues - use 'object exists' instead of 'no_traverse' * fix obsolete no_traverse test issues * fix SSHMocked func tests
89 lines
2.1 KiB
Python
89 lines
2.1 KiB
Python
import pytest
|
|
|
|
from dvc.exceptions import HTTPError
|
|
from dvc.path_info import URLInfo
|
|
from dvc.remote.http import RemoteHTTP
|
|
from tests.utils.httpd import StaticFileServer
|
|
|
|
|
|
def test_download_fails_on_error_code(dvc):
|
|
with StaticFileServer() as httpd:
|
|
url = "http://localhost:{}/".format(httpd.server_port)
|
|
config = {"url": url}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
with pytest.raises(HTTPError):
|
|
remote._download(URLInfo(url) / "missing.txt", "missing.txt")
|
|
|
|
|
|
def test_public_auth_method(dvc):
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"user": "",
|
|
"password": "",
|
|
}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
assert remote.auth_method() is None
|
|
|
|
|
|
def test_basic_auth_method(dvc):
|
|
from requests.auth import HTTPBasicAuth
|
|
|
|
user = "username"
|
|
password = "password"
|
|
auth = HTTPBasicAuth(user, password)
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"auth": "basic",
|
|
"user": user,
|
|
"password": password,
|
|
}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
assert remote.auth_method() == auth
|
|
assert isinstance(remote.auth_method(), HTTPBasicAuth)
|
|
|
|
|
|
def test_digest_auth_method(dvc):
|
|
from requests.auth import HTTPDigestAuth
|
|
|
|
user = "username"
|
|
password = "password"
|
|
auth = HTTPDigestAuth(user, password)
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"auth": "digest",
|
|
"user": user,
|
|
"password": password,
|
|
}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
assert remote.auth_method() == auth
|
|
assert isinstance(remote.auth_method(), HTTPDigestAuth)
|
|
|
|
|
|
def test_custom_auth_method(dvc):
|
|
header = "Custom-Header"
|
|
password = "password"
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"auth": "custom",
|
|
"custom_auth_header": header,
|
|
"password": password,
|
|
}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
assert remote.auth_method() is None
|
|
assert header in remote.headers
|
|
assert remote.headers[header] == password
|