Example #1
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 #2
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))
Example #3
0
 def setUp(self) -> None:
     self.price = uniform(0, 100)
     self.item_id = ep.stock_create(self.price).json()['item_id']
     self.res = ep.stock_find(self.item_id)
     self.stock_item = self.res.json()
     self.old_amount = self.stock_item['stock']
     self.rand_int_pos = randint(0, 100)
     self.rand_int_neg = randint(-100, -1)
     self.rand_float_pos = uniform(0, 100)
     self.rand_float_neg = uniform(-100, -1)
Example #4
0
    def test_stock_subtract_positive_integer_too_much(self):
        res2 = ep.stock_add(self.stock_item['item_id'], self.rand_int_pos)

        self.assertTrue(res2.ok)

        res3 = ep.stock_subtract(self.stock_item['item_id'],
                                 self.rand_int_pos + 1)

        self.assertFalse(res3.ok)
        self.assertEqual(
            ep.stock_find(self.item_id).json()['stock'], self.rand_int_pos)
    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_find_existing(self):
        res = ep.orders_find(self.order1['order_id'])

        order = res.json()

        items = order['items']
        total_cost = 0
        for item in items:
            total_cost += ep.stock_find(item).json()['price']

        self.assertTrue(res.ok)
        self.assertEqual(order['order_id'], self.order1['order_id'])
        self.assertEqual(order['paid'], 'False')
        self.assertIn(self.item1['item_id'], order['items'])
        self.assertIn(self.item2['item_id'], order['items'])
        self.assertEqual(order['total_cost'], str(total_cost))
        self.assertEqual(order['user_id'], self.user1['user_id'])
Example #8
0
    def test_stock_subtract_negative_integer(self):
        res2 = ep.stock_add(self.stock_item['item_id'], self.rand_int_neg)
        new_amount = ep.stock_find(self.item_id).json()['stock']

        self.assertFalse(res2.ok)
        self.assertEqual(new_amount, self.old_amount)
Example #9
0
    def test_stock_subtract_positive_float(self):
        res2 = ep.stock_add(self.stock_item['item_id'], self.rand_float_pos)
        new_amount = ep.stock_find(self.item_id).json()['stock']

        self.assertFalse(res2.ok)
        self.assertEqual(new_amount, self.old_amount)