Esempio n. 1
0
def _get_today_votes(client, token: str):
    today_votes = client.get(
        "/api/v1/vote",
        headers=token_headers(token)
    )
    assert_json_status(today_votes, 200)
    return json.loads(today_votes.data)
Esempio n. 2
0
def test_restaurant_delete(client):
    token = get_valid_token(client)
    restaurant1 = add_restaurant(client, "restaurant 1", "*****@*****.**")
    restId = restaurant1.id
    response = client.delete(f"/api/v1/restaurant/{restaurant1.id}",
                             headers=token_headers(token),
                             content_type="application/json")
    assert_json_status(response, 204)

    # following request for same restaurant should return 404
    url = f"/api/v1/restaurant/{restId}"
    response = client.get(
        url,
        headers=token_headers(token),
        content_type="application/json",
    )
    assert_json_status(response, 404)

    # count of stored restaurant should be 0

    response = client.get(
        "/api/v1/restaurant",
        headers=token_headers(token),
        content_type="application/json",
    )
    assert_success_200(response)
    data = json.loads(response.data)
    assert len(data) == 0
Esempio n. 3
0
def _place_vote(client, restaurant_id: int, user_token: str):
    response = client.post(
        f'/api/v1/vote/{restaurant_id}',
        headers=token_headers(user_token)
    )
    assert_json_status(response, 201)
    result = json.loads(response.data)
    return result
Esempio n. 4
0
def rest_restaurant_add(client, token: str, restaurant: RestaurantModel):
    restaurant_json = restaurant_schema.dump(restaurant)

    response = client.post("/api/v1/restaurant",
                           headers=token_headers(token),
                           content_type="application/json",
                           json=restaurant_json)
    assert_json_status(response, 201)
    data = json.loads(response.data)
    return data
Esempio n. 5
0
def _test_vote_add(client):
    token = get_valid_token(client)
    restaurant_id = 1
    th = token_headers(token)
    response = client.post(
        f"/api/v1/vote/{restaurant_id}",
        headers=token_headers(token)
    )
    assert_json_status(response, 201)
    data = json.loads(response.data)

    assert data["restaurant_id"] == restaurant_id
    assert data["user_id"] == 1
    assert data["vote_rate"] == 1
Esempio n. 6
0
def test_restaurant_update(client):
    token = get_valid_token(client)
    restaurant1 = add_restaurant(client, "restaurant 1", "*****@*****.**")
    response = client.put(f"/api/v1/restaurant/{restaurant1.id}",
                          headers=token_headers(token),
                          content_type="application/json",
                          json={
                              "name": "restaurant 1 - updated",
                              "email": "*****@*****.**"
                          })
    assert_json_status(response, 201)
    data = json.loads(response.data)
    assert data["name"] == "restaurant 1 - updated"
    assert data["email"] == "*****@*****.**"