Skip to content

Commit

Permalink
refactoring api main for composite in future
Browse files Browse the repository at this point in the history
  • Loading branch information
bomzheg committed Oct 28, 2023
1 parent fef7bc3 commit cb614d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
5 changes: 1 addition & 4 deletions shvatka/api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import uvicorn
from fastapi import FastAPI

from shvatka.api import dependencies, routes
from shvatka.api.config.parser.main import load_config
from shvatka.api.main_factory import (
get_paths,
Expand All @@ -20,10 +19,8 @@ def main() -> FastAPI:

setup_logging(paths)
config = load_config(paths)
app = create_app()
pool = create_pool(config.db)
dependencies.setup(app=app, pool=pool, redis=create_redis(config.redis), config=config)
routes.setup(app.router)
app = create_app(pool=pool, redis=create_redis(config.redis), config=config)

logger.info("app prepared")
return app
Expand Down
11 changes: 9 additions & 2 deletions shvatka/api/main_factory.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import logging

from fastapi import FastAPI
from redis.asyncio import Redis
from sqlalchemy.ext.asyncio import async_sessionmaker, AsyncSession

from shvatka.api import dependencies, routes
from shvatka.api.config.models.main import ApiConfig
from shvatka.common.config.models.paths import Paths
from shvatka.common.config.parser.paths import common_get_paths

logger = logging.getLogger(__name__)


def create_app() -> FastAPI:
return FastAPI()
def create_app(pool: async_sessionmaker[AsyncSession], redis: Redis, config: ApiConfig) -> FastAPI:
app = FastAPI()
dependencies.setup(app=app, pool=pool, redis=redis, config=config)
routes.setup(app.router)
return app


def get_paths() -> Paths:
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/api_full/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from redis.asyncio.client import Redis
from sqlalchemy.ext.asyncio import async_sessionmaker, AsyncSession

from shvatka.api import dependencies, routes
from shvatka.api.config.models.main import ApiConfig
from shvatka.api.config.parser.main import load_config
from shvatka.api.dependencies import AuthProvider
Expand All @@ -32,9 +31,7 @@ def patch_api_config(api_config: ApiConfig, postgres_url: str, redis: Redis):

@pytest.fixture(scope="session")
def app(api_config: ApiConfig, pool: async_sessionmaker[AsyncSession], redis: Redis) -> FastAPI:
app = create_app()
dependencies.setup(app=app, pool=pool, redis=redis, config=api_config)
routes.setup(app.router)
app = create_app(pool=pool, redis=redis, config=api_config)
return app


Expand Down

0 comments on commit cb614d5

Please sign in to comment.