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 /v1/topups endpoints #396

Merged
merged 1 commit into from
Feb 21, 2018
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
1 change: 1 addition & 0 deletions stripe/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
from stripe.api_resources.subscription_item import SubscriptionItem
from stripe.api_resources.three_d_secure import ThreeDSecure
from stripe.api_resources.token import Token
from stripe.api_resources.topup import Topup
from stripe.api_resources.transfer import Transfer
7 changes: 7 additions & 0 deletions stripe/api_resources/topup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Extra line here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the style used in other files, so I copied. I'll leave it as is to maintain consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a little weird coming from other languages, but believe it or not, this is conformant with the most universally accepted style for Python, PEP 8. From the spec:

Surround top-level function and class definitions with two blank lines.

There's a check that will fail the test suite if the style is off, so you're safe from pulling something in that's wrong, but I'd suggest as a general guideline just doing what Jamu did and copying the style seen elsewhere.

class Topup(CreateableAPIResource, ListableAPIResource, UpdateableAPIResource):
OBJECT_NAME = 'topup'
1 change: 1 addition & 0 deletions stripe/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def load_object_classes():
api_resources.SubscriptionItem,
api_resources.ThreeDSecure.OBJECT_NAME: api_resources.ThreeDSecure,
api_resources.Token.OBJECT_NAME: api_resources.Token,
api_resources.Topup.OBJECT_NAME: api_resources.Topup,
api_resources.Transfer.OBJECT_NAME: api_resources.Transfer,
}

Expand Down
58 changes: 58 additions & 0 deletions tests/api_resources/test_topup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import stripe
from tests.helper import StripeTestCase


TEST_RESOURCE_ID = 'tu_123'


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unnecessary extra lines?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Similarly to the comment above, I believe PEP 8 will require this doubled up blank line too.)

class TopupTest(StripeTestCase):
def test_is_listable(self):
resources = stripe.Topup.list()
self.assert_requested(
'get',
'/v1/topups'
)
self.assertIsInstance(resources.data, list)
self.assertIsInstance(resources.data[0], stripe.Topup)

def test_is_retrievable(self):
resource = stripe.Topup.retrieve(TEST_RESOURCE_ID)
self.assert_requested(
'get',
'/v1/topups/%s' % TEST_RESOURCE_ID
)
self.assertIsInstance(resource, stripe.Topup)

def test_is_creatable(self):
resource = stripe.Topup.create(
amount=100,
currency='usd',
source='src_123',
description='description',
statement_descriptor='statement descriptor'
)
self.assert_requested(
'post',
'/v1/topups'
)
self.assertIsInstance(resource, stripe.Topup)

def test_is_saveable(self):
resource = stripe.Topup.retrieve(TEST_RESOURCE_ID)
resource.metadata['key'] = 'value'
resource.save()
self.assert_requested(
'post',
'/v1/topups/%s' % resource.id
)

def test_is_modifiable(self):
resource = stripe.Topup.modify(
TEST_RESOURCE_ID,
metadata={'key': 'value'}
)
self.assert_requested(
'post',
'/v1/topups/%s' % TEST_RESOURCE_ID
)
self.assertIsInstance(resource, stripe.Topup)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth checking the resource has its metadata set to {'key': 'value'}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this, but it looks like stripe-mock doesn't actually mutate received data correctly. I believe it just validates what it received and returns stock data.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's correct Jamu. We want to fix this at some point, but for now it's not working checking any of the data that you get back.