Skip to content

Commit

Permalink
remove typing imports and uvicorn dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasrenault committed Oct 10, 2024
1 parent c7a91de commit f04ff2c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 19 deletions.
4 changes: 1 addition & 3 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ to run the unit tests for the backend app.

The project uses Pydantic's settings management through FastAPI. Documentation on how the settings work is availabe [here](https://fastapi.tiangolo.com/advanced/settings/).

The configuration file is located in [config/config.py](app/config/config.py). This file defines the setting properties, there types, and default values. The `Config` class specifies where these properties are from, i.e. the [.env.dev](.env.dev) file. Modify the values in the [.env.dev](.env.dev) file to change the configuration.

Note that when the backend application is run with Docker, the values in the [.env.dev](.env.dev) are overriden with environment variables set in the Docker configuration.
The configuration file is located in [config/config.py](app/config/config.py). This file defines the setting properties, their types, and default values. The `model_config` attribute specifies where these properties are from, i.e. the [.env](../.env) file at the root of the project. Modify the values in the [.env](../.env) file to change the configuration.
4 changes: 2 additions & 2 deletions backend/app/config/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import secrets
from typing import List, Literal
from typing import Literal

from pydantic import AnyHttpUrl, EmailStr
from pydantic_settings import BaseSettings, SettingsConfigDict
Expand All @@ -19,7 +19,7 @@ class Settings(BaseSettings):
# 60 minutes * 24 hours * 8 days = 8 days
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
# JSON-formatted list of origins
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
BACKEND_CORS_ORIGINS: list[AnyHttpUrl] = []
PROJECT_NAME: str
FIRST_SUPERUSER: EmailStr
FIRST_SUPERUSER_PASSWORD: str
Expand Down
8 changes: 4 additions & 4 deletions backend/app/routers/users.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any
from uuid import UUID

from beanie.exceptions import RevisionIdWasChanged
Expand Down Expand Up @@ -42,10 +42,10 @@ async def register_user(
)


@router.get("", response_model=List[schemas.User])
@router.get("", response_model=list[schemas.User])
async def get_users(
limit: Optional[int] = 10,
offset: Optional[int] = 0,
limit: int | None = 10,
offset: int | None = 0,
admin_user: models.User = Depends(get_current_active_superuser),
):
users = await models.User.find_all().skip(offset).limit(limit).to_list()
Expand Down
1 change: 0 additions & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ python = "^3.12"
requests = "^2.32.3"
pymongo = "^4.9.2"
fastapi = {extras = ["standard"], version = "^0.115.0"}
uvicorn = "^0.31.0"
python-multipart = "^0.0.12"
motor = "^3.6.0"
pydantic = "^2.9.2"
Expand Down
4 changes: 1 addition & 3 deletions backend/tests/routers/test_login.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Dict

import pytest
from httpx import AsyncClient

Expand All @@ -21,7 +19,7 @@ async def test_get_access_token(client: AsyncClient) -> None:

@pytest.mark.anyio
async def test_use_access_token(
client: AsyncClient, superuser_token_headers: Dict[str, str]
client: AsyncClient, superuser_token_headers: dict[str, str]
) -> None:
r = await client.get(
f"{settings.API_V1_STR}/login/test-token",
Expand Down
4 changes: 1 addition & 3 deletions backend/tests/routers/test_users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Dict

import pytest
from httpx import AsyncClient

Expand All @@ -16,7 +14,7 @@

@pytest.mark.anyio
async def test_get_profile_superuser(
client: AsyncClient, superuser_token_headers: Dict[str, str]
client: AsyncClient, superuser_token_headers: dict[str, str]
) -> None:
r = await client.get(
f"{settings.API_V1_STR}/users/me", headers=superuser_token_headers
Expand Down
5 changes: 2 additions & 3 deletions backend/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import random
import string
from typing import Dict

from httpx import AsyncClient

Expand All @@ -11,7 +10,7 @@

async def get_user_auth_headers(
client: AsyncClient, email: str, password: str
) -> Dict[str, str]:
) -> dict[str, str]:
"""
Given a user's email and password, send a request to login the user and return the
authorization headers.
Expand All @@ -24,7 +23,7 @@ async def get_user_auth_headers(
return headers


async def generate_user_auth_headers(client: AsyncClient, user: User) -> Dict[str, str]:
async def generate_user_auth_headers(client: AsyncClient, user: User) -> dict[str, str]:
"""
Given a user in DB, generate a token and return the authorization headers.
"""
Expand Down

0 comments on commit f04ff2c

Please sign in to comment.