From d8c301c6611fd1b6b305f8cc9d7ff8e8e8d7aba2 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 2 Apr 2019 17:47:39 -0700 Subject: [PATCH] Add custom methods to all resources --- stripe/api_resources/account.py | 3 ++- stripe/api_resources/customer.py | 2 ++ stripe/api_resources/dispute.py | 2 ++ stripe/api_resources/issuing/authorization.py | 3 +++ stripe/api_resources/issuing/card.py | 2 ++ stripe/api_resources/order.py | 3 +++ stripe/api_resources/payment_intent.py | 4 +++ stripe/api_resources/payment_method.py | 3 +++ stripe/api_resources/payout.py | 2 ++ stripe/api_resources/review.py | 2 ++ stripe/api_resources/subscription.py | 2 ++ stripe/api_resources/subscription_schedule.py | 3 +++ stripe/api_resources/topup.py | 2 ++ stripe/api_resources/transfer.py | 2 ++ .../issuing/test_authorization.py | 18 +++++++++++-- tests/api_resources/issuing/test_card.py | 7 +++++ tests/api_resources/test_account.py | 13 +++++++++- tests/api_resources/test_charge.py | 4 +-- tests/api_resources/test_customer.py | 6 +++++ tests/api_resources/test_dispute.py | 10 ++++++- tests/api_resources/test_order.py | 26 ++++++++++++++++--- tests/api_resources/test_payment_intent.py | 24 ++++++++++++++--- tests/api_resources/test_payment_method.py | 18 +++++++++++++ tests/api_resources/test_payout.py | 7 +++++ tests/api_resources/test_review.py | 9 ++++++- tests/api_resources/test_subscription.py | 6 +++++ .../test_subscription_schedule.py | 14 ++++++++++ tests/api_resources/test_topup.py | 13 +++++++--- tests/api_resources/test_transfer.py | 16 +++++++++++- 29 files changed, 207 insertions(+), 19 deletions(-) diff --git a/stripe/api_resources/account.py b/stripe/api_resources/account.py index c49657b81..96169e5ed 100644 --- a/stripe/api_resources/account.py +++ b/stripe/api_resources/account.py @@ -7,10 +7,11 @@ from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource from stripe.api_resources.abstract import nested_resource_class_methods - +from stripe.api_resources.abstract import custom_method from stripe.six.moves.urllib.parse import quote_plus +@custom_method("reject", http_verb="post") @nested_resource_class_methods( "external_account", operations=["create", "retrieve", "update", "delete", "list"], diff --git a/stripe/api_resources/customer.py b/stripe/api_resources/customer.py index 96345f892..68cae6211 100644 --- a/stripe/api_resources/customer.py +++ b/stripe/api_resources/customer.py @@ -5,9 +5,11 @@ from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method from stripe.api_resources.abstract import nested_resource_class_methods +@custom_method("delete_discount", http_verb="delete", http_path="discount") @nested_resource_class_methods( "source", operations=["create", "retrieve", "update", "delete", "list"] ) diff --git a/stripe/api_resources/dispute.py b/stripe/api_resources/dispute.py index 320c73f2f..59225e41b 100644 --- a/stripe/api_resources/dispute.py +++ b/stripe/api_resources/dispute.py @@ -3,8 +3,10 @@ from stripe import util from stripe.api_resources.abstract import ListableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("close", http_verb="post") class Dispute(ListableAPIResource, UpdateableAPIResource): OBJECT_NAME = "dispute" diff --git a/stripe/api_resources/issuing/authorization.py b/stripe/api_resources/issuing/authorization.py index 2f2ac5de3..05ac4a595 100644 --- a/stripe/api_resources/issuing/authorization.py +++ b/stripe/api_resources/issuing/authorization.py @@ -3,8 +3,11 @@ from stripe import util from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("approve", http_verb="post") +@custom_method("decline", http_verb="post") class Authorization(ListableAPIResource, UpdateableAPIResource): OBJECT_NAME = "issuing.authorization" diff --git a/stripe/api_resources/issuing/card.py b/stripe/api_resources/issuing/card.py index ebc606510..073bfc0a1 100644 --- a/stripe/api_resources/issuing/card.py +++ b/stripe/api_resources/issuing/card.py @@ -3,8 +3,10 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("details", http_verb="get") class Card(CreateableAPIResource, ListableAPIResource, UpdateableAPIResource): OBJECT_NAME = "issuing.card" diff --git a/stripe/api_resources/order.py b/stripe/api_resources/order.py index eb3d1ede7..640430691 100644 --- a/stripe/api_resources/order.py +++ b/stripe/api_resources/order.py @@ -4,8 +4,11 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("pay", http_verb="post") +@custom_method("return_order", http_verb="post", http_path="returns") class Order(CreateableAPIResource, UpdateableAPIResource, ListableAPIResource): OBJECT_NAME = "order" diff --git a/stripe/api_resources/payment_intent.py b/stripe/api_resources/payment_intent.py index 9e8ffa6a4..8912eb53c 100644 --- a/stripe/api_resources/payment_intent.py +++ b/stripe/api_resources/payment_intent.py @@ -4,8 +4,12 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("cancel", http_verb="post") +@custom_method("capture", http_verb="post") +@custom_method("confirm", http_verb="post") class PaymentIntent( CreateableAPIResource, UpdateableAPIResource, ListableAPIResource ): diff --git a/stripe/api_resources/payment_method.py b/stripe/api_resources/payment_method.py index 0389adf46..87fc62ce5 100644 --- a/stripe/api_resources/payment_method.py +++ b/stripe/api_resources/payment_method.py @@ -4,8 +4,11 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import ListableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("attach", http_verb="post") +@custom_method("detach", http_verb="post") class PaymentMethod( CreateableAPIResource, ListableAPIResource, UpdateableAPIResource ): diff --git a/stripe/api_resources/payout.py b/stripe/api_resources/payout.py index feacdcf7f..561bfd56c 100644 --- a/stripe/api_resources/payout.py +++ b/stripe/api_resources/payout.py @@ -4,8 +4,10 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("cancel", http_verb="post") class Payout( CreateableAPIResource, UpdateableAPIResource, ListableAPIResource ): diff --git a/stripe/api_resources/review.py b/stripe/api_resources/review.py index 2bc4bcc18..fa954581e 100644 --- a/stripe/api_resources/review.py +++ b/stripe/api_resources/review.py @@ -2,8 +2,10 @@ from stripe import util from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("approve", http_verb="post") class Review(ListableAPIResource): OBJECT_NAME = "review" diff --git a/stripe/api_resources/subscription.py b/stripe/api_resources/subscription.py index bf160490d..e31854710 100644 --- a/stripe/api_resources/subscription.py +++ b/stripe/api_resources/subscription.py @@ -5,8 +5,10 @@ from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("delete_discount", http_verb="delete", http_path="discount") class Subscription( CreateableAPIResource, DeletableAPIResource, diff --git a/stripe/api_resources/subscription_schedule.py b/stripe/api_resources/subscription_schedule.py index 7957aed55..954880a0d 100644 --- a/stripe/api_resources/subscription_schedule.py +++ b/stripe/api_resources/subscription_schedule.py @@ -5,8 +5,11 @@ from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource from stripe.api_resources.abstract import nested_resource_class_methods +from stripe.api_resources.abstract import custom_method +@custom_method("cancel", http_verb="post") +@custom_method("release", http_verb="post") @nested_resource_class_methods("revision", operations=["retrieve", "list"]) class SubscriptionSchedule( CreateableAPIResource, UpdateableAPIResource, ListableAPIResource diff --git a/stripe/api_resources/topup.py b/stripe/api_resources/topup.py index 2a0598444..996f780cf 100644 --- a/stripe/api_resources/topup.py +++ b/stripe/api_resources/topup.py @@ -4,8 +4,10 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import custom_method +@custom_method("cancel", http_verb="post") class Topup(CreateableAPIResource, ListableAPIResource, UpdateableAPIResource): OBJECT_NAME = "topup" diff --git a/stripe/api_resources/transfer.py b/stripe/api_resources/transfer.py index c95372b93..afee7a64b 100644 --- a/stripe/api_resources/transfer.py +++ b/stripe/api_resources/transfer.py @@ -5,8 +5,10 @@ from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import ListableAPIResource from stripe.api_resources.abstract import nested_resource_class_methods +from stripe.api_resources.abstract import custom_method +@custom_method("cancel", http_verb="post") @nested_resource_class_methods( "reversal", operations=["create", "retrieve", "update", "list"] ) diff --git a/tests/api_resources/issuing/test_authorization.py b/tests/api_resources/issuing/test_authorization.py index e5ebd3568..00221d7ff 100644 --- a/tests/api_resources/issuing/test_authorization.py +++ b/tests/api_resources/issuing/test_authorization.py @@ -39,7 +39,7 @@ def test_is_saveable(self, request_mock): assert isinstance(resource, stripe.issuing.Authorization) assert resource is authorization - def test_is_approveable(self, request_mock): + def test_can_approve(self, request_mock): resource = stripe.issuing.Authorization.retrieve(TEST_RESOURCE_ID) authorization = resource.approve() request_mock.assert_requested( @@ -48,7 +48,14 @@ def test_is_approveable(self, request_mock): assert isinstance(resource, stripe.issuing.Authorization) assert resource is authorization - def test_is_declineable(self, request_mock): + def test_can_approve_classmethod(self, request_mock): + resource = stripe.issuing.Authorization.approve(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/issuing/authorizations/%s/approve" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.issuing.Authorization) + + def test_can_decline(self, request_mock): resource = stripe.issuing.Authorization.retrieve(TEST_RESOURCE_ID) authorization = resource.decline() request_mock.assert_requested( @@ -56,3 +63,10 @@ def test_is_declineable(self, request_mock): ) assert isinstance(resource, stripe.issuing.Authorization) assert resource is authorization + + def test_can_decline_classmethod(self, request_mock): + resource = stripe.issuing.Authorization.decline(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/issuing/authorizations/%s/decline" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.issuing.Authorization) diff --git a/tests/api_resources/issuing/test_card.py b/tests/api_resources/issuing/test_card.py index 062db0d82..b042a69d7 100644 --- a/tests/api_resources/issuing/test_card.py +++ b/tests/api_resources/issuing/test_card.py @@ -51,3 +51,10 @@ def test_can_retrieve_details(self, request_mock): "get", "/v1/issuing/cards/%s/details" % TEST_RESOURCE_ID ) assert isinstance(card_details, stripe.issuing.CardDetails) + + def test_can_retrieve_details_classmethod(self, request_mock): + card_details = stripe.issuing.Card.details(TEST_RESOURCE_ID) + request_mock.assert_requested( + "get", "/v1/issuing/cards/%s/details" % TEST_RESOURCE_ID + ) + assert isinstance(card_details, stripe.issuing.CardDetails) diff --git a/tests/api_resources/test_account.py b/tests/api_resources/test_account.py index 7d1d6463e..771862448 100644 --- a/tests/api_resources/test_account.py +++ b/tests/api_resources/test_account.py @@ -96,11 +96,22 @@ def test_can_reject(self, request_mock): account = stripe.Account.retrieve(TEST_RESOURCE_ID) resource = account.reject(reason="fraud") request_mock.assert_requested( - "post", "/v1/accounts/%s/reject" % TEST_RESOURCE_ID + "post", + "/v1/accounts/%s/reject" % TEST_RESOURCE_ID, + {"reason": "fraud"}, ) assert isinstance(resource, stripe.Account) assert resource is account + def test_can_reject_classmethod(self, request_mock): + resource = stripe.Account.reject(TEST_RESOURCE_ID, reason="fraud") + request_mock.assert_requested( + "post", + "/v1/accounts/%s/reject" % TEST_RESOURCE_ID, + {"reason": "fraud"}, + ) + assert isinstance(resource, stripe.Account) + def test_is_deauthorizable(self, request_mock): account = stripe.Account.retrieve(TEST_RESOURCE_ID) request_mock.stub_request( diff --git a/tests/api_resources/test_charge.py b/tests/api_resources/test_charge.py index 9eb2e8d28..978a17cc3 100644 --- a/tests/api_resources/test_charge.py +++ b/tests/api_resources/test_charge.py @@ -52,7 +52,7 @@ def test_is_refundable(self, request_mock): ) assert isinstance(resource, stripe.Charge) - def test_is_capturable(self, request_mock): + def test_can_capture(self, request_mock): charge = stripe.Charge.retrieve(TEST_RESOURCE_ID) resource = charge.capture() request_mock.assert_requested( @@ -60,7 +60,7 @@ def test_is_capturable(self, request_mock): ) assert isinstance(resource, stripe.Charge) - def test_can_capture(self, request_mock): + def test_can_capture_classmethod(self, request_mock): resource = stripe.Charge.capture(TEST_RESOURCE_ID) request_mock.assert_requested( "post", "/v1/charges/%s/capture" % TEST_RESOURCE_ID diff --git a/tests/api_resources/test_customer.py b/tests/api_resources/test_customer.py index ef63df026..3f453015d 100644 --- a/tests/api_resources/test_customer.py +++ b/tests/api_resources/test_customer.py @@ -66,6 +66,12 @@ def test_can_delete_discount(self, request_mock): "delete", "/v1/customers/%s/discount" % TEST_RESOURCE_ID ) + def test_can_delete_discount_class_method(self, request_mock): + resource = stripe.Customer.delete_discount(TEST_RESOURCE_ID) + request_mock.assert_requested( + "delete", "/v1/customers/%s/discount" % TEST_RESOURCE_ID + ) + class TestCustomerSources(object): def test_is_creatable(self, request_mock): diff --git a/tests/api_resources/test_dispute.py b/tests/api_resources/test_dispute.py index 20236948b..83ccafe6b 100644 --- a/tests/api_resources/test_dispute.py +++ b/tests/api_resources/test_dispute.py @@ -37,9 +37,17 @@ def test_is_modifiable(self, request_mock): ) assert isinstance(resource, stripe.Dispute) - def test_is_closeable(self, request_mock): + def test_can_close(self, request_mock): resource = stripe.Dispute.retrieve(TEST_RESOURCE_ID) resource.close() request_mock.assert_requested( "post", "/v1/disputes/%s/close" % TEST_RESOURCE_ID ) + assert isinstance(resource, stripe.Dispute) + + def test_can_close_classmethod(self, request_mock): + resource = stripe.Dispute.close(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/disputes/%s/close" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.Dispute) diff --git a/tests/api_resources/test_order.py b/tests/api_resources/test_order.py index de8518de0..4f3686567 100644 --- a/tests/api_resources/test_order.py +++ b/tests/api_resources/test_order.py @@ -42,19 +42,37 @@ def test_is_modifiable(self, request_mock): ) assert isinstance(resource, stripe.Order) - def test_is_payable(self, request_mock): + def test_can_pay(self, request_mock): order = stripe.Order.retrieve(TEST_RESOURCE_ID) resource = order.pay(source="src_123") request_mock.assert_requested( - "post", "/v1/orders/%s/pay" % order.id, {"source": "src_123"} + "post", + "/v1/orders/%s/pay" % TEST_RESOURCE_ID, + {"source": "src_123"}, ) assert isinstance(resource, stripe.Order) assert resource is order - def test_is_returnable(self, request_mock): + def test_can_pay_classmethod(self, request_mock): + resource = stripe.Order.pay(TEST_RESOURCE_ID, source="src_123") + request_mock.assert_requested( + "post", + "/v1/orders/%s/pay" % TEST_RESOURCE_ID, + {"source": "src_123"}, + ) + assert isinstance(resource, stripe.Order) + + def test_can_return(self, request_mock): order = stripe.Order.retrieve(TEST_RESOURCE_ID) resource = order.return_order() request_mock.assert_requested( - "post", "/v1/orders/%s/returns" % order.id + "post", "/v1/orders/%s/returns" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.OrderReturn) + + def test_can_return_classmethod(self, request_mock): + resource = stripe.Order.return_order(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/orders/%s/returns" % TEST_RESOURCE_ID ) assert isinstance(resource, stripe.OrderReturn) diff --git a/tests/api_resources/test_payment_intent.py b/tests/api_resources/test_payment_intent.py index 0874fbf1f..05103a26d 100644 --- a/tests/api_resources/test_payment_intent.py +++ b/tests/api_resources/test_payment_intent.py @@ -52,27 +52,45 @@ def test_is_saveable(self, request_mock): def test_can_cancel(self, request_mock): resource = stripe.PaymentIntent.retrieve(TEST_RESOURCE_ID) - resource.cancel() request_mock.assert_requested( "post", "/v1/payment_intents/%s/cancel" % TEST_RESOURCE_ID ) assert isinstance(resource, stripe.PaymentIntent) + def test_can_cancel_classmethod(self, request_mock): + resource = stripe.PaymentIntent.cancel(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/payment_intents/%s/cancel" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.PaymentIntent) + def test_can_capture(self, request_mock): resource = stripe.PaymentIntent.retrieve(TEST_RESOURCE_ID) - resource.capture() request_mock.assert_requested( "post", "/v1/payment_intents/%s/capture" % TEST_RESOURCE_ID ) assert isinstance(resource, stripe.PaymentIntent) + def test_can_capture_classmethod(self, request_mock): + resource = stripe.PaymentIntent.capture(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/payment_intents/%s/capture" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.PaymentIntent) + def test_can_confirm(self, request_mock): resource = stripe.PaymentIntent.retrieve(TEST_RESOURCE_ID) - resource.confirm() request_mock.assert_requested( "post", "/v1/payment_intents/%s/confirm" % TEST_RESOURCE_ID ) assert isinstance(resource, stripe.PaymentIntent) + + def test_can_confirm_classmethod(self, request_mock): + resource = stripe.PaymentIntent.confirm(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/payment_intents/%s/confirm" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.PaymentIntent) diff --git a/tests/api_resources/test_payment_method.py b/tests/api_resources/test_payment_method.py index f9aea8cf2..5fafd9a3c 100644 --- a/tests/api_resources/test_payment_method.py +++ b/tests/api_resources/test_payment_method.py @@ -52,6 +52,17 @@ def test_can_attach(self, request_mock): ) assert isinstance(resource, stripe.PaymentMethod) + def test_can_attach_classmethod(self, request_mock): + resource = stripe.PaymentMethod.attach( + TEST_RESOURCE_ID, customer="cus_123" + ) + request_mock.assert_requested( + "post", + "/v1/payment_methods/%s/attach" % TEST_RESOURCE_ID, + {"customer": "cus_123"}, + ) + assert isinstance(resource, stripe.PaymentMethod) + def test_can_detach(self, request_mock): resource = stripe.PaymentMethod.retrieve(TEST_RESOURCE_ID) resource = resource.detach() @@ -59,3 +70,10 @@ def test_can_detach(self, request_mock): "post", "/v1/payment_methods/%s/detach" % TEST_RESOURCE_ID ) assert isinstance(resource, stripe.PaymentMethod) + + def test_can_detach_classmethod(self, request_mock): + resource = stripe.PaymentMethod.detach(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/payment_methods/%s/detach" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.PaymentMethod) diff --git a/tests/api_resources/test_payout.py b/tests/api_resources/test_payout.py index 0ca7233b6..e01f763cf 100644 --- a/tests/api_resources/test_payout.py +++ b/tests/api_resources/test_payout.py @@ -49,3 +49,10 @@ def test_can_cancel(self, request_mock): "post", "/v1/payouts/%s/cancel" % TEST_RESOURCE_ID ) assert isinstance(resource, stripe.Payout) + + def test_can_cancel_classmethod(self, request_mock): + resource = stripe.Payout.cancel(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/payouts/%s/cancel" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.Payout) diff --git a/tests/api_resources/test_review.py b/tests/api_resources/test_review.py index 24ef8dbc0..2d0c092d5 100644 --- a/tests/api_resources/test_review.py +++ b/tests/api_resources/test_review.py @@ -20,10 +20,17 @@ def test_is_retrievable(self, request_mock): ) assert isinstance(resource, stripe.Review) - def test_is_approveable(self, request_mock): + def test_can_approve(self, request_mock): resource = stripe.Review.retrieve(TEST_RESOURCE_ID) resource.approve() request_mock.assert_requested( "post", "/v1/reviews/%s/approve" % TEST_RESOURCE_ID ) assert isinstance(resource, stripe.Review) + + def test_can_approve_classmethod(self, request_mock): + resource = stripe.Review.approve(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/reviews/%s/approve" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.Review) diff --git a/tests/api_resources/test_subscription.py b/tests/api_resources/test_subscription.py index 649eb368e..ccdb6cbc3 100644 --- a/tests/api_resources/test_subscription.py +++ b/tests/api_resources/test_subscription.py @@ -63,3 +63,9 @@ def test_can_delete_discount(self, request_mock): request_mock.assert_requested( "delete", "/v1/subscriptions/%s/discount" % sub.id ) + + def test_can_delete_discount_classmethod(self, request_mock): + stripe.Subscription.delete_discount(TEST_RESOURCE_ID) + request_mock.assert_requested( + "delete", "/v1/subscriptions/%s/discount" % TEST_RESOURCE_ID + ) diff --git a/tests/api_resources/test_subscription_schedule.py b/tests/api_resources/test_subscription_schedule.py index e5a821147..a89b95e54 100644 --- a/tests/api_resources/test_subscription_schedule.py +++ b/tests/api_resources/test_subscription_schedule.py @@ -51,6 +51,13 @@ def test_can_cancel(self, request_mock): ) assert isinstance(resource, stripe.SubscriptionSchedule) + def test_can_cancel_classmethod(self, request_mock): + resource = stripe.SubscriptionSchedule.cancel(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/subscription_schedules/%s/cancel" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.SubscriptionSchedule) + def test_can_release(self, request_mock): resource = stripe.SubscriptionSchedule.retrieve(TEST_RESOURCE_ID) resource = resource.release() @@ -59,6 +66,13 @@ def test_can_release(self, request_mock): ) assert isinstance(resource, stripe.SubscriptionSchedule) + def test_can_release_classmethod(self, request_mock): + resource = stripe.SubscriptionSchedule.release(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/subscription_schedules/%s/release" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.SubscriptionSchedule) + class TestSubscriptionScheduleRevisions(object): def test_is_listable(self, request_mock): diff --git a/tests/api_resources/test_topup.py b/tests/api_resources/test_topup.py index 409149c64..e080ffaa5 100644 --- a/tests/api_resources/test_topup.py +++ b/tests/api_resources/test_topup.py @@ -48,9 +48,16 @@ def test_is_modifiable(self, request_mock): ) assert isinstance(resource, stripe.Topup) - def test_is_cancelable(self, request_mock): - topup = stripe.Topup.retrieve(TEST_RESOURCE_ID) - resource = topup.cancel() + def test_can_cancel(self, request_mock): + resource = stripe.Topup.retrieve(TEST_RESOURCE_ID) + resource = resource.cancel() + request_mock.assert_requested( + "post", "/v1/topups/%s/cancel" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.Topup) + + def test_can_cancel_classmethod(self, request_mock): + resource = stripe.Topup.cancel(TEST_RESOURCE_ID) request_mock.assert_requested( "post", "/v1/topups/%s/cancel" % TEST_RESOURCE_ID ) diff --git a/tests/api_resources/test_transfer.py b/tests/api_resources/test_transfer.py index d863f727e..4bd56fdf0 100644 --- a/tests/api_resources/test_transfer.py +++ b/tests/api_resources/test_transfer.py @@ -45,7 +45,7 @@ def test_is_modifiable(self, request_mock): ) assert isinstance(resource, stripe.Transfer) - def test_is_cancelable(self, request_mock): + def test_can_cancel(self, request_mock): # stripe-mock does not handle this anymore as it was on an old # API version so we stub instead. request_mock.stub_request( @@ -67,6 +67,20 @@ def test_is_cancelable(self, request_mock): ) assert isinstance(transfer_canceled, stripe.Transfer) + def test_can_cancel_classmethod(self, request_mock): + # stripe-mock does not handle this anymore as it was on an old + # API version so we stub instead. + request_mock.stub_request( + "post", + "/v1/transfers/%s/cancel" % TEST_RESOURCE_ID, + {"id": "%s" % TEST_RESOURCE_ID, "object": "transfer"}, + ) + transfer = stripe.Transfer.cancel(TEST_RESOURCE_ID) + request_mock.assert_requested( + "post", "/v1/transfers/%s/cancel" % TEST_RESOURCE_ID + ) + assert isinstance(transfer, stripe.Transfer) + class TestTransferReversals: def test_is_listable(self, request_mock):