Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert types of pagination responses #1015

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stripe/api_resources/list_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,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