mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Fix database
This commit is contained in:
@@ -1,8 +1,18 @@
|
|||||||
image: python:3.11
|
image: python:3.11
|
||||||
|
|
||||||
|
services:
|
||||||
|
- name: postgres:15
|
||||||
|
alias: postgres
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip-cache"
|
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip-cache"
|
||||||
PYTHONPATH: "$CI_PROJECT_DIR/backend"
|
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:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@@ -20,6 +30,8 @@ test:
|
|||||||
- source venv/bin/activate
|
- source venv/bin/activate
|
||||||
- cd backend
|
- cd backend
|
||||||
- pip install -r requirements.txt
|
- pip install -r requirements.txt
|
||||||
|
# Ждем, пока PostgreSQL будет готов
|
||||||
|
- python -c "import time; time.sleep(5)"
|
||||||
script:
|
script:
|
||||||
- python -m pytest -v --cov=app --cov-report=xml --timeout=30 -n auto
|
- python -m pytest -v --cov=app --cov-report=xml --timeout=30 -n auto
|
||||||
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
|
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from sqlalchemy import create_engine
|
|||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from sqlalchemy.pool import StaticPool
|
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.db.base import Base
|
||||||
from app.main import app
|
from app.main import app
|
||||||
from app.dependencies import get_db
|
from app.dependencies import get_db
|
||||||
@@ -29,10 +29,12 @@ def mock_telegram_notify(mocker):
|
|||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def engine():
|
def engine():
|
||||||
"""Create test database engine"""
|
"""Create test database engine"""
|
||||||
|
database_url = test_settings.get_database_url()
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
"sqlite:///:memory:",
|
database_url,
|
||||||
connect_args={"check_same_thread": False},
|
pool_pre_ping=True,
|
||||||
poolclass=StaticPool,
|
pool_size=5,
|
||||||
|
max_overflow=10
|
||||||
)
|
)
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
return engine
|
return engine
|
||||||
|
|||||||
Reference in New Issue
Block a user