提高代码覆盖率并提供显示代码覆盖率的工具

This commit is contained in:
2026-03-07 16:17:14 +08:00
parent ca1db103b5
commit 27e53c7acd
9 changed files with 200 additions and 15 deletions

View File

@ -7,6 +7,7 @@ from konabot.common.database import DatabaseManager
from konabot.common.permsys import PermManager
from konabot.common.permsys.entity import PermEntity
from konabot.common.permsys.migrates import execute_migration, get_current_version
from konabot.common.permsys.repo import PermRepo
@asynccontextmanager
@ -47,6 +48,17 @@ async def test_perm():
entity2 = PermEntity("nonexist-platform", "user", "jack")
chain2 = [entity2, entity_global]
async with db.get_conn() as conn:
repo = PermRepo(conn)
# 测试使用内置方法会创建 Entity 在数据库
assert await repo._get_entity_id_or_none(entity1) is None
assert await repo.get_entity_id(entity1) is not None
assert await repo._get_entity_id_or_none(entity1) is not None
# 测试使用内置方法获得 perm_info
assert await repo.get_perm_info(entity1, "module1") is None
assert not await service.check_has_permission(chain1, "*")
await service.update_permission(entity1, "*", True)
@ -83,3 +95,11 @@ async def test_perm():
assert await service.check_has_permission(chain2, "module2")
assert await service.check_has_permission(chain2, "module2.pack1")
assert await service.check_has_permission(chain2, "module2.pack2")
assert not await service.check_has_permission(entity2, "module2.pack2")
assert await service.check_has_permission(entity_global, "module2.pack2")
async with db.get_conn() as conn:
repo = PermRepo(conn)
assert await repo.get_perm_info(entity2, "module1") is True
assert await repo.get_perm_info(entity2, "module1.pack2") is False