karkas/src/modules/standart/roles/tests/test_roles.py

36 lines
1.6 KiB
Python

import unittest
from src.modules.standart.database.api import create_tables, add_user
from src.modules.standart.database.models.base import database
from src.modules.standart.roles.api import Roles
import asyncio
create_tables(database)
class TestRoles(unittest.IsolatedAsyncioTestCase):
async def asyncSetUp(self):
self.roles = Roles()
async def test_check_admin_permission(self):
self.assertTrue(await self.roles.check_admin_permission(1))
self.assertFalse(await self.roles.check_admin_permission(2))
self.assertFalse(await self.roles.check_admin_permission(3))
self.assertFalse(await self.roles.check_admin_permission(4))
async def test_check_moderator_permission(self):
self.assertTrue(await self.roles.check_moderator_permission(2))
self.assertFalse(await self.roles.check_moderator_permission(0))
self.assertFalse(await self.roles.check_moderator_permission(1))
self.assertFalse(await self.roles.check_moderator_permission(3))
async def test_get_role_name(self):
self.assertEqual(await self.roles.get_role_name(self.roles.admin_role_id), "ADMIN")
self.assertEqual(await self.roles.get_role_name(self.roles.moderator_role_id), "MODERATOR")
self.assertEqual(await self.roles.get_role_name(self.roles.user_role_id), "USER")
self.assertEqual(await self.roles.get_role_name(self.roles.bot_role_id), "BOT")
with self.assertRaises(ValueError):
await self.roles.get_role_name(999) # Несуществующий ID роли
if __name__ == '__main__':
unittest.main()