From 69321b29cfd4bca84be037400a77caa226b95f06 Mon Sep 17 00:00:00 2001 From: Melanie Wang Date: Wed, 11 Nov 2020 15:37:59 -0500 Subject: [PATCH 1/3] Add update_tracking --- shopify/resources/fulfillment.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index c0b5e7e7..82d5c66e 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -1,4 +1,5 @@ from ..base import ShopifyResource +import json class Fulfillment(ShopifyResource): @@ -13,6 +14,24 @@ def complete(self): def open(self): self._load_attributes_from_response(self.post("open")) + def update_tracking(self, tracking_info, notify_customer): + fulfill = FulfillmentV2() + fulfill.id = self.id + fulfill.update_tracking(tracking_info, notify_customer) + class FulfillmentOrders(ShopifyResource): _prefix_source = "/orders/$order_id/" + +class FulfillmentV2(ShopifyResource): + _singular = 'fulfillment' + _plural = 'fulfillments' + + def update_tracking(self, tracking_info, notify_customer): + body = { + "fulfillment": { + "tracking_info": tracking_info, + "notify_customer": notify_customer + } + } + self._load_attributes_from_response(self.post("update_tracking", json.dumps(body).encode())) From 58462b43b3ae5c8e8ba76c6f91a82d8ce802baf9 Mon Sep 17 00:00:00 2001 From: Melanie Wang Date: Wed, 11 Nov 2020 16:42:16 -0500 Subject: [PATCH 2/3] Add tests for update_tracking --- shopify/resources/fulfillment.py | 4 ++-- test/fixtures/fulfillment.json | 4 ++-- test/fulfillment_test.py | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index 82d5c66e..39277acc 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -17,7 +17,7 @@ def open(self): def update_tracking(self, tracking_info, notify_customer): fulfill = FulfillmentV2() fulfill.id = self.id - fulfill.update_tracking(tracking_info, notify_customer) + self._load_attributes_from_response(fulfill.update_tracking(tracking_info, notify_customer)) class FulfillmentOrders(ShopifyResource): @@ -34,4 +34,4 @@ def update_tracking(self, tracking_info, notify_customer): "notify_customer": notify_customer } } - self._load_attributes_from_response(self.post("update_tracking", json.dumps(body).encode())) + return self.post("update_tracking", json.dumps(body).encode()) diff --git a/test/fixtures/fulfillment.json b/test/fixtures/fulfillment.json index 9d7e04d3..6d8bd9e8 100644 --- a/test/fixtures/fulfillment.json +++ b/test/fixtures/fulfillment.json @@ -5,7 +5,7 @@ "order_id": 450789469, "service": "manual", "status": "pending", - "tracking_company": null, + "tracking_company": "null-company", "updated_at": "2013-11-01T16:06:08-04:00", "tracking_number": "1Z2345", "tracking_numbers": [ @@ -46,4 +46,4 @@ } ] } -} \ No newline at end of file +} diff --git a/test/fulfillment_test.py b/test/fulfillment_test.py index 20034fb1..7b88623f 100644 --- a/test/fulfillment_test.py +++ b/test/fulfillment_test.py @@ -3,7 +3,7 @@ from pyactiveresource.activeresource import ActiveResource class FulFillmentTest(TestCase): - + def setUp(self): super(FulFillmentTest, self).setUp() self.fake("orders/450789469/fulfillments/255858046", method='GET', body=self.load_fixture('fulfillment')) @@ -40,3 +40,24 @@ def test_able_to_cancel_fulfillment(self): self.assertEqual('pending', fulfillment.status) fulfillment.cancel() self.assertEqual('cancelled', fulfillment.status) + + def test_update_tracking(self): + fulfillment = shopify.Fulfillment.find(255858046, order_id=450789469) + + tracking_info = { "number": 1111, "url": "http://www.my-url.com", "company": "my-company"} + notify_customer = False + + update_tracking = self.load_fixture('fulfillment') + update_tracking = update_tracking.replace(b'null-company', b'my-company') + update_tracking = update_tracking.replace(b'http://www.google.com/search?q=1Z2345', b'http://www.my-url.com') + update_tracking = update_tracking.replace(b'1Z2345', b'1111') + + self.fake("fulfillments/255858046/update_tracking", method="POST", headers={'Content-type': 'application/json'}, body=update_tracking) + + self.assertEqual("null-company", fulfillment.tracking_company) + self.assertEqual("1Z2345", fulfillment.tracking_number) + self.assertEqual("http://www.google.com/search?q=1Z2345", fulfillment.tracking_url) + fulfillment.update_tracking(tracking_info, notify_customer) + self.assertEqual("my-company", fulfillment.tracking_company) + self.assertEqual('1111', fulfillment.tracking_number) + self.assertEqual('http://www.my-url.com', fulfillment.tracking_url) From d837bfd19ac4e306a7d377e0573a9b922aac1c0d Mon Sep 17 00:00:00 2001 From: Melanie Wang Date: Wed, 11 Nov 2020 16:56:12 -0500 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 254379c3..9a958f31 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +- Added support for Fulfillment.update_tracking ([#432](https://github.com/Shopify/shopify_python_api/pull/432)) + == Version 8.2.0 - [Feature] Add support for Dynamic API Versioning. When the library is initialized, it will now make a request to Shopify to fetch a list of the available API versions. ([#441](https://github.com/Shopify/shopify_python_api/pull/441))