diff --git a/CHANGELOG b/CHANGELOG index 3dcd4887..109996ff 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +=== 3.5.0 2017-01-18 + +* Added basic CRUD methods for Webhook Objects +* Fixed Order test + + === 3.4.0 2016-12-20 * Added session pooling diff --git a/VERSION b/VERSION index 18091983..1545d966 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.4.0 +3.5.0 diff --git a/easypost/__init__.py b/easypost/__init__.py index c644bbde..bd2a1f48 100644 --- a/easypost/__init__.py +++ b/easypost/__init__.py @@ -82,7 +82,8 @@ def convert_to_easypost_object(response, api_key, parent=None, name=None): 'Report': Report, 'ShipmentReport': Report, 'PaymentLogReport': Report, - 'TrackerReport': Report + 'TrackerReport': Report, + 'Webhook': Webhook } prefixes = { @@ -106,7 +107,8 @@ def convert_to_easypost_object(response, api_key, parent=None, name=None): 'user': User, 'shprep': Report, 'plrep': Report, - 'trkrep': Report + 'trkrep': Report, + 'hook': Webhook } if isinstance(response, list): @@ -984,3 +986,12 @@ def retrieve(cls, easypost_id, api_key=None, **params): url = "%s/%s" % (cls.class_url(), easypost_id) response, api_key = requestor.request('get', url) return response["signed_url"] + + +class Webhook(AllResource, CreateResource, DeleteResource): + def update(self, **params): + requestor = Requestor(self.api_key) + url = self.instance_url() + response, api_key = requestor.request('put', url, params) + self.refresh_from(response, api_key) + return self diff --git a/easypost/version.py b/easypost/version.py index 3bbffbdc..8ee9c90b 100644 --- a/easypost/version.py +++ b/easypost/version.py @@ -1 +1 @@ -VERSION = '3.4.0' +VERSION = '3.5.0' diff --git a/tests/order.py b/tests/order.py index 82ed1b29..be5980d0 100644 --- a/tests/order.py +++ b/tests/order.py @@ -64,14 +64,15 @@ def test_order_create_then_buy(self): # Assert the shipment's parcel assert len(order.shipments) == 2 - assert order.shipments[0].parcel.height == parcel1['height'] - assert order.shipments[0].parcel.length == parcel1['length'] - assert order.shipments[0].parcel.width == parcel1['width'] - assert order.shipments[0].parcel.weight == parcel1['weight'] - assert order.shipments[1].parcel.height == 5.0 - assert order.shipments[1].parcel.length == 8.0 - assert order.shipments[1].parcel.width == 5.0 - assert order.shipments[1].parcel.weight == 16.0 + + assert order.shipments[1].parcel.height == parcel1['height'] + assert order.shipments[1].parcel.length == parcel1['length'] + assert order.shipments[1].parcel.width == parcel1['width'] + assert order.shipments[1].parcel.weight == parcel1['weight'] + assert order.shipments[0].parcel.height == 5.0 + assert order.shipments[0].parcel.length == 8.0 + assert order.shipments[0].parcel.width == 5.0 + assert order.shipments[0].parcel.weight == 16.0 order.buy(carrier='USPS', service='Priority') diff --git a/tests/webhook.py b/tests/webhook.py new file mode 100644 index 00000000..57bf8b56 --- /dev/null +++ b/tests/webhook.py @@ -0,0 +1,45 @@ +# Unit tests related to 'Webhook' (https://www.easypost.com/webhooks-guide). + +import unittest +import easypost +from constants import API_KEY as api_key + +easypost.api_key = api_key + + +class WebhookTests(unittest.TestCase): + + def test_webhooks(self): + # Create a webhook + webhook = easypost.Webhook.create(url="example.com") + assert webhook.id is not None + assert webhook.mode == "test" + assert webhook.url == "http://example.com" + assert webhook.disabled_at is None + assert type(webhook) == easypost.Webhook + + # Retrieve a webhook + webhook2 = easypost.Webhook.retrieve(webhook.id) + assert webhook2.id is not None + assert webhook2.id == webhook.id + + # Update a webhook (re-enable it) + webhook3 = webhook.update() + assert webhook3.id is not None + assert webhook3.id == webhook.id + + # Index webhooks + webhooks = easypost.Webhook.all() + assert webhooks["webhooks"][len(webhooks["webhooks"]) - 1].id == webhook.id + + # Delete a webhook + webhook.delete() + try: + easypost.Webhook.retrieve(webhook.id) + except easypost.Error as e: + assert e.http_status == 404 + assert e.message == "The requested resource could not be found." + + +if __name__ == '__main__': + unittest.main()