Example #1
0
async def request_wager(database, game, tile):
    next_message_id = 16
    game.next_message_id = next_message_id
    return Request(
        message_id=next_message_id,
        action=Wager(type="wager", tile_id=tile.id, amount=100),
    )
Example #2
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),
    )
Example #3
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),
    )
Example #4
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)
Example #5
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)
Example #6
0
    async def test_errors_when_wager_amount_is_explicitly_prohibited(
            self, game_after_daily_double_chosen, player_1, tile):
        game = game_after_daily_double_chosen
        user = player_1
        forbidden_request = Request(
            message_id=game.next_message_id,
            action=Wager(type="wager", tile_id=tile.id, amount=666),
        )

        with pytest.raises(exceptions.ForbiddenWagerException):
            await validate_request(game, user, forbidden_request)
Example #7
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)
Example #8
0
async def request_response(database, game, tile):
    next_message_id = 12
    game.next_message_id = next_message_id
    return Request(
        message_id=next_message_id,
        action=Response(
            type="response",
            tile_id=tile.id,
            question="Test question?",
        ),
    )
Example #9
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)
Example #10
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)
Example #11
0
    async def test_checks_when_wager_is_permitted(
        self,
        mock_is_permitted_wager,
        game_after_daily_double_chosen,
        team_1,
        player_1,
        tile,
    ):
        valid_amount = 100
        team_1.score = 150
        await team_1.save()

        game = game_after_daily_double_chosen
        user = player_1
        request = Request(message_id=game.next_message_id,
                          action=Wager(type="wager",
                                       tile_id=tile.id,
                                       amount=valid_amount))

        await validate_request(game, user, request)
        mock_is_permitted_wager.assert_called_with(team_1, valid_amount)