Skip to content

Refactor #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@master
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@master
with:
python-version: ${{ matrix.python-version }}
- name: Tox
Expand All @@ -34,11 +34,11 @@ jobs:
python -m pip install -U tox
tox
- name: Trunk Check
uses: trunk-io/trunk-action@v1
uses: trunk-io/trunk-action@main

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@main

with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./
Expand Down
1 change: 1 addition & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
plugins
user_trunk.yaml
user.yaml
tmp
33 changes: 16 additions & 17 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
version: 0.1
cli:
version: 1.15.0
version: 1.22.2
plugins:
sources:
- id: trunk
ref: v1.2.3
ref: v1.6.0
uri: https://github.com/trunk-io/plugins
runtimes:
enabled:
- node@18.12.1
- python@3.10.8
lint:
enabled:
- actionlint@1.6.25
- checkov@2.4.9
- isort@5.12.0
- osv-scanner@1.3.6
- yamllint@1.32.0
- bandit@1.7.5
- black@23.7.0
- actionlint@1.7.1
- checkov@3.2.136
- isort@5.13.2
- osv-scanner@1.7.4
- yamllint@1.35.1
- bandit@1.7.9
- black@24.4.2
- git-diff-check
- markdownlint@0.36.0
- prettier@3.0.3
- ruff@0.0.287
- markdownlint@0.41.0
- prettier@3.3.2
- ruff@0.4.8
- taplo@0.8.1
- trivy@0.45.0
- trufflehog@3.54.3
- trivy@0.52.1
- trufflehog@3.78.1

