Skip to content

Commit

Permalink
Add tests and fix existing ones for the latest stripe-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Aug 5, 2020
1 parent 728d05b commit 1073eeb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/api_resources/test_account_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
43 changes: 43 additions & 0 deletions tests/api_resources/test_promotion_code.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 5 additions & 5 deletions tests/api_resources/test_subscription_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1073eeb

Please sign in to comment.