Exemple #1
0
    async def asyncSetUp(self):
        Environment.restore()

        self.ctx = mock_discord.MockContext()
        self.action_id = itertools.count(start=1000)

        patcher = patch.object(Storage, "get_actions")
        patcher.start()
        self.addAsyncCleanup(patcher.stop)
    async def asyncSetUp(self):
        self.ctx = mock_discord.MockContext()
        self.ctx.bot.all_commands = _CaseInsensitiveDict()
        self.ctx.bot.add_command = partial(GroupMixin.add_command,
                                           self.ctx.bot)

        setup_general_commands(self.ctx.bot)
        setup_pomwars_commands(self.ctx.bot)

        self.ctx.bot.commands = set(self.ctx.bot.all_commands.values())
Exemple #3
0
    async def asyncSetUp(self) -> None:
        """Ensure database tables exist, create contexts for the tests and
        configure reusable mocks.
        """
        self.ctx = mock_discord.MockContext()
        await Storage.create_tables_if_not_exists()
        await Storage.delete_all_rows_from_all_tables()

        patcher = patch.object(defend, "is_action_successful")
        patcher.start()
        self.addAsyncCleanup(patcher.stop)

        return await super().asyncSetUp()
    async def asyncSetUp(self) -> None:
        """Ensure database tables exist, create contexts for the tests and
        configure reusable mocks.
        """
        Environment.restore()

        self.ctx = mock_discord.MockContext()
        await Storage.create_tables_if_not_exists()
        await Storage.delete_all_rows_from_all_tables()

        for patcher in (
                patch.object(attack, "is_action_successful"),
                patch.object(State, "scoreboard"),
        ):
            _ = patcher.start(), self.addAsyncCleanup(patcher.stop)

        return await super().asyncSetUp()
    async def test_attack_does_less_damage_after_enemy_defends(
        self,
        number_of_defenders,
        user_supplied_args,
        attack_is_critical,
        expected_damage_output,
    ):
        """Test that the !attack command does less damage after some amount of
        enemies do their own !defend actions.
        """
        Pomwars.BASE_DAMAGE_FOR_NORMAL_ATTACKS = 10
        Pomwars.BASE_DAMAGE_FOR_HEAVY_ATTACKS = 40
        Pomwars.BASE_CHANCE_FOR_CRITICAL = float(attack_is_critical)
        Pomwars.DAMAGE_MULTIPLIER_FOR_CRITICAL = 1.35

        # For this test, all defenders are level 1.
        Pomwars.DEFEND_LEVEL_MULTIPLIERS = {1: 0.05}

        attack.is_action_successful.return_value = True
        State.scoreboard.update = AsyncMock()

        async def add_player(ctx: Context, team: Team):
            await Storage.add_user(user_id=ctx.author.id,
                                   zone=timezone(timedelta(hours=0)),
                                   team=team.value)
            ctx.author.roles.append(mock_discord.MockRole(name=team.value))

        for _ in range(number_of_defenders):
            new_ctx = mock_discord.MockContext()
            await add_player(new_ctx, Team.VIKINGS)
            await defend.do_defend(new_ctx)

        with semantics.assert_not_raises():
            await add_player(self.ctx, Team.KNIGHTS)
            await attack.do_attack(self.ctx, *user_supplied_args)

        all_actions = await Storage.get_actions()
        assert len(all_actions) == number_of_defenders + 1

        attacker_action = next(a for a in all_actions
                               if a.user_id == self.ctx.author.id)
        self.assertEqual(expected_damage_output, attacker_action.damage)
Exemple #6
0
 async def asyncSetUp(self) -> None:
     """Create contexts for the tests."""
     self.ctx = mock_discord.MockContext()
Exemple #7
0
 async def asyncSetUp(self) -> None:
     """Ensure database tables exist and create contexts for the tests."""
     self.ctx = mock_discord.MockContext()
     await Storage.create_tables_if_not_exists()
     await Storage.delete_all_rows_from_all_tables()
     return await super().asyncSetUp()
Exemple #8
0
    async def asyncSetUp(self):
        Environment.restore()

        self.ctx = mock_discord.MockContext()
        self.action_id = itertools.count(start=1000)