remote: http: rename http error, refactor test

This commit is contained in:
Paweł Redzyński
2019-11-29 15:30:55 +01:00
parent 72abfb0572
commit 7218ff202c
5 changed files with 16 additions and 22 deletions
+1 -2
View File
@@ -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):
+10 -10
View File
@@ -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")
-1
View File
@@ -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