예제 #1
0
def test_post_avadakedavra():
    with db_session:
        game = Game.get(id=pytest.info['game'])
        player = Player.select(lambda p: p.current_position == "" and p.game.id
                               == game.id).first()
        for i in pytest.users.keys():
            if pytest.users[i]["user_id"] == player.user.id:
                user = i
                break
        headers = {
            'Authorization': 'Bearer ' + pytest.users[user]["token"],
            'Content-Type': 'text/plain'
        }
        response = client.post(f"/games/{pytest.info['game']}/avadakedavra",
                               headers=headers,
                               json={'id': pytest.users[2]["player_id"]})
        assert response.status_code == 400
        assert response.json() == {
            "detail": "Its not time for playing spells!"
        }
        game.status["phase"] = "spell play"
        response = client.post(f"/games/{pytest.info['game']}/avadakedavra",
                               headers=headers,
                               json={'id': pytest.users[2]["player_id"]})
        assert response.status_code == 400
        assert response.json() == {
            "detail": "The avadakedavra spell is not available"
        }
예제 #2
0
def test_get_crucio():
    with db_session:
        game = Game.get(id=pytest.info['game'])
        player = Player.select(lambda p: p.current_position == "" and p.game.id
                               == game.id).first()
        for i in pytest.users.keys():
            if pytest.users[i]["user_id"] == player.user.id:
                user = i
                break
        headers = {
            'Authorization': 'Bearer ' + pytest.users[user]["token"],
            'Content-Type': 'text/plain'
        }
        game.status["phase"] = "otro estado"
        response = client.get(f"/games/{pytest.info['game']}/crucio/4000",
                              headers=headers)
        assert response.status_code == 400
        assert response.json() == {
            "detail": "The victim player does not belong to this game"
        }
        response = client.get(
            f"/games/{pytest.info['game']}/crucio/{pytest.users[user]['player_id']}",
            headers=headers)
        assert response.status_code == 400
        assert response.json() == {
            "detail": "Its not time for playing spells!"
        }
        game.status["phase"] = "spell play"
        game.started = False
        response = client.get(f"/games/{pytest.info['game']}/divination",
                              headers=headers)
        assert response.status_code == 400
        assert response.json() == {"detail": "Game is not started"}
        game.started = True
예제 #3
0
async def play_crucio(player_id: int, game_id: int, user=Depends(manager)):
    with db_session:
        game = Game.get(id=game_id)
        current_player = Player.user_player(user, game_id)
        victim_player = Player.select(
            lambda p: p.id == player_id and p.game.id == game_id).first()
        deck = game.board.spell_fields.split(",")
        if game is None:
            raise HTTPException(status_code=404, detail="Game not found")
        if not game.started:
            raise HTTPException(status_code=400, detail="Game is not started")
        if not victim_player:
            raise HTTPException(
                status_code=400,
                detail="The victim player does not belong to this game")
        if game.status["phase"] != "spell play":
            raise HTTPException(status_code=400,
                                detail="Its not time for playing spells!")
        if current_player["current_position"] != "minister":
            raise HTTPException(status_code=400,
                                detail=f"This player is not the minister")
        if game.board.de_proc == 0 or deck[game.board.de_proc - 1] != "crucio":
            raise HTTPException(status_code=400,
                                detail="The crucio spell is not available")
        victim_user = User.select(
            lambda u: u.id == victim_player.user.id).first()
        role = victim_player.role
        return {
            "role": role,
            "player_id": player_id,
            "player_alias": victim_user.useralias
        }
예제 #4
0
async def write_message(msg_content: MessageM,
                        game_id: int,
                        user=Depends(manager)):
    with db_session:
        game = Game.get(id=game_id)
        current_player = Player.select(lambda p: user["id"] == p.user.id and p.
                                       game.id == game_id).first()
        if game is None:
            raise HTTPException(status_code=404, detail="Game not found")
        if not game.started:
            raise HTTPException(status_code=400, detail="Game is not started")
        Message(date=datetime.datetime.now(),
                content=msg_content.content,
                game=game_id,
                player=current_player)
        return {"detail": "the message was recorder successfully"}
def gather_players_of_team(team):
    print("\t\t\tStarting to gathering player data of " + team.name)
    player_urls = util.check_exception(api.get_player_urls, (team, ))
    existed_player_objects = list(
        Player.select().join(Team).where(Team.id == team.id))

    difference_list = give_difference_list(existed_player_objects, player_urls)

    for url in difference_list:
        player = util.check_exception(api.get_player, (
            team,
            url,
        ))
        if player:
            existed_player_objects.append(player)
            print("\t\t\t\t" + player.name + "'s data gathered successfully.")
    print(
        "\t\t\tPlayer data of {} gathered successfully. There are {} players.\n"
        .format(team.name, len(difference_list)))
    return existed_player_objects
