Skip to content

Commit

Permalink
Merge d3601a0 into f51dbeb
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravsrijan authored May 23, 2019
2 parents f51dbeb + d3601a0 commit d060d5d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion stripe/api_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def interpret_response(self, rbody, rcode, rheaders):
rcode,
rheaders,
)
if not (200 <= rcode < 300):
if not 200 <= rcode < 300:
self.handle_error_response(rbody, rcode, resp.data, rheaders)

return resp
15 changes: 6 additions & 9 deletions stripe/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ def _handle_request_error(self, e):
err = "%s: %s" % (type(e).__name__, str(e))
should_retry = False
# Retry only timeout and connect errors; similar to urllib3 Retry
elif isinstance(e, requests.exceptions.Timeout) or isinstance(
e, requests.exceptions.ConnectionError
elif isinstance(
e,
(requests.exceptions.Timeout, requests.exceptions.ConnectionError),
):
msg = (
"Unexpected error communicating with Stripe. "
Expand Down Expand Up @@ -411,8 +412,8 @@ def __init__(self, verify_ssl_certs=True, proxy=None):
if self._proxy:
# now that we have the parser, get the proxy url pieces
proxy = self._proxy
for scheme in proxy:
proxy[scheme] = urlparse(proxy[scheme])
for scheme, value in six.iteritems(proxy):
proxy[scheme] = urlparse(value)

def parse_headers(self, data):
if "\r\n" not in data:
Expand Down Expand Up @@ -514,11 +515,7 @@ def _get_proxy(self, url):
proxy = self._proxy
scheme = url.split(":")[0] if url else None
if scheme:
if scheme in proxy:
return proxy[scheme]
scheme = scheme[0:-1]
if scheme in proxy:
return proxy[scheme]
return proxy.get(scheme, proxy.get(scheme[0:-1]))
return None

def close(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def check_call(mock, method, url, post_data, headers):
mock.Request.assert_called_with(url, post_data, headers)

if self.client._proxy:
assert type(self.client._proxy) is dict
assert isinstance(self.client._proxy, dict)
mock.ProxyHandler.assert_called_with(self.client._proxy)
mock.build_opener.open.assert_called_with(self.request_object)
assert not mock.urlopen.called
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def work():
stripe.Balance.retrieve()
stripe.Balance.retrieve()

threads = [Thread(target=work) for i in range(10)]
threads = [Thread(target=work) for _ in range(10)]
for t in threads:
t.start()
for t in threads:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_stripe_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

class TestStripeResponse(object):
def test_idempotency_key(self):
response, headers, body, code = self.mock_stripe_response()
response, headers, _, _ = self.mock_stripe_response()
assert response.idempotency_key == headers["idempotency-key"]

def test_request_id(self):
response, headers, body, code = self.mock_stripe_response()
response, headers, _, _ = self.mock_stripe_response()
assert response.request_id == headers["request-id"]

def test_code(self):
response, headers, body, code = self.mock_stripe_response()
response, _, _, code = self.mock_stripe_response()
assert response.code == code

def test_headers(self):
response, headers, body, code = self.mock_stripe_response()
response, headers, _, _ = self.mock_stripe_response()
assert response.headers == headers

def test_body(self):
response, headers, body, code = self.mock_stripe_response()
response, _, body, _ = self.mock_stripe_response()
assert response.body == body

def test_data(self):
response, headers, body, code = self.mock_stripe_response()
response, _, body, _ = self.mock_stripe_response()
assert response.data == json.loads(body)

@staticmethod
Expand Down
10 changes: 5 additions & 5 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ def test_convert_to_stripe_object_and_back(self):
}

obj = util.convert_to_stripe_object(resp)
assert type(obj) == stripe.Balance
assert isinstance(obj, stripe.Balance)
assert type(obj.available) == list
assert type(obj.available[0]) == stripe.stripe_object.StripeObject
assert isinstance(obj.available[0], stripe.stripe_object.StripeObject)

d = util.convert_to_dict(obj)
assert type(d) == dict
assert type(d["available"]) == list
assert type(d["available"][0]) == dict
assert isinstance(d, dict)
assert isinstance(d["available"], list)
assert isinstance(d["available"][0], dict)

assert d == resp

0 comments on commit d060d5d

Please sign in to comment.