/
burevol
/
GymAssistant
Обзор
Документация
Войти
/
burevol
/
GymAssistant
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
features/sqlalchemy
tests/test_db.py
52 строки
1 KB
Alexander Maximov
Добавлена возможность работы с PostgreSQL
09 май 2025, 00:02
09 май 2025, 00:02
c9ea399
Код
Авторство
О чём код?
import pytest from sqlalchemy import select from utils import Db from utils.db import User @pytest.fixture async def db(): db = Db() user_exists = await db.user_exists(username="johndoe") if not user_exists: async with db.AsyncSessionLocal() as session: # noinspection SpellCheckingInspection fake_user = User(username="johndoe", hashed_password="$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", disabled=False) session.add(fake_user) await session.commit() await session.refresh(fake_user) yield db await db.delete_user('johndoe') await db.async_engine.dispose() @pytest.fixture async def clean_db(): db = Db() yield db await db.async_engine.dispose() def test_db(db): assert db assert isinstance(db.url, str) async def test_create_user(clean_db): await clean_db.create_first_user() async def test_get_user(db): assert await db.get_user("johndoe") async def test_repr(db): async with db.AsyncSessionLocal() as session: stmt = select(User).where(User.username == "johndoe") result = await session.scalar(stmt) assert str(result) == "<User johndoe>"