-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from profcomff/backend-fixes
Add simple logic, fix tests, linting
- Loading branch information
Showing
14 changed files
with
86 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import os | ||
|
||
|
||
__version__ = os.getenv("APP_VERSION", "dev") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import uvicorn | ||
|
||
from my_app_api.routes import app | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
uvicorn.run(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class APIError(Exception): | ||
"""Base class for API errors""" | ||
|
||
def __init__(self, message: str) -> None: | ||
super().__init__(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
from auth_lib.fastapi import UnionAuth | ||
from fastapi import APIRouter, Depends | ||
from pydantic import BaseModel | ||
|
||
logger = logging.getLogger(__name__) | ||
router = APIRouter(prefix="/example", tags=["Example"]) | ||
|
||
CLICKS: dict[int, int] = {} | ||
|
||
|
||
class WhoAmI(BaseModel): | ||
id: int | ||
|
||
|
||
class TouchGet(WhoAmI): | ||
count: int | ||
|
||
|
||
@router.get("/whoami", response_model=WhoAmI) | ||
def whoami(auth=Depends(UnionAuth(allow_none=False))): | ||
return {"id": auth["id"]} | ||
|
||
|
||
@router.post("/touch", response_model=TouchGet) | ||
def touch(auth=Depends(UnionAuth(allow_none=False))): | ||
if auth["id"] not in CLICKS: | ||
CLICKS[auth["id"]] = 0 | ||
CLICKS[auth["id"]] += 1 | ||
return {"id": auth["id"], "count": CLICKS[auth["id"]]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ isort | |
pytest | ||
pytest-cov | ||
pytest-mock | ||
auth-lib-profcomff[testing] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from my_app_api.routes import app | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
client = TestClient(app) | ||
yield client |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.authenticated() | ||
def test_whoami(client): | ||
resp = client.get("/example/whoami") | ||
assert resp.status_code == 200 | ||
assert resp.json()["id"] == 0 | ||
|
||
|
||
@pytest.mark.authenticated() | ||
def test_touch(client): | ||
resp = client.post("/example/touch") | ||
assert resp.status_code == 200 | ||
assert resp.json()["id"] == 0 | ||
assert resp.json()["count"] == 1 | ||
|
||
resp = client.post("/example/touch") | ||
assert resp.status_code == 200 | ||
assert resp.json()["id"] == 0 | ||
assert resp.json()["count"] == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters