Beispiel #1
0
async def request_choice(database, game, tile):
    next_message_id = 8
    game.next_message_id = next_message_id
    await game.save()
    return Request(
        message_id=next_message_id,
        action=Action(type="choice", tile_id=tile.id),
    )
Beispiel #2
0
async def request_buzz(database, game, tile):
    next_message_id = 4
    game.next_message_id = next_message_id
    await game.save()
    return Request(
        message_id=next_message_id,
        action=Action(type="buzz", tile_id=tile.id),
    )
Beispiel #3
0
    async def test_does_not_error_for_logically_consistent_input(
            self, game_started_with_team_1, player_1, tile):
        game = game_started_with_team_1
        user = player_1
        consistent_request = Request(
            message_id=game.next_message_id,
            action=Action(type="choice", tile_id=tile.id),
        )

        await validate_request(game, user, consistent_request)
Beispiel #4
0
    async def test_errors_if_user_not_permitted_to_perform_the_action(
            self, game_started_with_team_1, player_2, tile):
        game = game_started_with_team_1
        wrong_user = player_2
        consistent_request = Request(
            message_id=game.next_message_id,
            action=Action(type="choice", tile_id=tile.id),
        )

        with pytest.raises(exceptions.ActOutOfTurnException):
            await validate_request(game, wrong_user, consistent_request)
Beispiel #5
0
    async def test_errors_when_tile_not_found(self, game_started_with_team_1,
                                              player_1, tile):
        game = game_started_with_team_1
        user = player_1
        inconsistent_request = Request(
            message_id=game.next_message_id,
            action=Action(type="choice", tile_id=tile.id + 1),
        )

        with pytest.raises(exceptions.TileNotFoundException):
            await validate_request(game, user, inconsistent_request)
Beispiel #6
0
    async def test_errors_when_tile_already_chosen(self,
                                                   game_started_with_team_1,
                                                   player_1, chosen_tile):
        game = game_started_with_team_1
        user = player_1
        forbidden_request = Request(
            message_id=game.next_message_id,
            action=Action(type="choice", tile_id=chosen_tile.id),
        )

        with pytest.raises(exceptions.TileAlreadyChosenException):
            await validate_request(game, user, forbidden_request)
Beispiel #7
0
    async def test_errors_when_action_type_not_next(self,
                                                    game_started_with_team_1,
                                                    player_1, tile):
        game = game_started_with_team_1
        user = player_1
        forbidden_request = Request(
            message_id=game.next_message_id,
            action=Action(type="buzz", tile_id=tile.id),
        )

        with pytest.raises(exceptions.ForbiddenActionException):
            await validate_request(game, user, forbidden_request)