From efaf4f941a7ae8fe3361709194d7a762841cf1f6 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Wed, 16 Aug 2023 14:59:59 -0700 Subject: [PATCH 1/2] assert on page types --- stripe/api_resources/list_object.py | 4 +++- stripe/api_resources/search_result_object.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/stripe/api_resources/list_object.py b/stripe/api_resources/list_object.py index eda72fd04..94eb876a0 100644 --- a/stripe/api_resources/list_object.py +++ b/stripe/api_resources/list_object.py @@ -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 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 From 54682c45ed254dcca850ddb548f4fbc87f70f354 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Wed, 16 Aug 2023 15:07:41 -0700 Subject: [PATCH 2/2] fix test --- tests/api_resources/test_search_result_object.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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"