Exemple #1
0
def test_del_food_success(url, token, cart_id):
    # silent ignore foods delete errors
    food_count = {"food_id": 2, "count": -2}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 204

    food_count = {"food_id": 3, "count": -2}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 204
Exemple #2
0
def test_del_food_success(url, token, cart_id):
    # silent ignore foods delete errors
    food_count = {"food_id": 2, "count": -2}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 204

    food_count = {"food_id": 3, "count": -2}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 204
Exemple #3
0
def test_add_food_success(url, token, cart_id):
    food_count = {"food_id": 2, "count": 1}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 204
    assert len(res.content) == 0

    # silent ignore foods delete errors
    food_count = {"food_id": 2, "count": -1}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 204
    assert len(res.content) == 0
Exemple #4
0
def test_add_food_success(url, token, cart_id):
    food_count = {"food_id": 2, "count": 1}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 204
    assert len(res.content) == 0

    # silent ignore foods delete errors
    food_count = {"food_id": 2, "count": -1}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 204
    assert len(res.content) == 0
Exemple #5
0
def test_add_food_not_exists_error(url, token, cart_id):
    food_count = {"food_id": -1, "count": 2}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 404
    assert res.json()["code"] == "FOOD_NOT_FOUND"
    assert res.json()["message"] == u"食物不存在"
Exemple #6
0
def test_add_food_exceed_limit_error(url, token, cart_id):
    food_count = {"food_id": 2, "count": 4}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 403
    assert res.json()["code"] == "FOOD_OUT_OF_LIMIT"
    assert res.json()["message"] == u"篮子中食物数量超过了三个"
Exemple #7
0
def test_add_food_error(url, token):
    res = jpatch(url + "/carts/-1", token, items)
    assert res.status_code == 404
    assert res.json()["code"] == "CART_NOT_FOUND"
    assert res.json()["message"] == u"篮子不存在"
Exemple #8
0
 def _f(token, _items=None):
     res = jpost(url + "/carts", token)
     cart_id = res.json()["cart_id"]
     jpatch(url + "/carts/%s" % cart_id, token, _items or items)
     return jpost(url + "/orders", token, {"cart_id": cart_id})
Exemple #9
0
def test_add_food_not_exists_error(url, token, cart_id):
    food_count = {"food_id": -1, "count": 2}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 404
    assert res.json()["code"] == "FOOD_NOT_FOUND"
    assert res.json()["message"] == u"食物不存在"
Exemple #10
0
def test_add_food_exceed_limit_error(url, token, cart_id):
    food_count = {"food_id": 2, "count": 4}
    res = jpatch(url + "/carts/%s" % cart_id, token, food_count)
    assert res.status_code == 403
    assert res.json()["code"] == "FOOD_OUT_OF_LIMIT"
    assert res.json()["message"] == u"篮子中食物数量超过了三个"
Exemple #11
0
def test_add_food_error(url, token):
    res = jpatch(url + "/carts/-1", token, items)
    assert res.status_code == 404
    assert res.json()["code"] == "CART_NOT_FOUND"
    assert res.json()["message"] == u"篮子不存在"
Exemple #12
0
 def _f(token, _items=None):
     res = jpost(url + "/carts", token)
     cart_id = res.json()["cart_id"]
     jpatch(url + "/carts/%s" % cart_id, token, _items or items)
     return jpost(url + "/orders", token, {"cart_id": cart_id})