This commit is contained in:
34
tests/auth/test_auth_service.py
Normal file
34
tests/auth/test_auth_service.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
from services.auth import AuthService
|
||||
from services.db import local_session
|
||||
from auth.orm import Author
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ensure_user_has_reader_role():
|
||||
auth_service = AuthService()
|
||||
|
||||
# Создаем тестового пользователя без роли reader
|
||||
with local_session() as session:
|
||||
test_author = Author(
|
||||
email="test_reader_role@example.com",
|
||||
slug="test_reader_role",
|
||||
password="test_password"
|
||||
)
|
||||
session.add(test_author)
|
||||
session.commit()
|
||||
user_id = test_author.id
|
||||
|
||||
# Проверяем, что роль reader добавляется
|
||||
result = await auth_service.ensure_user_has_reader_role(user_id)
|
||||
assert result is True
|
||||
|
||||
# Проверяем, что при повторном вызове возвращается True
|
||||
result = await auth_service.ensure_user_has_reader_role(user_id)
|
||||
assert result is True
|
||||
|
||||
# Очищаем тестовые данные
|
||||
with local_session() as session:
|
||||
test_author = session.query(Author).filter_by(id=user_id).first()
|
||||
if test_author:
|
||||
session.delete(test_author)
|
||||
session.commit()
|
Reference in New Issue
Block a user