Skip to content

Commit

Permalink
Update code and tests to support stripe-python 6.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bhch committed Nov 18, 2023
1 parent bbc9a8e commit 6ec8ab5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
3 changes: 3 additions & 0 deletions async_stripe/api_resources/abstract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from async_stripe.api_resources.abstract.listable_api_resource import (
ListableAPIResource,
)
from async_stripe.api_resources.abstract.searchable_api_resource import (
SearchableAPIResource,
)
from async_stripe.api_resources.abstract import test_helpers

from async_stripe.api_resources.abstract.nested_resource_class_methods import (
Expand Down
24 changes: 24 additions & 0 deletions async_stripe/api_resources/abstract/listable_api_resource.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
from stripe.api_resources.abstract.listable_api_resource import (
ListableAPIResource,
)
from stripe.api_resources.list_object import ListObject
from typing import Awaitable


async def auto_paging_iter_patch(cls, *args, **params):
obj = await cls.list(*args, **params)
return obj.auto_paging_iter()


def list_patch(
cls, api_key=None, stripe_version=None, stripe_account=None, **params
) -> Awaitable[ListObject]:
result = cls._static_request(
"get",
cls.class_url(),
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
params=params,
)

if not isinstance(result, Awaitable):
raise TypeError(
"Expected awaitable object from API, got %s"
% (type(result).__name__,)
)

return result


ListableAPIResource.auto_paging_iter = classmethod(auto_paging_iter_patch)
ListableAPIResource.list = classmethod(list_patch)


for subclass in ListableAPIResource.__subclasses__():
Expand Down
33 changes: 33 additions & 0 deletions async_stripe/api_resources/abstract/searchable_api_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from stripe.api_resources.abstract.searchable_api_resource import (
SearchableAPIResource,
)
from stripe.api_resources.search_result_object import SearchResultObject
from typing import Awaitable


def _search_patch(
cls,
search_url,
api_key=None,
stripe_version=None,
stripe_account=None,
**params
) -> Awaitable[SearchResultObject]:
ret = cls._static_request(
"get",
search_url,
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
params=params,
)
if not isinstance(ret, Awaitable):
raise TypeError(
"Expected awaitable object from API, got %s"
% (type(ret).__name__,)
)

return ret


SearchableAPIResource._search = classmethod(_search_patch)
8 changes: 5 additions & 3 deletions tests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@


class StripeClientTestCase(object):
REQUEST_LIBRARIES = ["AsyncHTTPClient"]
REQUEST_LIBRARIES = [
("AsyncHTTPClient", "async_stripe.http_client.AsyncHTTPClient"),
]

@pytest.fixture
def request_mocks(self, mocker):
request_mocks = {}
for lib in self.REQUEST_LIBRARIES:
request_mocks[lib] = mocker.patch("async_stripe.http_client.%s" % (lib,))
for lib, mockpath in self.REQUEST_LIBRARIES:
request_mocks[lib] = mocker.patch(mockpath)
return request_mocks


Expand Down

0 comments on commit 6ec8ab5

Please sign in to comment.