Skip to content

Commit d79b29e

Browse files
authored
Merge pull request #280 from EasyPost/tie_a_bow
Type Hints, Docstrings, and Missing Tests for v8
2 parents 5980c5f + 3b588a0 commit d79b29e

Some content is hidden

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

55 files changed

+203
-597
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ clean:
2727

2828
## coverage - Test the project and generate an HTML coverage report
2929
coverage:
30-
$(VIRTUAL_BIN)/pytest --cov=$(PROJECT_NAME) --cov-branch --cov-report=html --cov-report=lcov --cov-report=term-missing --cov-fail-under=88
30+
$(VIRTUAL_BIN)/pytest --cov=$(PROJECT_NAME) --cov-branch --cov-report=html --cov-report=lcov --cov-report=term-missing --cov-fail-under=90
3131

3232
## docs - Generates docs for the library
3333
docs:

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,14 @@ Some tests may require an EasyPost user with a particular set of enabled feature
127127
- `USPS_CARRIER_ACCOUNT_ID` (eg: one-call buying a shipment for non-EasyPost employees)
128128
- `PARTNER_USER_PROD_API_KEY` (eg: creating a referral user)
129129
- `REFERRAL_CUSTOMER_PROD_API_KEY` (eg: adding a credit card to a referral user)
130+
131+
#### Google Cloud SDK
132+
133+
To run the test suite with the Google Cloud SDK (`urlfetch` instead of the `requests` library), you'll need the following:
134+
135+
1. Install the appengine Python package to this virtual environment: `venv/bin/pip install appengine-python-standard`
136+
1. Install the Google Cloud SDK
137+
- [Direct Download](https://cloud.google.com/sdk/docs/install)
138+
- [Homebrew](https://formulae.brew.sh/cask/google-cloud-sdk)
139+
1. Point the `PYTHONPATH` environment variable to the path of the newly installed `google-cloud-sdk` directory. For Homebrew, this is `"$(brew --prefix)/share/google-cloud-sdk"`
140+
1. Run the test suite with the commands listed in this README

easypost/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# flake8: noqa
22
from easypost.constant import (
3+
AUTHOR,
34
VERSION,
45
VERSION_INFO,
56
)
@@ -13,6 +14,6 @@
1314
)
1415

1516

16-
__author__ = "EasyPost <[email protected]>"
17+
__author__ = AUTHOR
1718
__version__ = VERSION
1819
version_info = VERSION_INFO

easypost/constant.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Client defaults
77
API_BASE = "https://api.easypost.com"
88
API_VERSION = "v2"
9+
AUTHOR = "EasyPost <[email protected]>"
910
SUPPORT_EMAIL = "[email protected]"
1011
TIMEOUT = 60
1112

@@ -21,12 +22,12 @@
2122
INVALID_SIGNATURE_ERROR = "Webhook received does not contain an HMAC signature."
2223
INVALID_WEBHOOK_VALIDATION_ERROR = "Webhook received did not originate from EasyPost or had a webhook secret mismatch."
2324
MISSING_PARAMETER_ERROR = "Missing required parameter: {}"
24-
NO_API_KEY_ERROR = "No API key provided. Set an API key via \"EasyPostClient('EASYPOST_API_KEY')\". Your API keys can be found in your EasyPost dashboard, or you can email us at {} for assistance."
2525
NO_ATTRIBUTE_ERROR = "{} object has no attribute {}"
2626
NO_BILLING_ERROR = "Billing has not been setup for this user. Please add a payment method."
2727
NO_MORE_PAGES_ERROR = "There are no more pages to retrieve."
2828
NO_RATES_ERROR = "No rates found."
29-
SEND_STRIPE_DETAILS_ERROR = "Could not send card details to Stripe, please try again later"
29+
SEND_STRIPE_DETAILS_ERROR = "Could not send card details to Stripe, please try again later."
30+
TIMEOUT_ERROR = "Request timed out."
3031

3132
# Internal constants (user's should not use these)
3233
_TEST_FAILED_INTENTIONALLY_ERROR = "Test failed intentionally."

easypost/easypost_client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
API_BASE,
33
API_VERSION,
44
INVALID_REQUESTS_VERSION_ERROR,
5-
NO_API_KEY_ERROR,
65
SUPPORT_EMAIL,
76
TIMEOUT,
87
)
9-
from easypost.errors import MissingParameterError
108
from easypost.services import (
119
AddressService,
1210
BatchService,
@@ -75,9 +73,6 @@ def __init__(
7573
self.user = UserService(self)
7674
self.webhook = WebhookService(self)
7775

78-
if self.api_key is None:
79-
raise MissingParameterError(NO_API_KEY_ERROR.format(SUPPORT_EMAIL))
80-
8176
# use urlfetch as request_lib on google app engine, otherwise use requests
8277
self._request_lib = None
8378
try:
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
from typing import (
2-
Any,
3-
Dict,
4-
List,
5-
Optional,
6-
Union,
7-
)
8-
91
from easypost.errors.api.api_error import ApiError
102

113

124
class EncodingError(ApiError):
13-
def __init__(
14-
self,
15-
message: Union[
16-
Dict[str, Any], list, str
17-
], # message should be a string but can sometimes incorrectly come back as a list or object
18-
errors: Optional[List[str]] = None,
19-
code: Optional[str] = None,
20-
http_status: Optional[int] = None,
21-
http_body: Optional[Union[str, bytes]] = None,
22-
):
23-
super().__init__(
24-
message=message,
25-
errors=errors,
26-
code=code,
27-
http_status=http_status,
28-
http_body=http_body,
29-
)
5+
pass
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
from typing import (
2-
Any,
3-
Dict,
4-
List,
5-
Optional,
6-
Union,
7-
)
8-
91
from easypost.errors.api.api_error import ApiError
102

113

124
class ExternalApiError(ApiError):
13-
def __init__(
14-
self,
15-
message: Union[
16-
Dict[str, Any], list, str
17-
], # message should be a string but can sometimes incorrectly come back as a list or object
18-
errors: Optional[List[str]] = None,
19-
code: Optional[str] = None,
20-
http_status: Optional[int] = None,
21-
http_body: Optional[Union[str, bytes]] = None,
22-
):
23-
super().__init__(
24-
message=message,
25-
errors=errors,
26-
code=code,
27-
http_status=http_status,
28-
http_body=http_body,
29-
)
5+
pass
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
from typing import (
2-
Any,
3-
Dict,
4-
List,
5-
Optional,
6-
Union,
7-
)
8-
91
from easypost.errors.api.api_error import ApiError
102

113

124
class ForbiddenError(ApiError):
13-
def __init__(
14-
self,
15-
message: Union[
16-
Dict[str, Any], list, str
17-
], # message should be a string but can sometimes incorrectly come back as a list or object
18-
errors: Optional[List[str]] = None,
19-
code: Optional[str] = None,
20-
http_status: Optional[int] = None,
21-
http_body: Optional[Union[str, bytes]] = None,
22-
):
23-
super().__init__(
24-
message=message,
25-
errors=errors,
26-
code=code,
27-
http_status=http_status,
28-
http_body=http_body,
29-
)
5+
pass
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
from typing import (
2-
Any,
3-
Dict,
4-
List,
5-
Optional,
6-
Union,
7-
)
8-
91
from easypost.errors.api.api_error import ApiError
102

113

124
class GatewayTimeoutError(ApiError):
13-
def __init__(
14-
self,
15-
message: Union[
16-
Dict[str, Any], list, str
17-
], # message should be a string but can sometimes incorrectly come back as a list or object
18-
errors: Optional[List[str]] = None,
19-
code: Optional[str] = None,
20-
http_status: Optional[int] = None,
21-
http_body: Optional[Union[str, bytes]] = None,
22-
):
23-
super().__init__(
24-
message=message,
25-
errors=errors,
26-
code=code,
27-
http_status=http_status,
28-
http_body=http_body,
29-
)
5+
pass

easypost/errors/api/http_error.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
from typing import (
2-
Any,
3-
Dict,
4-
List,
5-
Optional,
6-
Union,
7-
)
8-
91
from easypost.errors.api.api_error import ApiError
102

113

124
class HttpError(ApiError):
13-
def __init__(
14-
self,
15-
message: Union[
16-
Dict[str, Any], list, str
17-
], # message should be a string but can sometimes incorrectly come back as a list or object
18-
errors: Optional[List[str]] = None,
19-
code: Optional[str] = None,
20-
http_status: Optional[int] = None,
21-
http_body: Optional[Union[str, bytes]] = None,
22-
):
23-
super().__init__(
24-
message=message,
25-
errors=errors,
26-
code=code,
27-
http_status=http_status,
28-
http_body=http_body,
29-
)
5+
pass

0 commit comments

Comments
 (0)