Skip to content

Commit 58462b4

Browse files
committed
Add tests for update_tracking
1 parent 69321b2 commit 58462b4

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

shopify/resources/fulfillment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def open(self):
1717
def update_tracking(self, tracking_info, notify_customer):
1818
fulfill = FulfillmentV2()
1919
fulfill.id = self.id
20-
fulfill.update_tracking(tracking_info, notify_customer)
20+
self._load_attributes_from_response(fulfill.update_tracking(tracking_info, notify_customer))
2121

2222

2323
class FulfillmentOrders(ShopifyResource):
@@ -34,4 +34,4 @@ def update_tracking(self, tracking_info, notify_customer):
3434
"notify_customer": notify_customer
3535
}
3636
}
37-
self._load_attributes_from_response(self.post("update_tracking", json.dumps(body).encode()))
37+
return self.post("update_tracking", json.dumps(body).encode())

test/fixtures/fulfillment.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"order_id": 450789469,
66
"service": "manual",
77
"status": "pending",
8-
"tracking_company": null,
8+
"tracking_company": "null-company",
99
"updated_at": "2013-11-01T16:06:08-04:00",
1010
"tracking_number": "1Z2345",
1111
"tracking_numbers": [
@@ -46,4 +46,4 @@
4646
}
4747
]
4848
}
49-
}
49+
}

test/fulfillment_test.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pyactiveresource.activeresource import ActiveResource
44

55
class FulFillmentTest(TestCase):
6-
6+
77
def setUp(self):
88
super(FulFillmentTest, self).setUp()
99
self.fake("orders/450789469/fulfillments/255858046", method='GET', body=self.load_fixture('fulfillment'))
@@ -40,3 +40,24 @@ def test_able_to_cancel_fulfillment(self):
4040
self.assertEqual('pending', fulfillment.status)
4141
fulfillment.cancel()
4242
self.assertEqual('cancelled', fulfillment.status)
43+
44+
def test_update_tracking(self):
45+
fulfillment = shopify.Fulfillment.find(255858046, order_id=450789469)
46+
47+
tracking_info = { "number": 1111, "url": "http://www.my-url.com", "company": "my-company"}
48+
notify_customer = False
49+
50+
update_tracking = self.load_fixture('fulfillment')
51+
update_tracking = update_tracking.replace(b'null-company', b'my-company')
52+
update_tracking = update_tracking.replace(b'http://www.google.com/search?q=1Z2345', b'http://www.my-url.com')
53+
update_tracking = update_tracking.replace(b'1Z2345', b'1111')
54+
55+
self.fake("fulfillments/255858046/update_tracking", method="POST", headers={'Content-type': 'application/json'}, body=update_tracking)
56+
57+
self.assertEqual("null-company", fulfillment.tracking_company)
58+
self.assertEqual("1Z2345", fulfillment.tracking_number)
59+
self.assertEqual("http://www.google.com/search?q=1Z2345", fulfillment.tracking_url)
60+
fulfillment.update_tracking(tracking_info, notify_customer)
61+
self.assertEqual("my-company", fulfillment.tracking_company)
62+
self.assertEqual('1111', fulfillment.tracking_number)
63+
self.assertEqual('http://www.my-url.com', fulfillment.tracking_url)

0 commit comments

Comments
 (0)