Getting orders by status

The get_order_by_status function returns a list of orders given a status. There are two scenarios we have to test here:

  • If the method returns the correct number of orders given a specific status
  • That the correct exception is raised when passing an invalid argument to the method
def test_get_order_by_status(self):    order = Order.objects.get_orders_by_status(Status.Received)    self.assertEqual(2, len(order),                     msg=('There should be only 2 orders '                          'with status=Received.'))    self.assertEqual('customer_001@test.com',                     order[0].order_customer.email)def test_get_order_by_status_with_invalid_status(self):    with self.assertRaises(InvalidArgumentError):        Order.objects.get_orders_by_status(1)

Simple enough. The first test we call ...

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.