示例#1
0
def test_http_method(dvc):
    config = {
        "url": "http://example.com/",
        "path": "file.html",
    }

    fs = HTTPFileSystem(**config, method="PUT")
    assert fs.upload_method == "PUT"

    fs = HTTPFileSystem(**config, method="POST")
    assert fs.upload_method == "POST"
示例#2
0
def test_public_auth_method(dvc):
    config = {
        "url": "http://example.com/",
        "path_info": "file.html",
        "user": "",
        "password": "",
    }

    fs = HTTPFileSystem(**config)

    assert fs._auth_method(config["url"]) is None
示例#3
0
def test_content_length(mocker, headers, expected_size):
    res = requests.Response()
    res.headers.update(headers)
    res.status_code = 200

    fs = HTTPFileSystem()
    mocker.patch.object(fs, "request", return_value=res)

    url = URLInfo("https://example.org/file.txt")

    assert fs.info(url) == {"etag": None, "size": expected_size}
    assert fs._content_length(res) == expected_size
示例#4
0
def test_custom_auth_method(dvc):
    header = "Custom-Header"
    password = "******"
    config = {
        "url": "http://example.com/",
        "path_info": "file.html",
        "auth": "custom",
        "custom_auth_header": header,
        "password": password,
    }

    fs = HTTPFileSystem(**config)

    assert fs._auth_method(config["url"]) is None
    assert header in fs.headers
    assert fs.headers[header] == password
示例#5
0
文件: test_http.py 项目: pyanezs/dvc
def test_basic_auth_method(dvc):
    from requests.auth import HTTPBasicAuth

    user = "******"
    password = "******"
    auth = HTTPBasicAuth(user, password)
    config = {
        "url": "http://example.com/",
        "path_info": "file.html",
        "auth": "basic",
        "user": user,
        "password": password,
    }

    fs = HTTPFileSystem(dvc, config)

    assert fs._auth_method() == auth
    assert isinstance(fs._auth_method(), HTTPBasicAuth)
示例#6
0
def test_ssl_verify_disable(dvc):
    config = {
        "url": "http://example.com/",
        "path": "file.html",
        "ssl_verify": False,
    }

    fs = HTTPFileSystem(**config)
    assert not fs.fs_args["client_kwargs"]["connector"]._ssl
示例#7
0
def test_digest_auth_method(dvc):
    from requests.auth import HTTPDigestAuth

    user = "******"
    password = "******"
    auth = HTTPDigestAuth(user, password)
    config = {
        "url": "http://example.com/",
        "path_info": "file.html",
        "auth": "digest",
        "user": user,
        "password": password,
    }

    fs = HTTPFileSystem(**config)

    assert fs._auth_method(config["url"]) == auth
    assert isinstance(fs._auth_method(config["url"]), HTTPDigestAuth)
示例#8
0
文件: test_http.py 项目: pyanezs/dvc
def test_ssl_verify_is_enabled_by_default(dvc):
    config = {
        "url": "http://example.com/",
        "path_info": "file.html",
    }

    fs = HTTPFileSystem(dvc, config)

    assert fs._session.verify is True
示例#9
0
def test_ssl_verify_custom_cert(dvc):
    config = {
        "url": "http://example.com/",
        "path_info": "file.html",
        "ssl_verify": "/path/to/custom/cabundle.pem",
    }

    fs = HTTPFileSystem(**config)

    assert fs._session.verify == "/path/to/custom/cabundle.pem"
示例#10
0
def test_ssl_verify_disable(dvc):
    config = {
        "url": "http://example.com/",
        "path_info": "file.html",
        "ssl_verify": False,
    }

    fs = HTTPFileSystem(**config)

    assert fs._session.verify is False
示例#11
0
def test_ssl_verify_custom_cert(dvc, mocker):
    config = {
        "url": "http://example.com/",
        "path": "file.html",
        "ssl_verify": "/path/to/custom/cabundle.pem",
    }

    fs = HTTPFileSystem(**config)

    assert isinstance(fs.fs_args["client_kwargs"]["connector"]._ssl,
                      ssl.SSLContext)
示例#12
0
def test_public_auth_method(dvc):
    config = {
        "url": "http://example.com/",
        "path": "file.html",
        "user": "",
        "password": "",
    }

    fs = HTTPFileSystem(**config)

    assert "auth" not in fs.fs_args["client_kwargs"]
    assert "headers" not in fs.fs_args
示例#13
0
文件: test_http.py 项目: pyanezs/dvc
def test_exists(mocker):
    import io

    import requests

    from dvc.path_info import URLInfo

    res = requests.Response()
    # need to add `raw`, as `exists()` fallbacks to a streaming GET requests
    # on HEAD request failure.
    res.raw = io.StringIO("foo")

    fs = HTTPFileSystem(None, {})
    mocker.patch.object(fs, "request", return_value=res)

    url = URLInfo("https://example.org/file.txt")

    res.status_code = 200
    assert fs.exists(url) is True

    res.status_code = 404
    assert fs.exists(url) is False

    res.status_code = 403
    with pytest.raises(HTTPError):
        fs.exists(url)
示例#14
0
def test_basic_auth_method(dvc):
    user = "******"
    password = "******"
    config = {
        "url": "http://example.com/",
        "path": "file.html",
        "auth": "basic",
        "user": user,
        "password": password,
    }

    fs = HTTPFileSystem(**config)

    assert fs.fs_args["client_kwargs"]["auth"].login == user
    assert fs.fs_args["client_kwargs"]["auth"].password == password
示例#15
0
def test_custom_auth_method(dvc):
    header = "Custom-Header"
    password = "******"
    config = {
        "url": "http://example.com/",
        "path": "file.html",
        "auth": "custom",
        "custom_auth_header": header,
        "password": password,
    }

    fs = HTTPFileSystem(**config)

    headers = fs.fs_args["headers"]
    assert header in headers
    assert headers[header] == password
示例#16
0
def test_download_fails_on_error_code(tmp_dir, http):
    fs = HTTPFileSystem(**http.config)

    with pytest.raises(FileNotFoundError):
        fs.download_file((http / "missing.txt").fs_path,
                         (tmp_dir / "missing.txt").fs_path)
示例#17
0
def test_download_fails_on_error_code(dvc, http):
    fs = HTTPFileSystem(**http.config)

    with pytest.raises(HTTPError):
        fs._download(http / "missing.txt", "missing.txt")