Compare commits
No commits in common. "c6e8e78c95ac93c83fbdea1505a51f67d24c2d1e" and "43eca19d91902e1fd0b026a00dd8af59265b4737" have entirely different histories.
c6e8e78c95
...
43eca19d91
|
@ -8,10 +8,6 @@ RUN mkdir -p /usr/src/fastfood
|
||||||
|
|
||||||
WORKDIR /usr/src/fastfood
|
WORKDIR /usr/src/fastfood
|
||||||
|
|
||||||
COPY ./pyproject.toml .
|
COPY . .
|
||||||
|
|
||||||
COPY ./poetry.lock .
|
|
||||||
|
|
||||||
RUN touch /usr/src/RUN_IN_DOCKER
|
|
||||||
|
|
||||||
RUN poetry install
|
RUN poetry install
|
||||||
|
|
|
@ -1,19 +1,5 @@
|
||||||
version: "3.8"
|
version: "3.8"
|
||||||
services:
|
services:
|
||||||
redis:
|
|
||||||
container_name: redis_test
|
|
||||||
|
|
||||||
image: redis:7.2.4-alpine3.19
|
|
||||||
|
|
||||||
ports:
|
|
||||||
- '6380:6379'
|
|
||||||
|
|
||||||
healthcheck:
|
|
||||||
test: [ "CMD", "redis-cli","ping" ]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
|
|
||||||
db:
|
db:
|
||||||
container_name: pgdb
|
container_name: pgdb
|
||||||
|
|
||||||
|
@ -52,8 +38,6 @@ services:
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
|
||||||
condition: service_healthy
|
|
||||||
|
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,5 @@
|
||||||
version: "3.8"
|
version: "3.8"
|
||||||
services:
|
services:
|
||||||
redis:
|
|
||||||
container_name: redis_test
|
|
||||||
|
|
||||||
image: redis:7.2.4-alpine3.19
|
|
||||||
|
|
||||||
ports:
|
|
||||||
- '6380:6379'
|
|
||||||
|
|
||||||
healthcheck:
|
|
||||||
test: [ "CMD", "redis-cli","ping" ]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
|
|
||||||
db:
|
db:
|
||||||
container_name: pgdb_test
|
container_name: pgdb_test
|
||||||
|
|
||||||
|
@ -52,11 +38,6 @@ services:
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
|
||||||
condition: service_healthy
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
- .:/usr/src/fastfood
|
|
||||||
|
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import os
|
|
||||||
|
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,20 +11,10 @@ class Settings(BaseSettings):
|
||||||
REDIS_DB: str = ''
|
REDIS_DB: str = ''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def DATABASE_URL_asyncpg(self) -> str:
|
def DATABASE_URL_asyncpg(self):
|
||||||
"""
|
"""
|
||||||
Возвращает строку подключения к БД необходимую для SQLAlchemy
|
Возвращает строку подключения к БД необходимую для SQLAlchemy
|
||||||
"""
|
"""
|
||||||
# Проверяем, в DOCKER или нет
|
|
||||||
|
|
||||||
file_path = '/usr/src/RUN_IN_DOCKER'
|
|
||||||
if os.path.exists(file_path):
|
|
||||||
return (
|
|
||||||
'postgresql+asyncpg://'
|
|
||||||
f'{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}'
|
|
||||||
f'@db:{self.DB_PORT}/{self.POSTGRES_DB}'
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
'postgresql+asyncpg://'
|
'postgresql+asyncpg://'
|
||||||
f'{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}'
|
f'{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}'
|
||||||
|
@ -38,28 +26,12 @@ class Settings(BaseSettings):
|
||||||
"""
|
"""
|
||||||
Возвращает строку подключения к БД необходимую для SQLAlchemy
|
Возвращает строку подключения к БД необходимую для SQLAlchemy
|
||||||
"""
|
"""
|
||||||
file_path = '/usr/src/RUN_IN_DOCKER'
|
|
||||||
if os.path.exists(file_path):
|
|
||||||
return (
|
|
||||||
'postgresql+asyncpg://'
|
|
||||||
f'{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}'
|
|
||||||
f'@db:{self.DB_PORT}/{self.POSTGRES_DB_TEST}'
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
'postgresql+asyncpg://'
|
'postgresql+asyncpg://'
|
||||||
f'{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}'
|
f'{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}'
|
||||||
f'@{self.DB_HOST}:{self.DB_PORT}/{self.POSTGRES_DB_TEST}'
|
f'@{self.DB_HOST}:{self.DB_PORT}/{self.POSTGRES_DB_TEST}'
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def REDIS_URL(self):
|
|
||||||
file_path = '/usr/src/RUN_IN_DOCKER'
|
|
||||||
if os.path.exists(file_path):
|
|
||||||
return 'redis://redis:6379/0'
|
|
||||||
|
|
||||||
return self.REDIS_DB
|
|
||||||
|
|
||||||
model_config = SettingsConfigDict(env_file='.env')
|
model_config = SettingsConfigDict(env_file='.env')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
|
||||||
|
|
||||||
|
|
||||||
def get_redis_pool():
|
def get_redis_pool():
|
||||||
return redis.from_url(settings.REDIS_URL, decode_responses=False)
|
return redis.from_url(settings.REDIS_DB, decode_responses=False)
|
||||||
|
|
||||||
|
|
||||||
async def get_async_redis_client(
|
async def get_async_redis_client(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator, Generator
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
@ -45,13 +45,22 @@ async def get_test_session() -> AsyncGenerator[AsyncSession, None]:
|
||||||
yield session
|
yield session
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
async def client(event_loop) -> AsyncGenerator[AsyncClient, None]:
|
def app(event_loop) -> Generator[FastAPI, None, None]:
|
||||||
app: FastAPI = create_app()
|
app: FastAPI = create_app()
|
||||||
app.dependency_overrides[get_async_session] = get_test_session
|
app.dependency_overrides[get_async_session] = get_test_session
|
||||||
|
yield app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest_asyncio.fixture(scope='session')
|
||||||
|
async def client(app) -> AsyncGenerator[AsyncClient, None]:
|
||||||
async with AsyncClient(
|
async with AsyncClient(
|
||||||
app=app,
|
app=app,
|
||||||
base_url='http://localhost:8000/api/v1/menus',
|
base_url='http://localhost:8000/api/v1/menus',
|
||||||
) as async_client:
|
) as async_client:
|
||||||
yield async_client
|
yield async_client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def session_data() -> dict:
|
||||||
|
return {}
|
||||||
|
|
|
@ -4,11 +4,6 @@ from httpx import AsyncClient
|
||||||
from .repository import Repository as Repo
|
from .repository import Repository as Repo
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module', autouse=True)
|
|
||||||
def session_data() -> dict:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_01(client: AsyncClient, session_data: dict):
|
async def test_01(client: AsyncClient, session_data: dict):
|
||||||
"""Проверяет создание меню"""
|
"""Проверяет создание меню"""
|
||||||
|
|
Loading…
Reference in New Issue