Exemple #1
0
    async def test_removePunishment(self):
        ast = AntiSpamTracker(AntiSpamHandler(get_mocked_bot()), 5)

        ast.remove_punishments(get_mocked_message())

        ast.update_cache(get_mocked_message(),
                         {"should_be_punished_this_message": True})
        self.assertEqual(1, ast.get_user_count(get_mocked_message()))

        ast.remove_punishments(get_mocked_message())
        with self.assertRaises(UserNotFound):
            ast.get_user_count(get_mocked_message())
Exemple #2
0
    async def test_removeOutdatedTimestamps(self):
        ast = AntiSpamTracker(AntiSpamHandler(get_mocked_bot()), 3, 50)
        ast.update_cache(get_mocked_message(),
                         {"should_be_punished_this_message": True})
        self.assertEqual(ast.get_user_count(get_mocked_message()), 1)

        ast.remove_outdated_timestamps(123456789, 12345)
        self.assertEqual(ast.get_user_count(get_mocked_message()), 1)

        await asyncio.sleep(0.06)
        ast.remove_outdated_timestamps(123456789, 12345)
        self.assertEqual(ast.get_user_count(get_mocked_message()), 0)
Exemple #3
0
    async def test_getUserCount(self):
        ast = AntiSpamTracker(AntiSpamHandler(get_mocked_bot()), 3)
        ast.update_cache(get_mocked_message(),
                         {"should_be_punished_this_message": True})

        user_count = ast.get_user_count(get_mocked_message())

        self.assertEqual(user_count, 1)

        for i in range(3):
            ast.update_cache(get_mocked_message(),
                             {"should_be_punished_this_message": True})
        user_count = ast.get_user_count(get_mocked_message())
        self.assertEqual(user_count, 4)

        with self.assertRaises(UserNotFound):
            message = get_mocked_message(guild_kwargs={"id": 15})
            ast.get_user_count(message)

        with self.assertRaises(UserNotFound):
            message = get_mocked_message(member_kwargs={"id": 25})
            ast.get_user_count(message)