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 test_access_protected_endpoint_with_valid_token(client): token = get_valid_token(client) response = client.get( "/protected", headers=dict(Authorization="Bearer " + token), content_type="application/json", ) assert_success_200(response) data = json.loads(response.data) assert data["message"] == "Protected message"
def test_vote_list(client): token = get_valid_token(client) response = client.get( "/api/v1/vote", headers=token_headers(token), content_type="application/json", ) assert_success_200(response) data = json.loads(response.data) assert not data
def test_restaurant_list(client): token = get_valid_token(client) response = client.get( "/api/v1/restaurant", headers=dict(Authorization="Bearer " + token), content_type="application/json", ) assert_success_200(response) data = json.loads(response.data) assert data == []
def test_logout(client): token = get_valid_token(client) response = client.post( "/api/v1/auth/logout", headers=dict(Authorization="Bearer " + token), content_type="application/json", ) assert_success_200(response) response_protected = client.get( "/protected", headers=dict(Authorization="Bearer " + token), content_type="application/json", ) assert_error_token_expired(response_protected)
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"] == "*****@*****.**"
def add_restaurant(client, name, email): token = get_valid_token(client) test_restaurant = RestaurantModel(name="restaurant 1", email="*****@*****.**") json = rest_restaurant_add(client, token, test_restaurant) # response = client.post( # "/api/v1/restaurant", # token_headers(token), # content_type="application/json", # json={"name": "restaurant 1", "email": "*****@*****.**"} # ) # assert_json_status(response, 201) # data = json.loads(response.data) rm = RestaurantModel(**json) return rm
def test_restaurant_add(client): token = get_valid_token(client) test_restaurant = RestaurantModel(name="restaurant 1", email="*****@*****.**") json = rest_restaurant_add(client, token, test_restaurant) assert json["name"] == "restaurant 1" assert json["email"] == "*****@*****.**"