Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure b2sdk.v2 emits v2 BucketIdNotFound exc #494

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion b2sdk/v2/b2http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Overridden to retain old-style BadRequest exception in case of a bad bucket id
class B2Http(v3.B2Http):
@classmethod
def _translate_error(cls, fcn, post_params=None):
def _translate_errors(cls, fcn, post_params=None):
try:
return super()._translate_errors(fcn, post_params)
except v3BucketIdNotFound as e:
Expand Down
1 change: 1 addition & 0 deletions changelog.d/437.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure `b2sdk.v2.b2http` emits `b2sdk.v2.BucketIdNotFound` exception instead of `b2sdk._v3.BucketIdNotFound`.
32 changes: 21 additions & 11 deletions test/unit/b2http/test_b2http.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@
from ..test_base import TestBase


class TestTranslateErrors(TestBase):
class TestTranslateErrors:
def test_ok(self):
response = MagicMock()
response.status_code = 200
actual = B2Http._translate_errors(lambda: response)
self.assertIs(response, actual)
assert response == actual

def test_partial_content(self):
response = MagicMock()
response.status_code = 206
actual = B2Http._translate_errors(lambda: response)
self.assertIs(response, actual)
assert response == actual

def test_b2_error(self):
response = MagicMock()
response.status_code = 503
response.content = b'{"status": 503, "code": "server_busy", "message": "busy"}'
with self.assertRaises(ServiceError):
with pytest.raises(ServiceError):
B2Http._translate_errors(lambda: response)

def test_broken_pipe(self):
Expand All @@ -66,7 +66,7 @@ def fcn():
)
)

with self.assertRaises(BrokenPipe):
with pytest.raises(BrokenPipe):
B2Http._translate_errors(fcn)

def test_unknown_host(self):
Expand All @@ -77,14 +77,14 @@ def fcn():
)
)

with self.assertRaises(UnknownHost):
with pytest.raises(UnknownHost):
B2Http._translate_errors(fcn)

def test_connection_error(self):
def fcn():
raise requests.ConnectionError('a message')

with self.assertRaises(B2ConnectionError):
with pytest.raises(B2ConnectionError):
B2Http._translate_errors(fcn)

def test_connection_reset(self):
Expand All @@ -94,22 +94,22 @@ class SysCallError(Exception):
def fcn():
raise SysCallError('(104, ECONNRESET)')

with self.assertRaises(ConnectionReset):
with pytest.raises(ConnectionReset):
B2Http._translate_errors(fcn)

def test_unknown_error(self):
def fcn():
raise Exception('a message')

with self.assertRaises(UnknownError):
with pytest.raises(UnknownError):
B2Http._translate_errors(fcn)

def test_too_many_requests(self):
response = MagicMock()
response.status_code = 429
response.headers = {'retry-after': 1}
response.content = b'{"status": 429, "code": "Too Many requests", "message": "retry after some time"}'
with self.assertRaises(TooManyRequests):
with pytest.raises(TooManyRequests):
B2Http._translate_errors(lambda: response)

def test_invalid_json(self):
Expand All @@ -129,9 +129,19 @@ def test_potential_s3_endpoint_passed_as_realm(self):
response.content = b'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
response.url = 'https://s3.us-west-000.backblazeb2.com'

with self.assertRaises(PotentialS3EndpointPassedAsRealm):
with pytest.raises(PotentialS3EndpointPassedAsRealm):
B2Http._translate_errors(lambda: response)

@pytest.mark.apiver(to_ver=2)
def test_bucket_id_not_found(self):
from b2sdk.v2.exception import BucketIdNotFound, v3BucketIdNotFound

def fcn():
raise v3BucketIdNotFound('bucket_id')

with pytest.raises(BucketIdNotFound):
B2Http._translate_errors(fcn)


def test_b2_error__nginx_html():
"""
Expand Down
Loading