def test_order_checkout_insufficient_balance(self):
        total_cost = float(
            ep.orders_find(self.order2['order_id']).json()['total_cost'])
        old_balance = float(
            ep.users_find(self.user2['user_id']).json()['credit'])

        res = ep.orders_checkout(self.order2['order_id'])

        new_balance = float(
            ep.users_find(self.user2['user_id']).json()['credit'])

        self.assertFalse(res.ok)
        self.assertLessEqual(old_balance, total_cost)
        self.assertEqual(old_balance, new_balance)
    def test_order_success_paid(self):
        res = ep.orders_find(self.order1['order_id'])

        self.assertTrue(res.ok)
        paid_before = res.json()['paid']

        self.assertEqual(paid_before, 'False')

        res2 = ep.orders_checkout(self.order1['order_id'])
        res3 = ep.orders_find(self.order1['order_id'])

        self.assertTrue(res2.ok)
        self.assertTrue(res3.ok)
        paid_after = res3.json()['paid']

        self.assertEqual(paid_after, 'True')
    def test_order_checkout_enough_balance_payment(self):
        total_cost = float(
            ep.orders_find(self.order1['order_id']).json()['total_cost'])
        old_balance = float(
            ep.users_find(self.user1['user_id']).json()['credit'])
        res = ep.orders_checkout(self.order1['order_id'])

        new_balance = float(
            ep.users_find(self.user1['user_id']).json()['credit'])

        self.assertTrue(
            res.ok,
            f"total_cost: {total_cost}, old_balance: {old_balance}, new_balance: {new_balance}"
        )
        self.assertGreaterEqual(old_balance, total_cost)
        self.assertEqual(new_balance, old_balance - total_cost)
Ejemplo n.º 4
0
    def test_insufficient_stock2(self):
        ep.stock_add(self.item_id, 0)
        ep.stock_add(self.item_id2, 10)
        ep.users_credit_add(self.user_id, 500)
        ep.orders_add_item(self.order_id, self.item_id)
        ep.orders_add_item(self.order_id, self.item_id2)

        response = ep.orders_checkout(self.order_id)

        item1_stock = int(ep.stock_find(self.item_id).json()['stock'])
        item2_stock = int(ep.stock_find(self.item_id2).json()['stock'])
        user_credit = Decimal(ep.users_find(self.user_id).json()['credit'])

        self.assertFalse(response.ok)
        self.assertEqual(item1_stock, 0)
        self.assertEqual(item2_stock, 10)
        self.assertEqual(user_credit, Decimal(500))
Ejemplo n.º 5
0
    def test_happy_flow(self):
        ep.stock_add(self.item_id, 10)
        ep.stock_add(self.item_id2, 10)
        ep.users_credit_add(self.user_id, 500)
        ep.orders_add_item(self.order_id, self.item_id)
        ep.orders_add_item(self.order_id, self.item_id2)

        response = ep.orders_checkout(self.order_id)

        item1_stock = int(ep.stock_find(self.item_id).json()['stock'])
        item2_stock = int(ep.stock_find(self.item_id2).json()['stock'])
        user_credit = Decimal(ep.users_find(self.user_id).json()['credit'])

        self.assertTrue(response.ok)
        self.assertEqual(item1_stock, 9)
        self.assertEqual(item2_stock, 9)
        self.assertEqual(user_credit, Decimal(493.5))
    def test_order_checkout_insufficient_stock(self):
        items = ep.orders_find(self.order2['order_id']).json()['items']

        stock_dict = {}
        for item in items:
            stock_dict[item] = ep.stock_find(item).json()['stock']

        order_dict = {}
        for item in items:
            if item in order_dict:
                order_dict[item] += 1
            else:
                order_dict[item] = 1

        res = ep.orders_checkout(self.order2['order_id'])

        self.assertFalse(res.ok)

        for item in items:
            self.assertEqual(stock_dict[item],
                             ep.stock_find(item).json()['stock'])
    def test_order_checkout_enough_balance_stock(self):
        items = ep.orders_find(self.order1['order_id']).json()['items']

        stock_dict = {}
        for item in items:
            stock_dict[item] = ep.stock_find(item).json()['stock']

        order_dict = {}
        for item in items:
            if item in order_dict:
                order_dict[item] += 1
            else:
                order_dict[item] = 1

        res = ep.orders_checkout(self.order1['order_id'])

        self.assertTrue(res.ok)

        for item in items:
            self.assertEqual(stock_dict[item] - order_dict[item],
                             ep.stock_find(item).json()['stock'])
    def test_order_checkout_non_existing(self):
        res = ep.orders_checkout(self.user1['user_id'])

        self.assertFalse(res.ok)