Skip to content

Commit 7195a34

Browse files
committed
Merge branch 'issue-107'
Closes #108 Reviewed by @jontsai and @mwaldt
2 parents d0de372 + be479c7 commit 7195a34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+8043
-38
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/tests/cassettes/*.yaml binary

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ virtualenv
2626
.virtualenv
2727
.idea
2828
.coverage
29+
.env-override

.travis.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
language: python
22
matrix:
33
include:
4-
- python: "2.7"
5-
- python: "3.4"
6-
- python: "3.5"
7-
- python: "3.6"
8-
- python: "pypy"
9-
- python: "pypy3.5"
10-
- python: 3.7
11-
dist: xenial
12-
sudo: true
4+
- python: '2.7'
5+
- python: '3.5'
6+
- python: '3.6'
7+
- python: pypy
8+
- python: pypy3.5
9+
- python: 3.7
10+
dist: xenial
11+
sudo: true
12+
- python: 3.8
13+
dist: xenial
14+
sudo: true
1315
install:
14-
- "pip install six requests"
15-
- "pip install -r requirements-tests.txt"
16-
- "python setup.py install"
17-
script: "pytest --cov=easypost --cov-report=term-missing tests/"
16+
- pip install six requests
17+
- pip install -r requirements-tests.txt
18+
- python setup.py install
19+
script: py.test --cov=easypost --cov-report=term-missing --vcr-record=none --cov-fail-under=60 tests/
20+
env:
21+
global:
22+
- secure: GY8+PX7WH8nZUK26F/7ygkYoWi6iXvetJybkNnAFZN+cwRuHe9qwJVrEtSr0jeFWWaxt0OvglAcv66ApHI6g137Y2cxqMyfJaBgFHI2d4Yl75ppkJuqkNch0YLhm2CiWllOnPfvdDkVz6ivW7T0jGbWtExeGt8NAMlQvkThE6Mo=
23+
- secure: WO+grBRxUJcGIXhBouWFb6/M59JLcA/mgLOhQmQcLPyw4n32wKgyRQZfc9AYqH+9bWxh2uWIk+Z0wmugCM6ETq80cVpEHWWUZ66bhlPG0tHYcquvBfn/+1iOmnDRdtXpsg59qe/My69S9H1mwPYEznVLJXuCFhOxFy9L9LyWMQU=

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ EasyPost is the simple shipping API. You can sign up for an account at <https://
88
Requirements
99
------------
1010

11-
* [Python](https://www.python.org) 2.7 or 3.3+ (or corresponding [PyPy](https://pypy.org) versions).
11+
* [Python](https://www.python.org) 2.7 or 3.3+ (or corresponding [PyPy](https://pypy.org) versions). Note that we only test on Python 2.7 and 3.5+; we strongly recommend against using 3.3.x or 3.4.x as they are no longer supported by many libraries.
1212
* [requests](http://docs.python-requests.org/en/latest/) (if not on Google App Engine)
1313
* [six](https://pythonhosted.org/six/)
1414

@@ -157,4 +157,5 @@ To run tests:
157157
- Create a virtualenv for your version of Python (e.g., `python2.7 -m virtualenv venv`)
158158
- Install dependencies in that virtualenv (`./venv/bin/pip install requests six`)
159159
- Install test dependencies (`./venv/bin/pip install -r requirements-tests.txt`)
160+
- Export `$TEST_API_KEY` and `$PROD_API_KEY` appropriately (these are set by `.travis.yml` for CI)
160161
- Run the tests with `py.test` (`./venv/bin/py.test -vs tests`)

easypost/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import requests
3131
request_lib = 'requests'
3232
requests_session = requests.Session()
33+
requests_http_adapter = requests.adapters.HTTPAdapter(max_retries=3)
34+
requests_session.mount('https://api.easypost.com', requests_http_adapter)
3335
except ImportError:
3436
raise ImportError('EasyPost requires an up to date requests library. '
3537
'Update requests via "pip install -U requests" or '
@@ -59,20 +61,21 @@
5961

6062

6163
class Error(Exception):
62-
def __init__(self, message=None, http_status=None, http_body=None):
64+
def __init__(self, message=None, http_status=None, http_body=None, original_exception=None):
6365
super(Error, self).__init__(message)
6466
self.message = message
6567
self.http_status = http_status
6668
self.http_body = http_body
69+
self.original_exception = original_exception
6770
try:
6871
self.json_body = json.loads(http_body)
69-
except:
72+
except Exception:
7073
self.json_body = None
7174

7275
self.param = None
7376
try:
7477
self.param = self.json_body['error'].get('param', None)
75-
except:
78+
except Exception:
7679
pass
7780

7881

@@ -222,7 +225,7 @@ def _encode_inner(cls, params):
222225
# don't need special encoding
223226
try:
224227
value = six.text_type(value)
225-
except:
228+
except Exception:
226229
pass
227230

228231
out.append((key, value))
@@ -350,7 +353,8 @@ def requests_request(self, method, abs_url, headers, params):
350353
http_status = result.status_code
351354
except Exception as e:
352355
raise Error("Unexpected error communicating with EasyPost. If this "
353-
"problem persists please let us know at [email protected].")
356+
"problem persists please let us know at [email protected].",
357+
original_exception=e)
354358
return http_body, http_status
355359

356360
def urlfetch_request(self, method, abs_url, headers, params):
@@ -371,9 +375,10 @@ def urlfetch_request(self, method, abs_url, headers, params):
371375

372376
try:
373377
result = urlfetch.fetch(**args)
374-
except:
378+
except Exception as e:
375379
raise Error("Unexpected error communicating with EasyPost. "
376-
"If this problem persists, let us know at [email protected].")
380+
"If this problem persists, let us know at [email protected].",
381+
original_exception=e)
377382

378383
return result.content, result.status_code
379384

requirements-tests.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
pytest==4.6.*
22
pytest-cov==2.8.1
33
pytz
4+
# 45.0.0 removes python 2.x support
5+
setuptools>=42,<45
6+
# zipp after 0.5 tries to install its own setuptools at build time,
7+
# which fails on python 2.7
8+
zipp==0.5.*
9+
# 4.x removes python 2.x support
10+
vcrpy==3.*
11+
# >3.0.5 removes python 2.x support
12+
mock==3.0.5
13+
pytest-vcr==1.*
14+
# 5.0.0 removes python 2.x support
15+
configparser<5
16+
requests

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444
"Environment :: Web Environment",
4545
"Programming Language :: Python",
4646
"Programming Language :: Python :: 2.7",
47-
"Programming Language :: Python :: 3.3",
48-
"Programming Language :: Python :: 3.4",
4947
"Programming Language :: Python :: 3.5",
5048
"Programming Language :: Python :: 3.6",
5149
"Programming Language :: Python :: 3.7",
50+
"Programming Language :: Python :: 3.8",
5251
"Intended Audience :: Developers",
5352
"Operating System :: OS Independent",
5453
"License :: OSI Approved :: MIT License",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
interactions:
2+
- request:
3+
body: !!python/unicode address%5Bstate%5D=DELEGACI%C3%B3N+BENITO+JU%C3%A1REZ
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
Content-Length:
12+
- '53'
13+
Content-type:
14+
- application/x-www-form-urlencoded
15+
authorization:
16+
- EZTK-NONE
17+
user-agent:
18+
- easypost/v2 pythonclient/suppressed
19+
x-client-user-agent:
20+
- suppressed
21+
method: POST
22+
uri: https://api.easypost.com/v2/addresses
23+
response:
24+
body:
25+
string: !!binary |
26+
H4sIAAAAAAAAA4SQQU7DQAxFr1LNmkqZadNAdm2JUBEqErQbNpEz9gijZBJNJgioehjOwBF6MSaL
27+
hsCG5f9+9rd9EIwiFYAuj5XRsIgBk4WcG5CXppjPrmaFLgqtI4PiQtTFC2kf+CWio7YNlnYEnjCH
28+
3laRiqZRPJVyp2QaJ6lKngLTNfgvY6EikdquLMPMumrAvp9l6x2Rl7+lGmD2IzLkhIzr7C67Wa43
29+
p6/tZJVtN7v7ye3+9PmQ9Ukf3PwEdda70C72j6HSPNd2WIIq4PIsqhr7uZ5a398MzjG53IDmchQf
30+
XsJI1jMMjYaQHJS5h7e8//Rozz/eKzk2rMFzbVuRHo7HbwAAAP//AwDzj9QRnAEAAA==
31+
headers:
32+
cache-control:
33+
- no-cache, no-store, must-revalidate, private
34+
content-encoding:
35+
- gzip
36+
content-type:
37+
- application/json; charset=utf-8
38+
expires:
39+
- '0'
40+
location:
41+
- /api/v2/addresses/adr_52fca65ad7614fa18fb4393bcbbcc0fd
42+
pragma:
43+
- no-cache
44+
strict-transport-security:
45+
- max-age=15768000; includeSubDomains; preload
46+
transfer-encoding:
47+
- chunked
48+
x-backend:
49+
- easypost
50+
x-content-type-options:
51+
- nosniff
52+
x-ep-request-uuid:
53+
- 2b85eb425eb9ca47fb0a061d000475f3
54+
x-frame-options:
55+
- SAMEORIGIN
56+
x-node:
57+
- bigweb6sj
58+
x-proxied:
59+
- intlb1sj 5834894b53
60+
- extlb1sj 5834894b53
61+
x-runtime:
62+
- '0.034639'
63+
x-version-label:
64+
- easypost-202005112100-59b664a857-master
65+
x-xss-protection:
66+
- 1; mode=block
67+
status:
68+
code: 201
69+
message: Created
70+
version: 1

0 commit comments

Comments
 (0)