def update_game(game_id): """Update the specified game (make a move or end a game).""" game = Game(game_id) game.load_game() if request.json.get("game_status") == Game.DISCONNECTED: game.game_over(won=False) return {"message": "OK"}, status.HTTP_200_OK, RESPONSE_HEADERS column = request.json["column"] name = request.json["name"] move_result = game.move(name, column) if move_result is None: message = "Bad request, column full." status_code = status.HTTP_400_BAD_REQUEST elif move_result is True: message = Game.WON status_code = status.HTTP_200_OK else: message = "OK" status_code = status.HTTP_200_OK response_data = {"message": message} response_data.update(game.game) response_body = json.dumps(response_data, cls=DecimalEncoder) return response_body, status_code, RESPONSE_HEADERS
def test_game_over_disconnected(self, mock_db): game = Game("1") game.game = {} game.game_over(won=False) mock_db.save_game.assert_called_once_with( "1", {"game_status": "disconnected"})
def test_game_over_won(self, mock_db): game = Game("1") game.game = {} game.game_over() mock_db.save_game.assert_called_once_with("1", {"game_status": "won"})