From 728d05bc350071deb425ffa506280720b58cd2c2 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 4 Aug 2020 18:31:17 -0700 Subject: [PATCH 1/2] Codegen for openapi f71053e (without incorrect File changes) --- stripe/api_resources/__init__.py | 1 + stripe/api_resources/promotion_code.py | 11 +++++++++++ stripe/object_classes.py | 1 + 3 files changed, 13 insertions(+) create mode 100644 stripe/api_resources/promotion_code.py diff --git a/stripe/api_resources/__init__.py b/stripe/api_resources/__init__.py index 32a514110..a9796ebc1 100644 --- a/stripe/api_resources/__init__.py +++ b/stripe/api_resources/__init__.py @@ -58,6 +58,7 @@ from stripe.api_resources.plan import Plan from stripe.api_resources.price import Price from stripe.api_resources.product import Product +from stripe.api_resources.promotion_code import PromotionCode from stripe.api_resources.recipient import Recipient from stripe.api_resources.recipient_transfer import RecipientTransfer from stripe.api_resources.refund import Refund diff --git a/stripe/api_resources/promotion_code.py b/stripe/api_resources/promotion_code.py new file mode 100644 index 000000000..5db6e749b --- /dev/null +++ b/stripe/api_resources/promotion_code.py @@ -0,0 +1,11 @@ +from __future__ import absolute_import, division, print_function + +from stripe.api_resources.abstract import CreateableAPIResource +from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import UpdateableAPIResource + + +class PromotionCode( + CreateableAPIResource, ListableAPIResource, UpdateableAPIResource +): + OBJECT_NAME = "promotion_code" diff --git a/stripe/object_classes.py b/stripe/object_classes.py index 7c8f11704..2d63dc218 100644 --- a/stripe/object_classes.py +++ b/stripe/object_classes.py @@ -58,6 +58,7 @@ api_resources.Plan.OBJECT_NAME: api_resources.Plan, api_resources.Price.OBJECT_NAME: api_resources.Price, api_resources.Product.OBJECT_NAME: api_resources.Product, + api_resources.PromotionCode.OBJECT_NAME: api_resources.PromotionCode, api_resources.radar.EarlyFraudWarning.OBJECT_NAME: api_resources.radar.EarlyFraudWarning, api_resources.radar.ValueList.OBJECT_NAME: api_resources.radar.ValueList, api_resources.radar.ValueListItem.OBJECT_NAME: api_resources.radar.ValueListItem, From 1073eebf726420b3794dca4f60f20146abb8b4a7 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 4 Aug 2020 18:48:13 -0700 Subject: [PATCH 2/2] Add tests and fix existing ones for the latest stripe-mock --- .travis.yml | 2 +- tests/api_resources/test_account_link.py | 2 +- tests/api_resources/test_promotion_code.py | 43 +++++++++++++++++++ tests/api_resources/test_subscription_item.py | 10 ++--- tests/conftest.py | 2 +- 5 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 tests/api_resources/test_promotion_code.py diff --git a/.travis.yml b/.travis.yml index e66959aaa..37868b3db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ cache: env: global: # If changing this number, please also change it in `tests/conftest.py`. - - STRIPE_MOCK_VERSION=0.93.0 + - STRIPE_MOCK_VERSION=0.95.0 before_install: # Unpack and start stripe-mock so that the test suite can talk to it diff --git a/tests/api_resources/test_account_link.py b/tests/api_resources/test_account_link.py index b4c5f9376..8f8a59f04 100644 --- a/tests/api_resources/test_account_link.py +++ b/tests/api_resources/test_account_link.py @@ -9,7 +9,7 @@ def test_is_creatable(self, request_mock): account="acct_123", refresh_url="https://stripe.com/failure", return_url="https://stripe.com/success", - type="custom_account_verification", + type="account_onboarding", ) request_mock.assert_requested("post", "/v1/account_links") assert isinstance(resource, stripe.AccountLink) diff --git a/tests/api_resources/test_promotion_code.py b/tests/api_resources/test_promotion_code.py new file mode 100644 index 000000000..397cf34cd --- /dev/null +++ b/tests/api_resources/test_promotion_code.py @@ -0,0 +1,43 @@ +from __future__ import absolute_import, division, print_function + +import stripe + + +TEST_RESOURCE_ID = "promo_123" + + +class TestPromotionCode(object): + def test_is_listable(self, request_mock): + resources = stripe.PromotionCode.list() + request_mock.assert_requested("get", "/v1/promotion_codes") + assert isinstance(resources.data, list) + assert isinstance(resources.data[0], stripe.PromotionCode) + + def test_is_retrievable(self, request_mock): + resource = stripe.PromotionCode.retrieve(TEST_RESOURCE_ID) + request_mock.assert_requested( + "get", "/v1/promotion_codes/%s" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.PromotionCode) + + def test_is_creatable(self, request_mock): + resource = stripe.PromotionCode.create(coupon="co_123", code="MYCODE") + request_mock.assert_requested("post", "/v1/promotion_codes") + assert isinstance(resource, stripe.PromotionCode) + + def test_is_saveable(self, request_mock): + resource = stripe.PromotionCode.retrieve(TEST_RESOURCE_ID) + resource.metadata["key"] = "value" + resource.save() + request_mock.assert_requested( + "post", "/v1/promotion_codes/%s" % TEST_RESOURCE_ID + ) + + def test_is_modifiable(self, request_mock): + resource = stripe.PromotionCode.modify( + TEST_RESOURCE_ID, metadata={"key": "value"} + ) + request_mock.assert_requested( + "post", "/v1/promotion_codes/%s" % TEST_RESOURCE_ID + ) + assert isinstance(resource, stripe.PromotionCode) diff --git a/tests/api_resources/test_subscription_item.py b/tests/api_resources/test_subscription_item.py index f74d71f1c..72d1e543d 100644 --- a/tests/api_resources/test_subscription_item.py +++ b/tests/api_resources/test_subscription_item.py @@ -24,29 +24,29 @@ def test_is_retrievable(self, request_mock): def test_is_creatable(self, request_mock): resource = stripe.SubscriptionItem.create( - plan="plan", subscription="sub_123" + price="price_123", subscription="sub_123" ) request_mock.assert_requested("post", "/v1/subscription_items") assert isinstance(resource, stripe.SubscriptionItem) def test_is_saveable(self, request_mock): resource = stripe.SubscriptionItem.retrieve(TEST_RESOURCE_ID) - resource.plan = "plan" + resource.price = "price_123" resource.save() request_mock.assert_requested( "post", "/v1/subscription_items/%s" % TEST_RESOURCE_ID, - {"plan": "plan"}, + {"price": "price_123"}, ) def test_is_modifiable(self, request_mock): resource = stripe.SubscriptionItem.modify( - TEST_RESOURCE_ID, plan="plan" + TEST_RESOURCE_ID, price="price_123" ) request_mock.assert_requested( "post", "/v1/subscription_items/%s" % TEST_RESOURCE_ID, - {"plan": "plan"}, + {"price": "price_123"}, ) assert isinstance(resource, stripe.SubscriptionItem) diff --git a/tests/conftest.py b/tests/conftest.py index 814a7148b..da371ad24 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,7 +16,7 @@ # When changing this number, don't forget to change it in `.travis.yml` too. -MOCK_MINIMUM_VERSION = "0.93.0" +MOCK_MINIMUM_VERSION = "0.95.0" # Starts stripe-mock if an OpenAPI spec override is found in `openapi/`, and # otherwise fall back to `STRIPE_MOCK_PORT` or 12111.