diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..41d3096 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,39 @@ +name: Derbit Client workflow + +on: + push: + branches: + - "**" + pull_request: + +jobs: + lint: + name: Lint & Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Upgrade pip + run: python -m pip install --upgrade pip + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Black check + run: black --check . + + - name: Isort check + run: isort --check-only . + + - name: Flake8 check + run: flake8 . + + - name: Run pytest + run: pytest -v diff --git a/app/core/database.py b/app/core/database.py index 615d3de..fa2b68a 100644 --- a/app/core/database.py +++ b/app/core/database.py @@ -1,17 +1,5 @@ -from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine from sqlalchemy.orm import DeclarativeBase -from app.core.config import settings - -engine = create_async_engine(settings.database_url, future=True) - -async_session = async_sessionmaker(engine, expire_on_commit=False) - class Base(DeclarativeBase): pass - - -async def get_session(): - async with async_session() as session: - yield session diff --git a/app/core/session.py b/app/core/session.py new file mode 100644 index 0000000..cb7a8ee --- /dev/null +++ b/app/core/session.py @@ -0,0 +1,12 @@ +from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine + +from app.core.config import settings + +engine = create_async_engine(settings.database_url, future=True) + +async_session = async_sessionmaker(engine, expire_on_commit=False) + + +async def get_session(): + async with async_session() as session: + yield session diff --git a/app/routers/prices.py b/app/routers/prices.py index 12499cc..9280fcc 100644 --- a/app/routers/prices.py +++ b/app/routers/prices.py @@ -1,7 +1,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query from sqlalchemy.ext.asyncio import AsyncSession -from app.core.database import get_session +from app.core.session import get_session from app.crud.price_crud import CRUDPrice from app.schemas.prices import PriceReadSchema diff --git a/requirements.txt b/requirements.txt index 46a8557..93c1066 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ aiohappyeyeballs==2.6.1 aiohttp==3.13.3 aiosignal==1.4.0 +aiosqlite==0.22.1 alembic==1.18.1 amqp==5.3.1 annotated-doc==0.0.4 @@ -15,6 +16,7 @@ click==8.3.1 click-didyoumean==0.3.1 click-plugins==1.1.1.2 click-repl==0.3.0 +coverage==7.13.1 fastapi==0.128.0 flake8==7.3.0 frozenlist==1.8.0 @@ -43,6 +45,7 @@ pydantic_core==2.41.5 pyflakes==3.4.0 Pygments==2.19.2 pytest==9.0.2 +pytest-asyncio==1.3.0 python-dateutil==2.9.0.post0 python-dotenv==1.2.1 pytokens==0.3.0 diff --git a/tests/test_crud_price.py b/tests/test_crud_price.py index ff253a4..c4377c9 100644 --- a/tests/test_crud_price.py +++ b/tests/test_crud_price.py @@ -26,6 +26,8 @@ async def session(): async with engine.begin() as conn: await conn.run_sync(Base.metadata.drop_all) + await engine.dispose() + @pytest.mark.asyncio async def test_save_price(session):