Skip to content

Commit

Permalink
Assert types of pagination responses (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe authored Aug 16, 2023
1 parent 5a844be commit e1e6874
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion stripe/api_resources/list_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ def next_page(
params_with_filters.update({"starting_after": last_id})
params_with_filters.update(params)

return self.list(
result = self.list(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
**params_with_filters
)
assert isinstance(result, ListObject)
return result

def previous_page(
self, api_key=None, stripe_version=None, stripe_account=None, **params
Expand Down
4 changes: 3 additions & 1 deletion stripe/api_resources/search_result_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ def next_search_result_page(
params_with_filters.update({"page": self.next_page})
params_with_filters.update(params)

return self.search(
result = self.search(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
**params_with_filters
)
assert isinstance(result, SearchResultObject)
return result
16 changes: 8 additions & 8 deletions tests/api_resources/test_search_result_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def test_bool(self, search_result_object):
assert search_result_object

empty = stripe.SearchResultObject.construct_from(
{"object": "list", "url": "/my/path", "data": []}, "mykey"
{"object": "search_result", "url": "/my/path", "data": []}, "mykey"
)
assert bool(empty) is False

def test_next_search_result_page(self, request_mock):
sro = stripe.SearchResultObject.construct_from(
{
"object": "list",
"object": "search_result",
"data": [{"id": 1}],
"has_more": True,
"next_page": "next_page_token",
Expand All @@ -79,7 +79,7 @@ def test_next_search_result_page(self, request_mock):
"get",
"/things",
{
"object": "list",
"object": "search_result",
"data": [{"id": 2}],
"has_more": False,
"url": "/things",
Expand All @@ -97,7 +97,7 @@ def test_next_search_result_page(self, request_mock):
def test_next_search_result_page_with_filters(self, request_mock):
sro = stripe.SearchResultObject.construct_from(
{
"object": "list",
"object": "search_result",
"data": [{"id": 1}],
"has_more": True,
"next_page": "next_page_token",
Expand All @@ -111,7 +111,7 @@ def test_next_search_result_page_with_filters(self, request_mock):
"get",
"/things",
{
"object": "list",
"object": "search_result",
"data": [{"id": 2}],
"has_more": False,
"next_page": None,
Expand All @@ -129,7 +129,7 @@ def test_next_search_result_page_with_filters(self, request_mock):
def test_next_search_result_page_empty_search_result(self):
sro = stripe.SearchResultObject.construct_from(
{
"object": "list",
"object": "search_result",
"data": [{"id": 1}],
"has_more": False,
"next_page": None,
Expand All @@ -143,7 +143,7 @@ def test_next_search_result_page_empty_search_result(self):

def test_serialize_empty_search_result(self):
empty = stripe.SearchResultObject.construct_from(
{"object": "list", "data": []}, "mykey"
{"object": "search_result", "data": []}, "mykey"
)
serialized = str(empty)
deserialized = stripe.SearchResultObject.construct_from(
Expand All @@ -153,7 +153,7 @@ def test_serialize_empty_search_result(self):

def test_serialize_nested_empty_search_result(self):
empty = stripe.SearchResultObject.construct_from(
{"object": "list", "data": []}, "mykey"
{"object": "search_result", "data": []}, "mykey"
)
obj = stripe.stripe_object.StripeObject.construct_from(
{"nested": empty}, "mykey"
Expand Down

0 comments on commit e1e6874

Please sign in to comment.