Files
dvc/tests/unit/remote/test_http.py
T
Peter Rowlands (변기호) a0c229cf9b remote: continue remote/cache/tree refactoring (#4041)
* remote: move constants into trees

* remote: replace Remote() Cache() helper functions

* output: update for remote changes

* cache/data_cloud: update for remote changes

* dependency: update for remote changes

* stage: update for remote changes

* remote: move remaining non-index methods into tree

* tests: update remote unit tests

* remote: LocalCache needs to lock remote index, not cache index

* fix bugs from moved PARAM_CHECKSUM/PARAM_RELPATH

* tests: repo tree open needs state context

* remote: make Remote.gc a class method

* operates on obj.tree, so that GC can be done with both remote and
  cache instances

* bug fixes

* tests: update test_data_cloud

* bug fixes

* tests: update func tests
2020-06-15 16:22:55 +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 HTTPRemoteTree
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}
tree = HTTPRemoteTree(dvc, config)
with pytest.raises(HTTPError):
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": "",
}
tree = HTTPRemoteTree(dvc, config)
assert 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,
}
tree = HTTPRemoteTree(dvc, config)
assert tree._auth_method() == auth
assert isinstance(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,
}
tree = HTTPRemoteTree(dvc, config)
assert tree._auth_method() == auth
assert isinstance(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,
}
tree = HTTPRemoteTree(dvc, config)
assert tree._auth_method() is None
assert header in tree.headers
assert tree.headers[header] == password