def test_make_order(): uid, token = next(token_gen) cart_id = new_cart(token) food_items = [next(food_gen)] # make order success res = make_order(uid, token, cart_id, food_items) assert res.status_code == 200 order_id = res.json()["id"] assert len(order_id) > 0 # verify query return the same order orders = json_get("/orders", token).json() assert len(orders) == 1 q_order = orders[0] assert q_order["id"] == order_id assert q_order["items"] == food_items # verify order info correct _price = lambda i: food_store[i]["price"] assert q_order["total"] == sum( _price(item["food_id"]) * item["count"] for item in q_order["items"]) # test only one order can be made res2 = make_order(uid, token, cart_id, food_items) assert res2.status_code == 403 assert res2.json() == {"code": "ORDER_OUT_OF_LIMIT", "message": u"每个用户只能下一单"}
def test_make_order(): uid, token = next(token_gen) cart_id = new_cart(token) item_items = [next(item_gen)] # make order success res = make_order(uid, token, cart_id, item_items) assert res.status_code == 200 order_id = res.json()["order_id"] assert len(order_id) > 0 # verify query return the same order orders = json_get("/orders", token).json() assert len(orders) == 1 q_order = orders[0] assert q_order["id"] == order_id assert q_order["items"] == item_items # verify order info correct _price = lambda i: item_store[i]["price"] assert q_order["total"] == sum( _price(item["item_id"]) * item["count"] for item in q_order["items"]) # test only one order can be made res2 = make_order(uid, token, cart_id, item_items) assert res2.status_code == 403 assert res2.json() == { "code": "ORDER_OUT_OF_LIMIT", "message": u"每个用户只能下一单" }
def test_admin_query_orders(): res = json_get("/admin/orders", admin_token) assert res.status_code == 200 q_orders = res.json() assert len(q_orders) == len(order_store) for q_order in q_orders: order_id = q_order["id"] assert order_id in order_store assert q_order["user_id"] == order_store[order_id]["user_id"] assert q_order["items"] == order_store[order_id]["items"]
def _valid(tk): return json_get("/foods", tk).status_code == 200
def _req(): _, token = next(token_gen) return json_get("/foods", token)
def test_get_orders(): _, token = next(token_gen) # new user should have no orders res = json_get("/orders", token) assert res.status_code == 200 assert len(res.json()) == 0
def _req(): _, token = next(token_gen) return json_get("/items", token)