mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Добавления тестов бекенда4
This commit is contained in:
21
backend/scripts/create-multiple-postgresql-databases.sh
Normal file
21
backend/scripts/create-multiple-postgresql-databases.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
function create_user_and_database() {
|
||||||
|
local database=$1
|
||||||
|
echo " Creating user and database '$database'"
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
|
||||||
|
CREATE DATABASE $database;
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE $database TO $POSTGRES_USER;
|
||||||
|
EOSQL
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
|
||||||
|
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
|
||||||
|
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
|
||||||
|
create_user_and_database $db
|
||||||
|
done
|
||||||
|
echo "Multiple databases created"
|
||||||
|
fi
|
||||||
@@ -5,16 +5,15 @@ from fastapi.testclient import TestClient
|
|||||||
from app.database import Base, get_db
|
from app.database import Base, get_db
|
||||||
from app.main import app
|
from app.main import app
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
|
SQLALCHEMY_DATABASE_URL = "postgresql://postgres:postgres123@postgres:5432/support_db_test"
|
||||||
|
|
||||||
engine = create_engine(
|
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
||||||
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
|
|
||||||
)
|
|
||||||
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def db_session():
|
def db_session():
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.drop_all(bind=engine) # Сначала удаляем все таблицы
|
||||||
|
Base.metadata.create_all(bind=engine) # Создаем таблицы заново
|
||||||
session = TestingSessionLocal()
|
session = TestingSessionLocal()
|
||||||
try:
|
try:
|
||||||
yield session
|
yield session
|
||||||
|
|||||||
Reference in New Issue
Block a user