Files
dvc/tests/unit/remote/test_http.py
T
Peter Rowlands (변기호) 74bd8137ba remote: finish separating RemoteTree methods (#3946)
* remote: move upload()/download() into tree

* remote: move path_info/path_cls into tree

* remote.azure: finish moving methods into tree

* remote.gs: finish moving methods into tree

* remote.hdfs: finish moving methods to tree

* remote.http: finish moving methods into tree

* remote.oss: finish moving methods into tree

* remote.s3: finish moving methods into tree

* remote.ssh: finish moving methods into tree

* remote.gdrive: finish moving methods into tree

* tests: update remote unit tests

* tests: update func tests

* remote: use walk_files() for all remotes

* list_cache_paths() now uses tree.walk_files() for all remotes except
  local/ssh

* fix DS warnings

* bugfixes
2020-06-04 23:22:31 +03:00

89 lines
2.1 KiB
Python

import pytest
from dvc.exceptions import HTTPError
from dvc.path_info import URLInfo
from dvc.remote.http import HTTPRemote
from tests.utils.httpd import StaticFileServer
def test_download_fails_on_error_code(dvc):
with StaticFileServer() as httpd:
url = f"http://localhost:{httpd.server_port}/"
config = {"url": url}
remote = HTTPRemote(dvc, config)
with pytest.raises(HTTPError):
remote.tree._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 = HTTPRemote(dvc, config)
assert remote.tree._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 = HTTPRemote(dvc, config)
assert remote.tree._auth_method() == auth
assert isinstance(remote.tree._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 = HTTPRemote(dvc, config)
assert remote.tree._auth_method() == auth
assert isinstance(remote.tree._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 = HTTPRemote(dvc, config)
assert remote.tree._auth_method() is None
assert header in remote.tree.headers
assert remote.tree.headers[header] == password