fix: use proper test fixtures instead of local_session
Some checks failed
Deploy on push / deploy (push) Failing after 2m17s
Some checks failed
Deploy on push / deploy (push) Failing after 2m17s
- Replace local_session() calls with db_session fixture in tests - Add @pytest.mark.asyncio decorators to async test functions - Fix test_unpublish_shout.py to use proper test database setup - Tests now use in-memory SQLite database with proper schema - All test tables are created automatically via conftest.py fixtures
This commit is contained in:
@@ -1,24 +1,22 @@
|
||||
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():
|
||||
async def test_ensure_user_has_reader_role(db_session):
|
||||
"""Тест добавления роли reader пользователю"""
|
||||
|
||||
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
|
||||
test_author = Author(
|
||||
email="test_reader_role@example.com",
|
||||
slug="test_reader_role",
|
||||
password="test_password"
|
||||
)
|
||||
db_session.add(test_author)
|
||||
db_session.commit()
|
||||
user_id = test_author.id
|
||||
|
||||
try:
|
||||
# Проверяем, что роль reader добавляется
|
||||
@@ -30,8 +28,7 @@ async def test_ensure_user_has_reader_role():
|
||||
assert result is True
|
||||
finally:
|
||||
# Очищаем тестовые данные
|
||||
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()
|
||||
test_author = db_session.query(Author).filter_by(id=user_id).first()
|
||||
if test_author:
|
||||
db_session.delete(test_author)
|
||||
db_session.commit()
|
||||
|
||||
Reference in New Issue
Block a user