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 the Webhook Endpoint resource #484

Merged
merged 1 commit into from
Oct 30, 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 @@ -53,3 +53,4 @@
from stripe.api_resources.transfer import Transfer
from stripe.api_resources.usage_record import UsageRecord
from stripe.api_resources.usage_record_summary import UsageRecordSummary
from stripe.api_resources.webhook_endpoint import WebhookEndpoint
11 changes: 11 additions & 0 deletions stripe/api_resources/webhook_endpoint.py
Original file line number Diff line number Diff line change
@@ -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 DeletableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class WebhookEndpoint(CreateableAPIResource, UpdateableAPIResource,
DeletableAPIResource, ListableAPIResource):
OBJECT_NAME = 'webhook_endpoint'
2 changes: 2 additions & 0 deletions stripe/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def load_object_classes():
api_resources.UsageRecord.OBJECT_NAME: api_resources.UsageRecord,
api_resources.UsageRecordSummary.OBJECT_NAME:
api_resources.UsageRecordSummary,
api_resources.WebhookEndpoint.OBJECT_NAME:
api_resources.WebhookEndpoint,
api_resources.terminal.Location.OBJECT_NAME:
api_resources.terminal.Location,
api_resources.terminal.ConnectionToken.OBJECT_NAME:
Expand Down
65 changes: 65 additions & 0 deletions tests/api_resources/test_webhook_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = 'we_123'


class TestWebhookEndpoint(object):
def test_is_listable(self, request_mock):
resources = stripe.WebhookEndpoint.list()
request_mock.assert_requested(
'get',
'/v1/webhook_endpoints'
)
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], stripe.WebhookEndpoint)

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

def test_is_creatable(self, request_mock):
resource = stripe.WebhookEndpoint.create(
enabled_events=['charge.succeeded'],
url='https://stripe.com'
)
request_mock.assert_requested(
'post',
'/v1/webhook_endpoints'
)
assert isinstance(resource, stripe.WebhookEndpoint)

def test_is_saveable(self, request_mock):
resource = stripe.WebhookEndpoint.retrieve(TEST_RESOURCE_ID)
resource.enabled_events = ['charge.succeeded']
resource.save()
request_mock.assert_requested(
'post',
'/v1/webhook_endpoints/%s' % TEST_RESOURCE_ID
)

def test_is_modifiable(self, request_mock):
resource = stripe.WebhookEndpoint.modify(
TEST_RESOURCE_ID,
enabled_events=['charge.succeeded']
)
request_mock.assert_requested(
'post',
'/v1/webhook_endpoints/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.WebhookEndpoint)

def test_is_deletable(self, request_mock):
resource = stripe.WebhookEndpoint.retrieve(TEST_RESOURCE_ID)
resource.delete()
request_mock.assert_requested(
'delete',
'/v1/webhook_endpoints/%s' % TEST_RESOURCE_ID
)
assert resource.deleted is True