예제 #6
0
async def kill_player(player_id: PlayerM, game_id: int, user=Depends(manager)):
    with db_session:
        game = Game.get(id=game_id)
        current_player = Player.user_player(user, game_id)
        victim_player = Player.select(
            lambda p: p.id == player_id.id and p.game.id == game_id).first()
        deck = game.board.spell_fields.split(",")
        if game is None:
            raise HTTPException(status_code=404, detail="Game not found")
        if game.status["phase"] != "spell play":
            raise HTTPException(status_code=400,
                                detail="Its not time for playing spells!")
        if not game.board.de_proc or deck[game.board.de_proc -
                                          1] != 'avadakedavra':
            raise HTTPException(
                status_code=400,
                detail="The avadakedavra spell is not available")
        if not victim_player:
            raise HTTPException(
                status_code=400,
                detail="The victim player does not belong to this game")
        if current_player["current_position"] != "minister":
            raise HTTPException(status_code=404,
                                detail="This player is not the minister")
        victim_player.alive = False
        if victim_player.is_voldemort:
            game.status = {
                "info": "game ended",
                "winner": "Phoenix Order",
                "detail": "voldemort killed"
            }
        else:
            Player.reassign_minister(game)
        victim_user = User.select(
            lambda u: u.id == victim_player.user.id).first()
        return {
            "avadakedavra": "succeed!",
            "dead_player_id": player_id.id,
            "dead_player_alias": victim_user.useralias
        }
예제 #7
0
def test_players_game():
    headers = {
        'Authorization': 'Bearer ' + pytest.users[2]["token"],
        'Content-Type': 'text/plain'
    }
    response = client.get(f"/games/{pytest.info['game']}/players",
                          headers=headers)
    assert response.status_code == 200
    with db_session:
        player1 = Player.select(lambda p: p.user.username == pytest.users[1][
            "username"] and p.game.id == pytest.info['game']).first()
        pytest.users[1]["player_id"] = player1.id
        player2 = Player.select(lambda p: p.user.username == pytest.users[2][
            "username"] and p.game.id == pytest.info['game']).first()
        pytest.users[2]["player_id"] = player2.id
        player3 = Player.select(lambda p: p.user.username == pytest.users[3][
            "username"] and p.game.id == pytest.info['game']).first()
        pytest.users[3]["player_id"] = player3.id
        player4 = Player.select(lambda p: p.user.username == pytest.users[4][
            "username"] and p.game.id == pytest.info['game']).first()
        pytest.users[4]["player_id"] = player4.id
        player5 = Player.select(lambda p: p.user.username == pytest.users[5][
            "username"] and p.game.id == pytest.info['game']).first()
        pytest.users[5]["player_id"] = player5.id
        assert response.json() == {
            "data": [{
                "id": player1.id,
                "choosable": True,
                "current_position": player1.current_position,
                "game": pytest.info['game'],
                "role": player1.role,
                "is_voldemort": player1.is_voldemort,
                "alive": True,
                "user": {
                    "id": pytest.users[1]["user_id"],
                    "useralias": "andres",
                    "username": "******",
                    'verified': True
                },
            }, {
                "id": player3.id,
                "choosable": True,
                "current_position": player3.current_position,
                "game": pytest.info['game'],
                "role": player3.role,
                "is_voldemort": player3.is_voldemort,
                "alive": True,
                "user": {
                    "id": pytest.users[3]["user_id"],
                    "useralias": "andres3",
                    "username": "******",
                    'verified': True
                },
            }, {
                "id": player4.id,
                "choosable": True,
                "current_position": player4.current_position,
                "game": pytest.info['game'],
                "role": player4.role,
                "is_voldemort": player4.is_voldemort,
                "alive": True,
                "user": {
                    "id": pytest.users[4]["user_id"],
                    "useralias": "andres4",
                    "username": "******",
                    "verified": True
                },
            }, {
                "id": player5.id,
                "choosable": True,
                "current_position": player5.current_position,
                "game": pytest.info['game'],
                "role": player5.role,
                "is_voldemort": player5.is_voldemort,
                "alive": True,
                "user": {
                    "id": pytest.users[5]["user_id"],
                    "useralias": "andres5",
                    "username": "******",
                    "verified": True
                },
            }, {
                "id": player2.id,
                "choosable": True,
                "current_position": player2.current_position,
                "game": pytest.info['game'],
                "role": player2.role,
                "is_voldemort": player2.is_voldemort,
                "alive": True,
                "user": {
                    "id": pytest.users[2]["user_id"],
                    "useralias": "andres2",
                    "username": "******",
                    "verified": True
                }
            }]
        }
    response = client.get("/games/100/players", headers=headers)
    assert response.status_code == 404
    assert response.json() == {'detail': "Game not found"}