Beispiel #1
0
    def test_order_total_multi_item(self):
        order = Order(self.member, self.room)

        item = OrderItem(self.product, order, 2)
        order.items.add(item)

        self.assertEqual(order.total(), 20)
Beispiel #2
0
    def test_order_total_single_item(self):
        order = Order(self.member, self.room)

        item = OrderItem(self.product, order, 1)
        order.items.add(item)

        self.assertEqual(order.total(), 10)
Beispiel #3
0
    def test_order_execute_multi_transaction(self, fulfill):
        order = Order(self.member, self.room)

        item = OrderItem(self.product, order, 2)
        order.items.add(item)

        order.execute()

        fulfill.assert_called_once_with(PayTransaction(20))
Beispiel #4
0
    def test_order_execute_no_money(self, fulfill, can_fulfill):
        can_fulfill.return_value = False
        order = Order(self.member, self.room)

        item = OrderItem(self.product, order, 2)
        order.items.add(item)

        with self.assertRaises(StregForbudError):
            order.execute()

        fulfill.was_not_called()
Beispiel #5
0
    def test_order_execute_multi_some_remaining(self, fulfill):
        self.product.sale_set.create(price=100, member=self.member)
        self.product.start_date = datetime.date(year=2017, month=1, day=1)
        self.product.quantity = 2
        order = Order(self.member, self.room)

        item = OrderItem(self.product, order, 2)
        order.items.add(item)

        with self.assertRaises(NoMoreInventoryError):
            order.execute()

        fulfill.was_not_called()
Beispiel #6
0
    def test_order_execute_no_money(self, can_fulfill):
        can_fulfill.return_value = False
        balance_before = self.member.balance
        order = Order(self.member, self.room)

        item = OrderItem(self.product, order, 2)
        order.items.add(item)

        with self.assertRaises(StregForbudError):
            order.execute()

        balance_after = self.member.balance
        self.assertEqual(balance_before, balance_after)