Skip to content

Commit b441c72

Browse files
authored
Merge pull request #230 from EasyPost/robust_tests
chore: better test coverage and enforcement
2 parents a41d79a + e7e4acf commit b441c72

31 files changed

+1108
-775
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
- name: Install Dependencies
3333
run: make install
3434
- name: Run Tests
35-
run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make test
35+
run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make coverage
3636
- name: Run security analysis
3737
run: make scan

Makefile

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

2020
## coverage - Test the project and generate an HTML coverage report
2121
coverage:
22-
$(VIRTUAL_BIN)/pytest --cov=$(PROJECT_NAME) --cov-branch --cov-report=html --cov-report=term-missing
22+
$(VIRTUAL_BIN)/pytest --cov=$(PROJECT_NAME) --cov-branch --cov-report=html --cov-report=term-missing --cov-fail-under=88
2323

2424
## black - Runs the Black Python formatter against the project
2525
black:

easypost/address.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,12 @@ def create_and_verify(cls, api_key: Optional[str] = None, **params) -> "Address"
4444
wrapped_params = {cls.snakecase_name(): params}
4545
response, api_key = requestor.request(method=RequestMethod.POST, url=url, params=wrapped_params)
4646

47-
response_address = response.get("address", None)
48-
49-
if response_address is not None:
50-
verified_address = convert_to_easypost_object(response=response_address, api_key=api_key)
51-
return verified_address
52-
else:
53-
return convert_to_easypost_object(response=response, api_key=api_key)
47+
return convert_to_easypost_object(response=response["address"], api_key=api_key)
5448

5549
def verify(self) -> "Address":
5650
"""Verify an address."""
5751
requestor = Requestor(local_api_key=self._api_key)
5852
url = "%s/%s" % (self.instance_url(), "verify")
5953
response, api_key = requestor.request(method=RequestMethod.GET, url=url)
6054

61-
response_address = response.get("address", None)
62-
63-
if response_address is not None:
64-
verified_address = convert_to_easypost_object(response=response_address, api_key=api_key)
65-
return verified_address
66-
else:
67-
return convert_to_easypost_object(response=response, api_key=api_key)
55+
return convert_to_easypost_object(response=response["address"], api_key=api_key)

easypost/endshipper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def create(cls, api_key: Optional[str] = None, **params) -> "EndShipper":
2222
return convert_to_easypost_object(response=response, api_key=api_key)
2323

2424
def save(self) -> "EndShipper":
25-
"""Update an EndShipper object."""
25+
"""Update an EndShipper object.
26+
27+
This function requires all parameters to be present for an EndShipper.
28+
"""
2629
if self._unsaved_values:
2730
requestor = Requestor(local_api_key=self._api_key)
2831
params = {}

easypost/resource.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818

1919
class Resource(EasyPostObject):
20-
def _ident(self) -> List[str]:
21-
return [self.get("id")]
22-
2320
@classmethod
2421
def retrieve(cls, easypost_id: str, api_key: Optional[str] = None, **params) -> object:
2522
"""Retrieve an object from the EasyPost API."""

easypost/version.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
VERSION = "7.6.0"
22

3-
elements = VERSION.split("-")
4-
numbers = [str(v) for v in elements[0].split(".")]
5-
if len(elements) > 1:
6-
numbers.extend(elements[1])
7-
numbers.extend(elements[1:])
3+
numbers = [str(number) for number in VERSION.split(".")]
84
VERSION_INFO = numbers

pytest.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/cassettes/test_address_all.yaml

Lines changed: 42 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/cassettes/test_address_create_and_verify.yaml

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)