tests-fix-1
This commit is contained in:
@@ -93,9 +93,9 @@ class TestCommunityRoleInheritance:
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Author должен иметь разрешение {perm}"
|
||||
|
||||
def test_community_editor_role_inheritance(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_editor_role_inheritance(self, session, unique_email, unique_slug):
|
||||
"""Тест наследования ролей для editor в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -118,7 +118,7 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Создаем CommunityAuthor с ролью editor
|
||||
ca = CommunityAuthor(
|
||||
@@ -132,24 +132,24 @@ class TestCommunityRoleInheritance:
|
||||
# Проверяем что editor наследует разрешения author
|
||||
author_permissions = ["draft:create", "shout:create", "collection:create"]
|
||||
for perm in author_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Editor должен наследовать разрешение {perm} от author"
|
||||
|
||||
# Проверяем что editor наследует разрешения reader через author
|
||||
reader_permissions = ["shout:read", "topic:read", "collection:read"]
|
||||
for perm in reader_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Editor должен наследовать разрешение {perm} от reader через author"
|
||||
|
||||
# Проверяем специфичные разрешения editor
|
||||
editor_permissions = ["shout:delete_any", "shout:update_any", "topic:create", "community:create"]
|
||||
for perm in editor_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Editor должен иметь разрешение {perm}"
|
||||
|
||||
def test_community_admin_role_inheritance(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_admin_role_inheritance(self, session, unique_email, unique_slug):
|
||||
"""Тест наследования ролей для admin в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -172,7 +172,7 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Создаем CommunityAuthor с ролью admin
|
||||
ca = CommunityAuthor(
|
||||
@@ -192,12 +192,12 @@ class TestCommunityRoleInheritance:
|
||||
]
|
||||
|
||||
for perm in all_role_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Admin должен иметь разрешение {perm} через наследование"
|
||||
|
||||
def test_community_expert_role_inheritance(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_expert_role_inheritance(self, session, unique_email, unique_slug):
|
||||
"""Тест наследования ролей для expert в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -220,7 +220,7 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Создаем CommunityAuthor с ролью expert
|
||||
ca = CommunityAuthor(
|
||||
@@ -234,24 +234,24 @@ class TestCommunityRoleInheritance:
|
||||
# Проверяем что expert наследует разрешения reader
|
||||
reader_permissions = ["shout:read", "topic:read", "collection:read"]
|
||||
for perm in reader_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Expert должен наследовать разрешение {perm} от reader"
|
||||
|
||||
# Проверяем специфичные разрешения expert
|
||||
expert_permissions = ["reaction:create:PROOF", "reaction:create:DISPROOF", "reaction:create:AGREE"]
|
||||
for perm in expert_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Expert должен иметь разрешение {perm}"
|
||||
|
||||
# Проверяем что expert НЕ имеет разрешения author
|
||||
author_permissions = ["draft:create", "shout:create"]
|
||||
for perm in author_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert not has_permission, f"Expert НЕ должен иметь разрешение {perm}"
|
||||
|
||||
def test_community_artist_role_inheritance(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_artist_role_inheritance(self, session, unique_email, unique_slug):
|
||||
"""Тест наследования ролей для artist в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -274,7 +274,7 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Создаем CommunityAuthor с ролью artist
|
||||
ca = CommunityAuthor(
|
||||
@@ -288,24 +288,24 @@ class TestCommunityRoleInheritance:
|
||||
# Проверяем что artist наследует разрешения author
|
||||
author_permissions = ["draft:create", "shout:create", "collection:create"]
|
||||
for perm in author_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Artist должен наследовать разрешение {perm} от author"
|
||||
|
||||
# Проверяем что artist наследует разрешения reader через author
|
||||
reader_permissions = ["shout:read", "topic:read", "collection:read"]
|
||||
for perm in reader_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Artist должен наследовать разрешение {perm} от reader через author"
|
||||
|
||||
# Проверяем специфичные разрешения artist
|
||||
artist_permissions = ["reaction:create:CREDIT", "reaction:read:CREDIT", "reaction:update:CREDIT"]
|
||||
for perm in artist_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Artist должен иметь разрешение {perm}"
|
||||
|
||||
def test_community_multiple_roles_inheritance(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_multiple_roles_inheritance(self, session, unique_email, unique_slug):
|
||||
"""Тест множественных ролей с наследованием в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -328,7 +328,7 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Создаем CommunityAuthor с несколькими ролями
|
||||
ca = CommunityAuthor(
|
||||
@@ -342,24 +342,24 @@ class TestCommunityRoleInheritance:
|
||||
# Проверяем разрешения от роли author
|
||||
author_permissions = ["draft:create", "shout:create", "collection:create"]
|
||||
for perm in author_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Пользователь с ролями author,expert должен иметь разрешение {perm} от author"
|
||||
|
||||
# Проверяем разрешения от роли expert
|
||||
expert_permissions = ["reaction:create:PROOF", "reaction:create:DISPROOF", "reaction:create:AGREE"]
|
||||
for perm in expert_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Пользователь с ролями author,expert должен иметь разрешение {perm} от expert"
|
||||
|
||||
# Проверяем общие разрешения от reader (наследуются обеими ролями)
|
||||
reader_permissions = ["shout:read", "topic:read", "collection:read"]
|
||||
for perm in reader_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Пользователь с ролями author,expert должен иметь разрешение {perm} от reader"
|
||||
|
||||
def test_community_roles_have_permission_inheritance(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_roles_have_permission_inheritance(self, session, unique_email, unique_slug):
|
||||
"""Тест функции roles_have_permission с наследованием в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -382,27 +382,27 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Проверяем что editor имеет разрешения author через наследование
|
||||
has_author_permission = roles_have_permission(["editor"], "draft:create", community.id)
|
||||
has_author_permission = await roles_have_permission(["editor"], "draft:create", community.id)
|
||||
assert has_author_permission, "Editor должен иметь разрешение draft:create через наследование от author"
|
||||
|
||||
# Проверяем что admin имеет разрешения reader через наследование
|
||||
has_reader_permission = roles_have_permission(["admin"], "shout:read", community.id)
|
||||
has_reader_permission = await roles_have_permission(["admin"], "shout:read", community.id)
|
||||
assert has_reader_permission, "Admin должен иметь разрешение shout:read через наследование от reader"
|
||||
|
||||
# Проверяем что artist имеет разрешения author через наследование
|
||||
has_artist_author_permission = roles_have_permission(["artist"], "shout:create", community.id)
|
||||
has_artist_author_permission = await roles_have_permission(["artist"], "shout:create", community.id)
|
||||
assert has_artist_author_permission, "Artist должен иметь разрешение shout:create через наследование от author"
|
||||
|
||||
# Проверяем что expert НЕ имеет разрешения author
|
||||
has_expert_author_permission = roles_have_permission(["expert"], "draft:create", community.id)
|
||||
has_expert_author_permission = await roles_have_permission(["expert"], "draft:create", community.id)
|
||||
assert not has_expert_author_permission, "Expert НЕ должен иметь разрешение draft:create"
|
||||
|
||||
def test_community_deep_inheritance_chain(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_deep_inheritance_chain(self, session, unique_email, unique_slug):
|
||||
"""Тест глубокой цепочки наследования в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -425,7 +425,7 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Создаем CommunityAuthor с ролью admin
|
||||
ca = CommunityAuthor(
|
||||
@@ -446,12 +446,12 @@ class TestCommunityRoleInheritance:
|
||||
]
|
||||
|
||||
for perm in inheritance_chain_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Admin должен иметь разрешение {perm} через цепочку наследования"
|
||||
|
||||
def test_community_permission_denial_with_inheritance(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_permission_denial_with_inheritance(self, session, unique_email, unique_slug):
|
||||
"""Тест отказа в разрешениях с учетом наследования в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -474,7 +474,7 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Создаем CommunityAuthor с ролью reader
|
||||
ca = CommunityAuthor(
|
||||
@@ -496,12 +496,12 @@ class TestCommunityRoleInheritance:
|
||||
]
|
||||
|
||||
for perm in denied_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert not has_permission, f"Reader НЕ должен иметь разрешение {perm}"
|
||||
|
||||
def test_community_role_permissions_consistency(self, session, unique_email, unique_slug):
|
||||
@pytest.mark.asyncio
|
||||
async def test_community_role_permissions_consistency(self, session, unique_email, unique_slug):
|
||||
"""Тест консистентности разрешений ролей в сообществе"""
|
||||
pytest.skip("Community RBAC тесты временно отключены из-за проблем с Redis")
|
||||
# Создаем тестового пользователя
|
||||
user = Author(
|
||||
email=unique_email,
|
||||
@@ -524,7 +524,7 @@ class TestCommunityRoleInheritance:
|
||||
session.add(community)
|
||||
session.flush()
|
||||
|
||||
initialize_community_permissions(community.id)
|
||||
await initialize_community_permissions(community.id)
|
||||
|
||||
# Проверяем что все роли имеют корректные разрешения
|
||||
role_permissions_map = {
|
||||
@@ -548,7 +548,7 @@ class TestCommunityRoleInheritance:
|
||||
|
||||
# Проверяем что роль имеет ожидаемые разрешения
|
||||
for perm in expected_permissions:
|
||||
has_permission = user_has_permission(user.id, perm, community.id)
|
||||
has_permission = await user_has_permission(user.id, perm, community.id)
|
||||
assert has_permission, f"Роль {role} должна иметь разрешение {perm}"
|
||||
|
||||
# Удаляем запись для следующей итерации
|
||||
|
||||
Reference in New Issue
Block a user