Testing the get all orders function

Now, we are going to add tests to the get_all_orders_by_customer method. For this method, we need to test:

  • If the correct number of orders is returned when given a customer ID
  • If the correct exception is raised when passing an invalid argument to the method
def test_get_all_orders_by_customer(self):    orders = Order.objects.get_all_orders_by_customer(customer_id=1)    self.assertEqual(2, len(orders),                     msg='It should have returned 2 orders.')def test_get_all_order_by_customer_with_invalid_id(self):    with self.assertRaises(InvalidArgumentError):        Order.objects.get_all_orders_by_customer('o')

The tests for the get_all_orders_by_customer method are quite simple. In the first test, we fetch the orders for the customer ...

Get Python Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.