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

Bindings for Terminal endpoints #478

Merged
merged 3 commits into from
Sep 24, 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cache:
env:
global:
# If changing this number, please also change it in `tests/conftest.py`.
- STRIPE_MOCK_VERSION=0.32.0
- STRIPE_MOCK_VERSION=0.33.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/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from stripe.api_resources import issuing # noqa
from stripe.api_resources import reporting # noqa
from stripe.api_resources import sigma # noqa
from stripe.api_resources import terminal # noqa

# OAuth
from stripe.oauth import OAuth # noqa
Expand Down
7 changes: 7 additions & 0 deletions stripe/api_resources/terminal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import absolute_import, division, print_function

# flake8: noqa

from stripe.api_resources.terminal.connection_token import ConnectionToken
from stripe.api_resources.terminal.location import Location
from stripe.api_resources.terminal.reader import Reader
7 changes: 7 additions & 0 deletions stripe/api_resources/terminal/connection_token.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 ConnectionToken(CreateableAPIResource):
OBJECT_NAME = 'terminal.connection_token'
10 changes: 10 additions & 0 deletions stripe/api_resources/terminal/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class Location(CreateableAPIResource, ListableAPIResource,
UpdateableAPIResource):
OBJECT_NAME = 'terminal.location'
10 changes: 10 additions & 0 deletions stripe/api_resources/terminal/reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class Reader(CreateableAPIResource, ListableAPIResource,
UpdateableAPIResource):
OBJECT_NAME = 'terminal.reader'
6 changes: 6 additions & 0 deletions stripe/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ def load_object_classes():
api_resources.UsageRecord.OBJECT_NAME: api_resources.UsageRecord,
api_resources.UsageRecordSummary.OBJECT_NAME:
api_resources.UsageRecordSummary,
api_resources.terminal.Location.OBJECT_NAME:
api_resources.terminal.Location,
api_resources.terminal.ConnectionToken.OBJECT_NAME:
api_resources.terminal.ConnectionToken,
api_resources.terminal.Reader.OBJECT_NAME:
api_resources.terminal.Reader,
}


Expand Down
16 changes: 16 additions & 0 deletions tests/api_resources/terminal/test_connection_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = 'rdr_123'


class TestConnectionToken(object):
def test_is_creatable(self, request_mock):
resource = stripe.terminal.ConnectionToken.create()
request_mock.assert_requested(
'post',
'/v1/terminal/connection_tokens'
)
assert isinstance(resource, stripe.terminal.ConnectionToken)
64 changes: 64 additions & 0 deletions tests/api_resources/terminal/test_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = 'loc_123'


class TestLocation(object):
def test_is_creatable(self, request_mock):
resource = stripe.terminal.Location.create(
display_name='name',
address={
'line1': 'line1',
'country': 'US',
'state': 'CA',
'postal_code': '12345',
'city': 'San Francisco',
}
)
request_mock.assert_requested(
'post',
'/v1/terminal/locations'
)
assert isinstance(resource, stripe.terminal.Location)

def test_is_listable(self, request_mock):
resources = stripe.terminal.Location.list()
request_mock.assert_requested(
'get',
'/v1/terminal/locations'
)
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], stripe.terminal.Location)

def test_is_modifiable(self, request_mock):
resource = stripe.terminal.Location.modify(
TEST_RESOURCE_ID,
display_name='new-name'
)
request_mock.assert_requested(
'post',
'/v1/terminal/locations/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.terminal.Location)

def test_is_retrievable(self, request_mock):
resource = stripe.terminal.Location.retrieve(TEST_RESOURCE_ID)
request_mock.assert_requested(
'get',
'/v1/terminal/locations/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.terminal.Location)

def test_is_saveable(self, request_mock):
resource = stripe.terminal.Location.retrieve(TEST_RESOURCE_ID)
resource.display_name = 'new-name'
location = resource.save()
request_mock.assert_requested(
'post',
'/v1/terminal/locations/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.terminal.Location)
assert resource is location
58 changes: 58 additions & 0 deletions tests/api_resources/terminal/test_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = 'rdr_123'


class TestReader(object):
def test_is_creatable(self, request_mock):
resource = stripe.terminal.Reader.create(
registration_code='a-b-c',
label='name'
)
request_mock.assert_requested(
'post',
'/v1/terminal/readers'
)
assert isinstance(resource, stripe.terminal.Reader)

def test_is_listable(self, request_mock):
resources = stripe.terminal.Reader.list()
request_mock.assert_requested(
'get',
'/v1/terminal/readers'
)
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], stripe.terminal.Reader)

def test_is_modifiable(self, request_mock):
resource = stripe.terminal.Reader.modify(
TEST_RESOURCE_ID,
label='new-name'
)
request_mock.assert_requested(
'post',
'/v1/terminal/readers/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.terminal.Reader)

def test_is_retrievable(self, request_mock):
resource = stripe.terminal.Reader.retrieve(TEST_RESOURCE_ID)
request_mock.assert_requested(
'get',
'/v1/terminal/readers/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.terminal.Reader)

def test_is_saveable(self, request_mock):
resource = stripe.terminal.Reader.retrieve(TEST_RESOURCE_ID)
resource.label = 'new-name'
reader = resource.save()
request_mock.assert_requested(
'post',
'/v1/terminal/readers/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.terminal.Reader)
assert resource is reader
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tests.request_mock import RequestMock


MOCK_MINIMUM_VERSION = '0.32.0'
MOCK_MINIMUM_VERSION = '0.33.0'
MOCK_PORT = os.environ.get('STRIPE_MOCK_PORT', 12111)


Expand Down