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'])
    def test_order_create_existing_user(self):
        res = ep.orders_create(self.user1['user_id'])
        order_id = res.json()['order_id']
        try:
            uuid_obj = UUID(order_id, version=4)
        except ValueError:
            return False

        self.assertTrue(res.ok)
        self.assertEqual(str(uuid_obj), order_id)
    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'])
    def test_order_delete_existing(self):
        res = ep.orders_create(self.user1['user_id'])

        self.assertTrue(res.ok)

        res2 = ep.orders_remove(res.json()['order_id'])

        self.assertTrue(res2.ok)

        res3 = ep.orders_find(res.json()['order_id'])

        self.assertFalse(res3.ok)
    def test_order_find_by_user_existing(self):
        res = ep.orders_find_by_user(self.user1['user_id'])

        orders = res.json()['order_ids']
        self.assertIsInstance(orders, list)
        self.assertIn(self.order1['order_id'], orders)

        res2 = ep.orders_create(self.user1['user_id'])

        self.assertTrue(res2.ok)

        res = ep.orders_find_by_user(self.user1['user_id'])
        orders = res.json()['order_ids']
        self.assertIsInstance(orders, list)
        self.assertIn(self.order1['order_id'], orders)
        self.assertIn(res2.json()['order_id'], orders)
    def test_order_create_non_existing_user(self):
        res = ep.orders_create(self.order1['order_id'])

        self.assertFalse(res.ok)
예제 #7
0
 def setUp(self):
     self.item_id = ep.stock_create(5.5).json()['item_id']
     self.item_id2 = ep.stock_create(1).json()['item_id']
     self.user_id = ep.users_create().json()['user_id']
     self.order_id = ep.orders_create(self.user_id).json()['order_id']