def setUp(self) -> None:
        self.user1 = ep.users_create().json()
        self.user2 = ep.users_create().json()
        self.order1 = ep.orders_create(self.user1['user_id']).json()
        self.order2 = ep.orders_create(self.user2['user_id']).json()

        self.price = uniform(0, 100)
        self.balance_sufficient = self.price
        self.balance_insufficient = uniform(0, self.price - 1.0)

        self.item1 = ep.stock_create(self.price).json()
        ep.users_credit_add(self.user1['user_id'], self.balance_sufficient)
        ep.users_credit_add(self.user2['user_id'], self.balance_insufficient)

        ep.orders_add_item(self.order1['order_id'], self.item1['item_id'])
        ep.orders_add_item(self.order2['order_id'], self.item1['item_id'])
Example #2
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))
Example #3
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 setUp(self) -> None:
        self.user1 = ep.users_create().json()
        self.user2 = ep.users_create().json()
        ep.users_credit_add(self.user1['user_id'], 100)
        self.item1 = ep.stock_create(20).json()
        ep.stock_add(self.item1["item_id"], 3)
        self.item2 = ep.stock_create(10).json()
        ep.stock_add(self.item2["item_id"], 3)
        self.order1 = ep.orders_create(self.user1['user_id']).json()
        self.order2 = ep.orders_create(self.user2['user_id']).json()
        self.order3 = ep.orders_create(self.user2['user_id']).json()

        # First order will have item 1 two times and item 2 once, total price is 50
        ep.orders_add_item(self.order1['order_id'], self.item1['item_id'])
        ep.orders_add_item(self.order1['order_id'], self.item1['item_id'])
        ep.orders_add_item(self.order1['order_id'], self.item2['item_id'])

        # Order 2 has total price of 20
        ep.orders_add_item(self.order2['order_id'], self.item1['item_id'])