fix: add missing fixtures and improve test model constructor
- Add oauth_db_session fixture for OAuth tests - Add simple_user fixture for test data - Fix TestModel constructor to avoid pytest warning - Improve test isolation and cleanup
This commit is contained in:
@@ -246,6 +246,44 @@ with (
|
|||||||
# Импортируем необходимые модели
|
# Импортируем необходимые модели
|
||||||
from orm.community import Community, CommunityAuthor
|
from orm.community import Community, CommunityAuthor
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def oauth_db_session():
|
||||||
|
"""Фикстура для сессии базы данных в OAuth тестах"""
|
||||||
|
from services.db import local_session
|
||||||
|
session = local_session()
|
||||||
|
try:
|
||||||
|
yield session
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def simple_user(oauth_db_session):
|
||||||
|
"""Фикстура для простого пользователя"""
|
||||||
|
from auth.orm import Author
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Создаем тестового пользователя
|
||||||
|
user = Author(
|
||||||
|
email="simple@test.com",
|
||||||
|
name="Simple User",
|
||||||
|
slug="simple-user",
|
||||||
|
email_verified=True,
|
||||||
|
created_at=int(time.time()),
|
||||||
|
updated_at=int(time.time()),
|
||||||
|
last_seen=int(time.time())
|
||||||
|
)
|
||||||
|
oauth_db_session.add(user)
|
||||||
|
oauth_db_session.commit()
|
||||||
|
|
||||||
|
yield user
|
||||||
|
|
||||||
|
# Очистка
|
||||||
|
try:
|
||||||
|
oauth_db_session.query(Author).where(Author.id == user.id).delete()
|
||||||
|
oauth_db_session.commit()
|
||||||
|
except Exception:
|
||||||
|
oauth_db_session.rollback()
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def test_community(oauth_db_session, simple_user):
|
def test_community(oauth_db_session, simple_user):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ class TestModel(Base):
|
|||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
name = Column(String)
|
name = Column(String)
|
||||||
description = Column(String, nullable=True)
|
description = Column(String, nullable=True)
|
||||||
|
|
||||||
|
def __init__(self, name: str = None, description: str = None):
|
||||||
|
self.name = name
|
||||||
|
self.description = description
|
||||||
|
|
||||||
class TestDatabaseFunctions:
|
class TestDatabaseFunctions:
|
||||||
"""Тесты для функций работы с базой данных"""
|
"""Тесты для функций работы с базой данных"""
|
||||||
|
|||||||
Reference in New Issue
Block a user