Skip to content

Commit 1e0660e

Browse files
committed
tests: strong api key assertions
1 parent 5bfc815 commit 1e0660e

File tree

9 files changed

+152
-722
lines changed

9 files changed

+152
-722
lines changed

easypost/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# flake8: noqa
22
import easypost.beta
33
from easypost.address import Address
4+
from easypost.api_key import ApiKey
45
from easypost.batch import Batch
56
from easypost.billing import Billing
67
from easypost.brand import Brand

easypost/api_key.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from easypost.resource import Resource
2+
3+
4+
class ApiKey(Resource):
5+
pass

easypost/easypost_object.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP = {
13+
"ak": "ApiKey",
1314
"adr": "Address",
1415
"batch": "Batch",
1516
"brd": "Brand",

easypost/user.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Optional,
66
)
77

8+
from easypost.api_key import ApiKey
89
from easypost.easypost_object import convert_to_easypost_object
910
from easypost.requestor import (
1011
RequestMethod,
@@ -57,7 +58,7 @@ def all_api_keys(cls, api_key: Optional[str] = None) -> Dict[str, Any]:
5758
response, api_key = requestor.request(method=RequestMethod.GET, url=url)
5859
return convert_to_easypost_object(response=response, api_key=api_key)
5960

60-
def api_keys(self) -> List[Dict[str, Any]]:
61+
def api_keys(self) -> List[ApiKey]:
6162
"""Retrieve a list of API keys (works for the authenticated user or a child user)."""
6263
api_keys = self.all_api_keys()
6364

tests/cassettes/test_authenticated_user_api_keys.yaml

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

tests/cassettes/test_child_user_api_keys.yaml

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

tests/cassettes/test_user_all_api_keys.yaml

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

tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,11 @@ def vcr_config():
112112
],
113113
"before_record_response": scrub_response_bodies(
114114
scrubbers=[
115-
["api_keys", SCRUBBED_ARRAY],
116115
["client_ip", SCRUBBED_STRING],
117116
["credentials", SCRUBBED_DICT],
118117
["email", SCRUBBED_STRING],
119118
["fields", SCRUBBED_ARRAY],
120119
["key", SCRUBBED_STRING],
121-
["keys", SCRUBBED_ARRAY],
122120
["phone_number", SCRUBBED_STRING],
123121
["phone", SCRUBBED_STRING],
124122
["test_credentials", SCRUBBED_DICT],

tests/test_user.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def test_user_all_api_keys(prod_api_key):
7070
user = easypost.User.retrieve_me()
7171
api_keys = user.all_api_keys()
7272

73-
assert api_keys["keys"] is not None
73+
assert all(isinstance(key, easypost.ApiKey) for key in api_keys.keys)
74+
for child in api_keys.children:
75+
assert all(isinstance(key, easypost.ApiKey) for key in child["keys"])
7476

7577

7678
@pytest.mark.vcr()
@@ -79,7 +81,7 @@ def test_authenticated_user_api_keys(prod_api_key):
7981
user = easypost.User.retrieve_me()
8082
api_keys = user.api_keys()
8183

82-
assert api_keys is not None
84+
assert all(isinstance(key, easypost.ApiKey) for key in api_keys)
8385

8486

8587
@pytest.mark.vcr()
@@ -90,7 +92,10 @@ def test_child_user_api_keys(prod_api_key):
9092

9193
api_keys = child_user.api_keys()
9294

93-
assert api_keys is not None
95+
assert all(isinstance(key, easypost.ApiKey) for key in api_keys)
96+
97+
# Delete the user so we don't clutter up the test environment
98+
user.delete()
9499

95100

96101
@pytest.mark.vcr()

0 commit comments

Comments
 (0)