ignore:
- linters: [ALL]
Expand All @@ -35,9 +35,8 @@ lint:
- Dockerfile
- .github/workflows/*.yml
actions:
disabled:
enabled:
- trunk-upgrade-available
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
enabled:
- trunk-upgrade-available
6 changes: 3 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ coverage:
precision: 2
round: up
# trunk-ignore(yamllint/quoted-strings)
range: "95...100"
range: "85...100"
status:
patch:
default:
target: 95%
target: 85%
project:
default:
target: 95%
target: 85%
2,070 changes: 984 additions & 1,086 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
[tool.poetry]
name = "tracker"
version = "2.1.15"
description = ""
authors = ["Masum Billal <proafxin@users.noreply.github.com>"]
description = "A simple bug tracking API"
authors = ["Masum Billal <billalmasum93@gmail.com>"]
license = "LICENSE"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
fastapi-myhelper = "^0.1.7"
fastapi = { extras = ["all"], version = "^0.103.0" }
uvicorn = { extras = ["standard"], version = "^0.23.2" }
python = "^3.11"
sqlalchemy = "^2.0.20"
mysqlclient = "^2.2.0"
pymysql = "^1.1.0"
alembic = "^1.11.3"
aiomysql = "^0.2.0"
aiosqlite = "^0.19.0"
fastapi-cli = "^0.0.4"
fastapi = "^0.111.0"
cryptography = "^42.0.8"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
coverage = "^7.3.0"
pytest-asyncio = "^0.21.1"
gevent = "^23.9.0.post1"

[tool.pytest]
asyncio_mode = "auto"

[tool.ruff]
line-length = 100

[build-system]
requires = ["poetry-core"]
Expand Down
7 changes: 3 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from typing import AsyncGenerator

import pytest
import pytest_asyncio
Expand All @@ -18,12 +19,10 @@
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)

SessionTesting = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)


@pytest_asyncio.fixture(scope="class")
async def app():
session = SessionTesting()
session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)()
app_test = FastAPI()
app_test.dependency_overrides[get_db] = lambda: session
app_test.include_router(bug_router)
Expand All @@ -35,7 +34,7 @@ async def app():


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

Expand Down
2 changes: 1 addition & 1 deletion tests/views/test_bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def __test_bug(self, bug: dict):

@pytest.mark.asyncio
async def test_create(self, client: AsyncClient) -> None:
json = {"name": "Test Story"}
json: dict[str, str | int] = {"name": "Test Story"}
await client.post("/stories/", json=json)
json = {
"title": "Test Bug",
Expand Down
16 changes: 7 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]

envlist =
envlist =
py3, tests
; docs-{linux, win32}
skipsdist = true
Expand All @@ -16,20 +16,18 @@ platform =
passenv = *
basepython = python3
recreate = false

deps =
poetry >= 1.3.2
deps = poetry

commands =
poetry install


[testenv:tests]

commands =
commands =
poetry install --with dev
poetry run coverage run -m pytest -v
poetry run coverage report -m
poetry run coverage run --source=. -m pytest
poetry run coverage report -m --fail-under=85
poetry run coverage xml -o coverage.xml

; [testenv:docs-win32]
Expand All @@ -49,8 +47,8 @@ commands =
; allowlist_externals = *

; changedir = docs
; commands =
; commands =
; poetry install --with docs
; poetry run sphinx-apidoc -f -o source/ ../ ../tests/
; make clean
; make html
; make html
3 changes: 1 addition & 2 deletions tracker/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
DBUSER = environ["MYSQL_USER"]
DBPASSWORD = environ["MYSQL_PASSWORD"]
DBHOST = environ["MYSQL_HOST"]
DBPORT = environ["MYSQL_PORT"]
DBPORT = int(DBPORT)
DBPORT = int(environ["MYSQL_PORT"])
29 changes: 16 additions & 13 deletions tracker/main.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
from contextlib import asynccontextmanager
from typing import AsyncGenerator

Check warning on line 2 in tracker/main.py

View check run for this annotation

Codecov / codecov/patch

tracker/main.py#L1-L2

Added lines #L1 - L2 were not covered by tests

from fastapi import FastAPI

from tracker.db.session import engine
from tracker.views.bug import router as bug_router
from tracker.views.story import router as story_router

app = FastAPI(title="Bug Tracker", description="Simple bug tracking API.")


@app.on_event(event_type="startup")
async def start():
await configure()
async def configure_router():
app.include_router(story_router)
app.include_router(bug_router)

Check warning on line 13 in tracker/main.py

View check run for this annotation

Codecov / codecov/patch

tracker/main.py#L11-L13

Added lines #L11 - L13 were not covered by tests


@app.on_event(event_type="shutdown")
async def shutdown():
await engine.dispose()
async def configure():
await configure_router()

Check warning on line 17 in tracker/main.py

View check run for this annotation

Codecov / codecov/patch

tracker/main.py#L16-L17

Added lines #L16 - L17 were not covered by tests


def configure_router():
app.include_router(story_router)
app.include_router(bug_router)
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
await configure()
yield
await engine.dispose()

Check warning on line 24 in tracker/main.py

View check run for this annotation

Codecov / codecov/patch

tracker/main.py#L20-L24

Added lines #L20 - L24 were not covered by tests


async def configure():
configure_router()
app = FastAPI(

Check warning on line 27 in tracker/main.py

View check run for this annotation

Codecov / codecov/patch

tracker/main.py#L27

Added line #L27 was not covered by tests
title="Bug Tracker", description="Simple bug tracking API.", lifespan=lifespan
)
16 changes: 8 additions & 8 deletions tracker/views/bug.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Annotated

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from sqlalchemy.ext.asyncio import AsyncSession

from tracker.db.session import get_db
from tracker.serializers.bug import BugInput, BugOutput
Expand All @@ -10,23 +12,21 @@


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

return obj


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


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

return obj
15 changes: 8 additions & 7 deletions tracker/views/story.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Annotated

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from sqlalchemy.ext.asyncio import AsyncSession

from tracker.db.session import get_db
from tracker.serializers.story import StoryInput, StoryOutput
Expand All @@ -10,22 +12,21 @@


@router.post("/stories/", response_model=StoryOutput)
# trunk-ignore(ruff/B008)
async def create(story: StoryInput, db: Session = Depends(get_db)):
async def create(story: StoryInput, db: Annotated[AsyncSession, Depends(get_db)]):
obj = await create_story(db=db, story=story)

return obj


@router.get("/stories/", response_model=list[StoryOutput])
# trunk-ignore(ruff/B008)
async def get_stories(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
async def get_stories(
db: Annotated[AsyncSession, Depends(get_db)], skip: int = 0, limit: int = 10
):
return await stories(db=db, skip=skip, limit=limit)


@router.get("/stories/{id}", response_model=StoryOutput)
# trunk-ignore(ruff/B008)
async def get_story(id: int, db: Session = Depends(get_db)):
async def get_story(id: int, db: Annotated[AsyncSession, Depends(get_db)]):
obj = await story_by_id(db=db, id=id)

return obj
Loading