Skip to content

Commit 006e3e6

Browse files
committed
Add optional customer.orders() support with tests
1 parent 31dfa86 commit 006e3e6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

shopify/resources/customer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ..base import ShopifyResource
22
from shopify import mixins
33
from .customer_invite import CustomerInvite
4+
from .order import Order
45

56

67
class Customer(ShopifyResource, mixins.Metafields):
@@ -24,3 +25,6 @@ def search(cls, **kwargs):
2425
def send_invite(self, customer_invite=CustomerInvite()):
2526
resource = self.post("send_invite", customer_invite.encode())
2627
return CustomerInvite(Customer.format.decode(resource.body))
28+
29+
def orders(self):
30+
return Order.find(customer_id=self.id)

test/customer_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,12 @@ def test_send_invite_with_params(self):
5353
self.assertEqual(customer_invite, json.loads(self.http.request.data.decode("utf-8")))
5454
self.assertIsInstance(customer_invite_response, shopify.CustomerInvite)
5555
self.assertEqual(customer_invite['customer_invite']['to'], customer_invite_response.to)
56+
57+
def test_get_customer_orders(self):
58+
self.fake('customers/207119551', method='GET', body=self.load_fixture('customer'))
59+
customer = shopify.Customer.find(207119551)
60+
self.fake('customers/207119551/orders', method='GET', body=self.load_fixture('orders'))
61+
orders = customer.orders()
62+
self.assertIsInstance(orders[0], shopify.Order)
63+
self.assertEqual(450789469, orders[0].id)
64+
self.assertEqual(207119551, orders[0].customer.id)

0 commit comments

Comments
 (0)