1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Fix database

This commit is contained in:
MoonTestUse1
2025-01-07 06:05:27 +06:00
parent e9f17ab3fb
commit d0142ee7ac
2 changed files with 18 additions and 4 deletions

View File

@@ -1,8 +1,18 @@
image: python:3.11
services:
- name: postgres:15
alias: postgres
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip-cache"
PYTHONPATH: "$CI_PROJECT_DIR/backend"
POSTGRES_DB: test_app
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/test_app"
TESTING: "1"
cache:
paths:
@@ -20,6 +30,8 @@ test:
- source venv/bin/activate
- cd backend
- pip install -r requirements.txt
# Ждем, пока PostgreSQL будет готов
- python -c "import time; time.sleep(5)"
script:
- python -m pytest -v --cov=app --cov-report=xml --timeout=30 -n auto
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'

View File

@@ -6,7 +6,7 @@ from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import StaticPool
from app.core.config import settings
from app.core.test_config import test_settings
from app.db.base import Base
from app.main import app
from app.dependencies import get_db
@@ -29,10 +29,12 @@ def mock_telegram_notify(mocker):
@pytest.fixture(scope="session")
def engine():
"""Create test database engine"""
database_url = test_settings.get_database_url()
engine = create_engine(
"sqlite:///:memory:",
connect_args={"check_same_thread": False},
poolclass=StaticPool,
database_url,
pool_pre_ping=True,
pool_size=5,
max_overflow=10
)
Base.metadata.create_all(bind=engine)
return engine