Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for billing_portal namespace and Session resource and APIs #651

Merged
merged 2 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.76.0
- STRIPE_MOCK_VERSION=0.88.0

before_install:
# Unpack and start stripe-mock so that the test suite can talk to it
Expand Down
1 change: 1 addition & 0 deletions stripe/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from stripe.api_resources.error_object import ErrorObject, OAuthErrorObject
from stripe.api_resources.list_object import ListObject

from stripe.api_resources import billing_portal
from stripe.api_resources import checkout
from stripe.api_resources import issuing
from stripe.api_resources import radar
Expand Down
5 changes: 5 additions & 0 deletions stripe/api_resources/billing_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import absolute_import, division, print_function

# flake8: noqa

from stripe.api_resources.billing_portal.session import Session
7 changes: 7 additions & 0 deletions stripe/api_resources/billing_portal/session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource


class Session(CreateableAPIResource):
OBJECT_NAME = "billing_portal.session"
1 change: 1 addition & 0 deletions stripe/object_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
api_resources.Balance.OBJECT_NAME: api_resources.Balance,
api_resources.BalanceTransaction.OBJECT_NAME: api_resources.BalanceTransaction,
api_resources.BankAccount.OBJECT_NAME: api_resources.BankAccount,
api_resources.billing_portal.Session.OBJECT_NAME: api_resources.billing_portal.Session,
api_resources.BitcoinReceiver.OBJECT_NAME: api_resources.BitcoinReceiver,
api_resources.BitcoinTransaction.OBJECT_NAME: api_resources.BitcoinTransaction,
api_resources.Capability.OBJECT_NAME: api_resources.Capability,
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions tests/api_resources/billing_portal/test_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = "pts_123"


class TestSession(object):
def test_is_creatable(self, request_mock):
resource = stripe.billing_portal.Session.create(
customer="cus_123", return_url="https://stripe.com/return"
)
request_mock.assert_requested("post", "/v1/billing_portal/sessions")
assert isinstance(resource, stripe.billing_portal.Session)
Empty file.
Empty file.
20 changes: 18 additions & 2 deletions tests/api_resources/issuing/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,30 @@ def test_is_saveable(self, request_mock):
assert resource is card

def test_can_retrieve_details(self, request_mock):
resource = stripe.issuing.Card.retrieve(TEST_RESOURCE_ID)
card_details = resource.details()
# stripe-mock does not handle this anymore so we stub instead.
request_mock.stub_request(
"get",
"/v1/issuing/cards/%s/details" % TEST_RESOURCE_ID,
{"object": "issuing.card_details"},
)
card = stripe.issuing.Card.construct_from(
{"id": "%s" % TEST_RESOURCE_ID, "object": "issuing.card"},
stripe.api_key,
)
card_details = card.details()
request_mock.assert_requested(
"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):
# stripe-mock does not handle this anymore so we stub instead.
request_mock.stub_request(
"get",
"/v1/issuing/cards/%s/details" % TEST_RESOURCE_ID,
{"object": "issuing.card_details"},
)

card_details = stripe.issuing.Card.details(TEST_RESOURCE_ID)
request_mock.assert_requested(
"get", "/v1/issuing/cards/%s/details" % TEST_RESOURCE_ID
Expand Down
18 changes: 2 additions & 16 deletions tests/api_resources/issuing/test_dispute.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class TestDispute(object):
def test_is_creatable(self, request_mock):
resource = stripe.issuing.Dispute.create(
reason="fraudulent", disputed_transaction="ipi_123"
)
resource = stripe.issuing.Dispute.create()
request_mock.assert_requested("post", "/v1/issuing/disputes")
assert isinstance(resource, stripe.issuing.Dispute)

Expand All @@ -21,9 +19,7 @@ def test_is_listable(self, request_mock):
assert isinstance(resources.data[0], stripe.issuing.Dispute)

def test_is_modifiable(self, request_mock):
resource = stripe.issuing.Dispute.modify(
TEST_RESOURCE_ID, metadata={"key": "value"}
)
resource = stripe.issuing.Dispute.modify(TEST_RESOURCE_ID)
request_mock.assert_requested(
"post", "/v1/issuing/disputes/%s" % TEST_RESOURCE_ID
)
Expand All @@ -35,13 +31,3 @@ def test_is_retrievable(self, request_mock):
"get", "/v1/issuing/disputes/%s" % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Dispute)

def test_is_saveable(self, request_mock):
resource = stripe.issuing.Dispute.retrieve(TEST_RESOURCE_ID)
resource.metadata["key"] = "value"
dispute = resource.save()
request_mock.assert_requested(
"post", "/v1/issuing/disputes/%s" % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Dispute)
assert resource is dispute
Empty file.
Empty file.
Empty file.
Empty file.
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.76.0"
MOCK_MINIMUM_VERSION = "0.88.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