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)
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
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
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
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
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"] == "*****@*****.**"