From e1e6874d68b0425baf6aafcb5b3e868f8e70068d Mon Sep 17 00:00:00 2001 From: Richard Marmorstein <52928443+richardm-stripe@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:12:20 -0700 Subject: [PATCH] Assert types of pagination responses (#1015) --- stripe/api_resources/list_object.py | 4 +++- stripe/api_resources/search_result_object.py | 4 +++- tests/api_resources/test_search_result_object.py | 16 ++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/stripe/api_resources/list_object.py b/stripe/api_resources/list_object.py index 3780f580a..4c614ca10 100644 --- a/stripe/api_resources/list_object.py +++ b/stripe/api_resources/list_object.py @@ -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 diff --git a/stripe/api_resources/search_result_object.py b/stripe/api_resources/search_result_object.py index 974cead9f..c7b7768e1 100644 --- a/stripe/api_resources/search_result_object.py +++ b/stripe/api_resources/search_result_object.py @@ -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 diff --git a/tests/api_resources/test_search_result_object.py b/tests/api_resources/test_search_result_object.py index 379131eb0..8517c7881 100644 --- a/tests/api_resources/test_search_result_object.py +++ b/tests/api_resources/test_search_result_object.py @@ -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", @@ -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", @@ -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", @@ -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, @@ -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, @@ -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( @@ -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"