Skip to content

Commit e2fdcab

Browse files
authored
Merge pull request #454 from Shopify/melaniewpaulinak/add-fulfillment-event
Melaniewpaulinak/add fulfillment event
2 parents 60d6c23 + 1e855a7 commit e2fdcab

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- Added support for Fulfillment.update_tracking ([#432](https://github.com/Shopify/shopify_python_api/pull/432))
2+
- Add FulfillmentEvent resource ([#454](https://github.com/Shopify/shopify_python_api/pull/454))
23

34
== Version 8.2.0
45
- [Feature] Add support for Dynamic API Versioning. When the library is initialized, it will now make a request to

shopify/resources/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from .country import Country
3939
from .refund import Refund
4040
from .fulfillment import Fulfillment, FulfillmentOrders
41+
from .fulfillment_event import FulfillmentEvent
4142
from .fulfillment_service import FulfillmentService
4243
from .carrier_service import CarrierService
4344
from .transaction import Transaction
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from ..base import ShopifyResource
2+
3+
class FulfillmentEvent(ShopifyResource):
4+
_prefix_source = "/orders/$order_id/fulfillments/$fulfillment_id/"
5+
_singular = 'event'
6+
_plural = 'events'
7+
8+
@classmethod
9+
def _prefix(cls, options={}):
10+
order_id = options.get("order_id")
11+
fulfillment_id = options.get('fulfillment_id')
12+
event_id = options.get("event_id")
13+
14+
return "%s/orders/%s/fulfillments/%s" % (
15+
cls.site, order_id, fulfillment_id)
16+
17+
def save(self):
18+
status = self.attributes['status']
19+
if status not in ['label_printed', 'label_purchased', 'attempted_delivery', 'ready_for_pickup', 'picked_up', 'confirmed', 'in_transit', 'out_for_delivery', 'delivered', 'failure']:
20+
raise AttributeError("Invalid status")
21+
return super(ShopifyResource, self).save()

test/fixtures/fulfillment_event.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"fulfillment_event": {
3+
"id": 12584341209251,
4+
"fulfillment_id": 2608403447971,
5+
"status": "label_printed",
6+
"message": null,
7+
"happened_at": "2021-01-25T16:32:23-05:00",
8+
"city": null,
9+
"province": null,
10+
"country": null,
11+
"zip": null,
12+
"address1": null,
13+
"latitude": null,
14+
"longitude": null,
15+
"shop_id": 49144037539,
16+
"created_at": "2021-01-25T16:32:23-05:00",
17+
"updated_at": "2021-01-25T16:32:23-05:00",
18+
"estimated_delivery_at": null,
19+
"order_id": 2776493818019,
20+
"admin_graphql_api_id": "gid://shopify/FulfillmentEvent/12584341209251"
21+
}
22+
}

test/fulfillment_event_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import shopify
2+
from test.test_helper import TestCase
3+
from pyactiveresource.activeresource import ActiveResource
4+
5+
class FulFillmentEventTest(TestCase):
6+
def test_get_fulfillment_event(self):
7+
self.fake("orders/2776493818019/fulfillments/2608403447971/events", method='GET', body=self.load_fixture('fulfillment_event'))
8+
fulfillment_event = shopify.FulfillmentEvent.find(order_id=2776493818019, fulfillment_id=2608403447971)
9+
self.assertEqual(1, len(fulfillment_event))
10+
11+
def test_create_fulfillment_event(self):
12+
self.fake("orders/2776493818019/fulfillments/2608403447971/events", method='POST', body=self.load_fixture('fulfillment_event'), headers={'Content-type': 'application/json'})
13+
new_fulfillment_event = shopify.FulfillmentEvent({'order_id': '2776493818019', 'fulfillment_id': '2608403447971'})
14+
new_fulfillment_event.status = 'ready_for_pickup'
15+
new_fulfillment_event.save()
16+
17+
def test_error_on_incorrect_status(self):
18+
with self.assertRaises(AttributeError):
19+
self.fake("orders/2776493818019/fulfillments/2608403447971/events/12584341209251", method='GET', body=self.load_fixture('fulfillment_event'))
20+
incorrect_status = 'asdf'
21+
fulfillment_event = shopify.FulfillmentEvent.find(12584341209251, order_id='2776493818019', fulfillment_id='2608403447971')
22+
fulfillment_event.status = incorrect_status
23+
fulfillment_event.save()
24+

0 commit comments

Comments
 (0)