diff --git a/tests/test_api.py b/tests/test_api.py index 52b6546..6b23d13 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -27,8 +27,8 @@ def createGame(user:User): if content is None: print("content is none") raise Exception("Response is null") - if content["status"] != "ok": - print(content["status"]) + if content["error"] != 0: + print(content["msg"]) raise Exception("Status is not ok") user.isAdmin = True return content["game_id"] @@ -43,8 +43,8 @@ def joinGame(user:User,game_id:str): content = responseObject.json if content is None: raise Exception("Response is null") - if content["status"] != "ok": - print(content["status"]) + if content["error"] != 0: + print(content["msg"]) raise Exception("Status is not ok") return True @@ -56,8 +56,8 @@ def startGame(user:User): content = responseObject.json if content is None: raise Exception("Response is null") - if content["status"] != "ok": - print(content["status"]) + if content["error"] != 0: + print(content["msg"]) raise Exception("Status is not ok") return True @@ -96,7 +96,7 @@ def test_that_two_person_having_the_same_pseudo_creating_two_games_results_in_tw def test_that_not_sending_a_username_results_in_an_error(): responseObject = test_app.post("/api/v1/createGame") assert responseObject.status_code == 200 - assert responseObject.json["status"] != "ok" + assert responseObject.json["error"] != 0 def test_that_sending_a_empty_username_results_in_an_error(): @@ -144,20 +144,20 @@ def test_that_people_joining_without_sending_any_data_results_in_an_error(): game_id = createGame(User("neoxyde")) responseObject = test_app.post("/api/v1/joinGame") assert responseObject.status_code == 200 - assert responseObject.json["status"] != "ok" + assert responseObject.json["error"] != 0 def test_that_people_joining_without_sending_a_game_id_results_in_an_error(): data={"username":"neomblic"} responseObject = test_app.post("/api/v1/joinGame",data=data) assert responseObject.status_code == 200 - assert responseObject.json["status"] != "ok" + assert responseObject.json["error"] != 0 def test_that_people_joining_without_sending_an_username_still_results_in_an_error(): game_id = createGame(User("neonyx")) data={"game_id":game_id} responseObject = test_app.post("/api/v1/joinGame",data=data) assert responseObject.status_code == 200 - assert responseObject.json["status"] != "ok" + assert responseObject.json["error"] != 0 def test_that_people_joining_with_an_empty_username_still_results_in_an_error(): game_id = createGame(User("neodeur")) diff --git a/truthseeker/routes/routes_api.py b/truthseeker/routes/routes_api.py index ae0a416..647b3a1 100644 --- a/truthseeker/routes/routes_api.py +++ b/truthseeker/routes/routes_api.py @@ -10,11 +10,11 @@ routes_api = flask.Blueprint("api", __name__) def create_game(): username = flask.request.values.get("username") if username==None: - return {"status": "error, username not set"} + return {"error": 1, "msg": "username not set"} response = {} - response["status"] = "ok" + response["error"] = 0 game = game_logic.create_game(owner=username) response["game_id"] = game.game_id @@ -29,11 +29,11 @@ def join_game(): game_id = flask.request.values.get("game_id") username = flask.request.values.get("username") if game_id==None or username==None: - return {"status": "error, username or game id not set"} + return {"error": 1, "msg": "username or game id not set"} game = game_logic.get_game(game_id) if game == None: - return {"status": "error, game does not exist"} + return {"error": 1, "msg": "game does not exist"} game.add_member(username) @@ -42,17 +42,15 @@ def join_game(): flask.session["is_owner"] = False flask.session["username"] = username - response = {} - response["status"] = "ok" - return response + return {"error": 0} @routes_api.route("/startGame", methods=["GET", "POST"]) def start_game(): if not flask.session: - return {"status": "No session"} + return {"error": 1, "msg": "No session"} if not flask.session["is_owner"]: - return {"status": "Error, you are not the owner of this game"} + return {"error": 1, "msg": "you are not the owner of this game"} if game_logic.get_game(flask.session["game_id"]) == None: - return {"status": "Error, this game doesn't exist"} + return {"error": 1, "msg": "this game doesn't exist"} - return {"status": "ok"} + return {"error": 0}