Skip to content

Commit 7218ff2

Browse files
committed
remote: http: rename http error, refactor test
1 parent 72abfb0 commit 7218ff2

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

dvc/exceptions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,8 @@ def __init__(self, path, external_repo_path, external_repo_url):
350350
)
351351

352352

353-
class HTTPErrorStatusCodeException(DvcException):
353+
class HTTPError(DvcException):
354354
def __init__(self, code, reason):
355-
super(HTTPErrorStatusCodeException, self).__init__(
356-
"Server responded with error status code: '{}' and message: "
357-
"'{}'".format(code, reason)
355+
super(HTTPError, self).__init__(
356+
"HTTP error: '{} {}'".format(code, reason)
358357
)

dvc/remote/http.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
from dvc.config import Config
99
from dvc.config import ConfigError
10-
from dvc.exceptions import DvcException
11-
from dvc.exceptions import HTTPErrorStatusCodeException
10+
from dvc.exceptions import DvcException, HTTPError
1211
from dvc.progress import Tqdm
1312
from dvc.remote.base import RemoteBASE
1413
from dvc.scheme import Schemes
@@ -40,9 +39,7 @@ def __init__(self, repo, config):
4039
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
4140
response = self._request("GET", from_info.url, stream=True)
4241
if response.status_code != 200:
43-
raise HTTPErrorStatusCodeException(
44-
response.status_code, response.reason
45-
)
42+
raise HTTPError(response.status_code, response.reason)
4643
with Tqdm(
4744
total=None if no_progress_bar else self._content_length(from_info),
4845
leave=False,

tests/func/test_repro.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
from tests.func.test_data_cloud import get_ssh_url
4444
from tests.func.test_data_cloud import TEST_AWS_REPO_BUCKET
4545
from tests.func.test_data_cloud import TEST_GCP_REPO_BUCKET
46-
from tests.utils.httpd import ContentMD5Handler
47-
from tests.utils.httpd import StaticFileServer
46+
from tests.utils.httpd import StaticFileServer, ContentMD5Handler
4847

4948

5049
class TestRepro(TestDvc):

tests/unit/remote/test_http.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
try:
2+
from http.server import BaseHTTPRequestHandler
3+
except ImportError:
4+
from BaseHTTPServer import BaseHTTPRequestHandler
5+
16
import pytest
2-
from BaseHTTPServer import BaseHTTPRequestHandler
37

48
from dvc.config import ConfigError
5-
from dvc.exceptions import HTTPErrorStatusCodeException
9+
from dvc.exceptions import HTTPError
610
from dvc.path_info import URLInfo
711
from dvc.remote.http import RemoteHTTP
812
from tests.utils.httpd import StaticFileServer
@@ -19,21 +23,17 @@ def test_no_traverse_compatibility(dvc_repo):
1923
RemoteHTTP(dvc_repo, config)
2024

2125

22-
@pytest.mark.parametrize("response_code", [404, 403, 500])
23-
def test_download_fails_on_error_code(response_code, dvc_repo):
26+
def test_download_fails_on_error_code(dvc_repo):
2427
class ErrorStatusRequestHandler(BaseHTTPRequestHandler):
2528
def do_GET(self):
26-
self.send_response(response_code, message="Error message")
29+
self.send_response(404, message="Not found")
2730
self.end_headers()
2831

2932
with StaticFileServer(ErrorStatusRequestHandler) as httpd:
3033
url = "http://localhost:{}/".format(httpd.server_port)
3134
config = {"url": url}
3235

3336
remote = RemoteHTTP(dvc_repo, config)
34-
import os
3537

36-
with pytest.raises(HTTPErrorStatusCodeException):
37-
remote._download(
38-
URLInfo(os.path.join(url, "file.txt")), "file.txt"
39-
)
38+
with pytest.raises(HTTPError):
39+
remote._download(URLInfo(url) / "file.txt", "file.txt")

tests/utils/httpd.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class StaticFileServer:
4747

4848
def __init__(self, handler_class=ETagHandler):
4949
self._lock.acquire()
50-
self.response_handler = handler_class
5150
self._httpd = HTTPServer(("localhost", 0), handler_class)
5251
self._thread = None
5352

0 commit comments

Comments
 (0)