mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 07:18:31 +01:00
remote: http: rename http error, refactor test
This commit is contained in:
@@ -43,8 +43,7 @@ from tests.func.test_data_cloud import _should_test_ssh
|
||||
from tests.func.test_data_cloud import get_ssh_url
|
||||
from tests.func.test_data_cloud import TEST_AWS_REPO_BUCKET
|
||||
from tests.func.test_data_cloud import TEST_GCP_REPO_BUCKET
|
||||
from tests.utils.httpd import ContentMD5Handler
|
||||
from tests.utils.httpd import StaticFileServer
|
||||
from tests.utils.httpd import StaticFileServer, ContentMD5Handler
|
||||
|
||||
|
||||
class TestRepro(TestDvc):
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
try:
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
except ImportError:
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler
|
||||
|
||||
import pytest
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler
|
||||
|
||||
from dvc.config import ConfigError
|
||||
from dvc.exceptions import HTTPErrorStatusCodeException
|
||||
from dvc.exceptions import HTTPError
|
||||
from dvc.path_info import URLInfo
|
||||
from dvc.remote.http import RemoteHTTP
|
||||
from tests.utils.httpd import StaticFileServer
|
||||
@@ -19,11 +23,10 @@ def test_no_traverse_compatibility(dvc_repo):
|
||||
RemoteHTTP(dvc_repo, config)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("response_code", [404, 403, 500])
|
||||
def test_download_fails_on_error_code(response_code, dvc_repo):
|
||||
def test_download_fails_on_error_code(dvc_repo):
|
||||
class ErrorStatusRequestHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(response_code, message="Error message")
|
||||
self.send_response(404, message="Not found")
|
||||
self.end_headers()
|
||||
|
||||
with StaticFileServer(ErrorStatusRequestHandler) as httpd:
|
||||
@@ -31,9 +34,6 @@ def test_download_fails_on_error_code(response_code, dvc_repo):
|
||||
config = {"url": url}
|
||||
|
||||
remote = RemoteHTTP(dvc_repo, config)
|
||||
import os
|
||||
|
||||
with pytest.raises(HTTPErrorStatusCodeException):
|
||||
remote._download(
|
||||
URLInfo(os.path.join(url, "file.txt")), "file.txt"
|
||||
)
|
||||
with pytest.raises(HTTPError):
|
||||
remote._download(URLInfo(url) / "file.txt", "file.txt")
|
||||
|
||||
@@ -47,7 +47,6 @@ class StaticFileServer:
|
||||
|
||||
def __init__(self, handler_class=ETagHandler):
|
||||
self._lock.acquire()
|
||||
self.response_handler = handler_class
|
||||
self._httpd = HTTPServer(("localhost", 0), handler_class)
|
||||
self._thread = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user