Skip to content

Commit 156e1f9

Browse files
committed
fixed dependencies and refactored typing
1 parent f7175e4 commit 156e1f9

File tree

11 files changed

+162
-45
lines changed

11 files changed

+162
-45
lines changed

.coveragerc

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/python-package.yml renamed to .github/workflows/ci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
python-version: ["3.10", "3.11"]
23+
python-version: ["3.11", "3.12"]
2424

2525
steps:
26-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@master
2727
- name: Set up Python ${{ matrix.python-version }}
28-
uses: actions/setup-python@v3
28+
uses: actions/setup-python@master
2929
with:
3030
python-version: ${{ matrix.python-version }}
3131
- name: Tox
@@ -34,11 +34,11 @@ jobs:
3434
python -m pip install -U tox
3535
tox
3636
- name: Trunk Check
37-
uses: trunk-io/trunk-action@v1
38-
37+
uses: trunk-io/trunk-action@main
38+
3939
- name: Upload coverage reports to Codecov
40-
uses: codecov/codecov-action@v3
41-
40+
uses: codecov/codecov-action@main
41+
4242
with:
4343
token: ${{ secrets.CODECOV_TOKEN }}
4444
directory: ./

poetry.lock

Lines changed: 130 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ aiomysql = "^0.2.0"
1616
aiosqlite = "^0.19.0"
1717
fastapi-cli = "^0.0.4"
1818
fastapi = "^0.111.0"
19+
cryptography = "^42.0.8"
1920

2021
[tool.poetry.group.dev.dependencies]
2122
pytest = "^7.4.0"

tests/conftest.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from typing import AsyncGenerator
23

34
import pytest
45
import pytest_asyncio
@@ -14,16 +15,12 @@
1415

1516
SQLALCHEMY_DATABASE_URL = "sqlite+aiosqlite:///./test_db.db"
1617

17-
engine = create_async_engine(
18-
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
19-
)
20-
21-
SessionTesting = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
18+
engine = create_async_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False})
2219

2320

2421
@pytest_asyncio.fixture(scope="class")
2522
async def app():
26-
session = SessionTesting()
23+
session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)()
2724
app_test = FastAPI()
2825
app_test.dependency_overrides[get_db] = lambda: session
2926
app_test.include_router(bug_router)
@@ -35,7 +32,7 @@ async def app():
3532

3633

3734
@pytest_asyncio.fixture(scope="class")
38-
async def client(app: FastAPI) -> AsyncClient:
35+
async def client(app: FastAPI) -> AsyncGenerator[AsyncClient, None]:
3936
async with engine.begin() as conn:
4037
await conn.run_sync(Base.metadata.create_all)
4138

tox.ini

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ platform =
1616
passenv = *
1717
basepython = python3
1818
recreate = false
19-
20-
deps =
21-
poetry >= 1.3.2
19+
deps = poetry
2220

2321
commands =
2422
poetry install
@@ -28,8 +26,8 @@ commands =
2826

2927
commands =
3028
poetry install --with dev
31-
poetry run coverage run --source=. -m pytest -v
32-
poetry run coverage report -m
29+
poetry run coverage run --source=. -m pytest
30+
poetry run coverage report -m --fail-under=85
3331
poetry run coverage xml -o coverage.xml
3432

3533
; [testenv:docs-win32]

tracker/config/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
DBUSER = environ["MYSQL_USER"]
55
DBPASSWORD = environ["MYSQL_PASSWORD"]
66
DBHOST = environ["MYSQL_HOST"]
7-
DBPORT = environ["MYSQL_PORT"]
8-
DBPORT = int(DBPORT)
7+
DBPORT = int(environ["MYSQL_PORT"])

tracker/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
from tracker.views.story import router as story_router
99

1010

11-
def configure_router():
11+
async def configure_router():
1212
app.include_router(story_router)
1313
app.include_router(bug_router)
1414

1515

1616
async def configure():
17-
configure_router()
17+
await configure_router()
1818

1919

2020
@asynccontextmanager
2121
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
22-
configure()
22+
await configure()
2323
yield
2424
await engine.dispose()
2525

tracker/models/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ class Base(BaseModel):
99
__abstract__ = True
1010

1111
id: Mapped[int] = Column(Integer, primary_key=True, autoincrement=True, index=True)
12-
created_at: Mapped[TIMESTAMP] = Column(
13-
TIMESTAMP, server_default=func.now(), index=True
14-
)
12+
created_at: Mapped[TIMESTAMP] = Column(TIMESTAMP, server_default=func.now(), index=True)
1513
updated_at: Mapped[TIMESTAMP] = Column(
1614
TIMESTAMP,
1715
server_default=func.now(),

tracker/views/bug.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from typing import Annotated
2+
13
from fastapi import APIRouter, Depends
2-
from sqlalchemy.orm import Session
4+
from sqlalchemy.ext.asyncio import AsyncSession
35

46
from tracker.db.session import get_db
57
from tracker.serializers.bug import BugInput, BugOutput
@@ -10,23 +12,19 @@
1012

1113

1214
@router.post("/bugs/", response_model=BugOutput)
13-
# trunk-ignore(ruff/B008)
14-
async def create(bug: BugInput, db: Session = Depends(get_db)):
15+
async def create(bug: BugInput, db: Annotated[AsyncSession, Depends(get_db)]):
1516
obj = await create_bug(db=db, bug=bug)
1617

1718
return obj
1819

1920

2021
@router.get("/bugs/", response_model=list[BugOutput])
21-
# trunk-ignore(ruff/B008)
22-
async def get(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
22+
async def get(db: Annotated[AsyncSession, Depends(get_db)], skip: int = 0, limit: int = 10):
2323
return await bugs(db=db, skip=skip, limit=limit)
2424

2525

2626
@router.get("/bugs/{id}", response_model=BugOutput)
27-
# trunk-ignore(ruff/B008)
28-
async def get_bug(id: int, db: Session = Depends(get_db)):
27+
async def get_bug(id: int, db: Annotated[AsyncSession, Depends(get_db)]):
2928
obj = await bug_by_id(db=db, id=id)
30-
print(obj)
3129

3230
return obj

0 commit comments

Comments
 (0)