Skip to content

Commit 7ca5d92

Browse files
authored
lint + format on backend (#19)
1 parent 31b16ba commit 7ca5d92

File tree

10 files changed

+27
-76
lines changed

10 files changed

+27
-76
lines changed

Diff for: {{cookiecutter.project_slug}}/backend/app/app/api/api_v1/endpoints/users.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,9 @@ async def update_user(
5050
Update user.
5151
"""
5252
if current_user.hashed_password:
53-
user = await crud.user.authenticate(
54-
db, email=current_user.email, password=obj_in.original
55-
)
53+
user = await crud.user.authenticate(db, email=current_user.email, password=obj_in.original)
5654
if not obj_in.original or not user:
57-
raise HTTPException(
58-
status_code=400, detail="Unable to authenticate this update."
59-
)
55+
raise HTTPException(status_code=400, detail="Unable to authenticate this update.")
6056
current_user_data = jsonable_encoder(current_user)
6157
user_in = schemas.UserUpdate(**current_user_data)
6258
if obj_in.password is not None:
@@ -150,9 +146,7 @@ async def create_user(
150146
)
151147
user = await crud.user.create(db, obj_in=user_in)
152148
if settings.EMAILS_ENABLED and user_in.email:
153-
send_new_account_email(
154-
email_to=user_in.email, username=user_in.email, password=user_in.password
155-
)
149+
send_new_account_email(email_to=user_in.email, username=user_in.email, password=user_in.password)
156150
return user
157151

158152

Diff for: {{cookiecutter.project_slug}}/backend/app/app/api/deps.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ async def get_current_user(
4949
return user
5050

5151

52-
async def get_totp_user(
53-
db: AgnosticDatabase = Depends(get_db), token: str = Depends(reusable_oauth2)
54-
) -> models.User:
52+
async def get_totp_user(db: AgnosticDatabase = Depends(get_db), token: str = Depends(reusable_oauth2)) -> models.User:
5553
token_data = get_token_payload(token)
5654
if token_data.refresh or not token_data.totp:
5755
# Refresh token is not a valid access token and TOTP False cannot be used to validate TOTP
@@ -115,9 +113,7 @@ async def get_current_active_superuser(
115113
current_user: models.User = Depends(get_current_user),
116114
) -> models.User:
117115
if not crud.user.is_superuser(current_user):
118-
raise HTTPException(
119-
status_code=400, detail="The user doesn't have enough privileges"
120-
)
116+
raise HTTPException(status_code=400, detail="The user doesn't have enough privileges")
121117
return current_user
122118

123119

Diff for: {{cookiecutter.project_slug}}/backend/app/app/core/config.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ def get_project_name(cls, v: Optional[str], info: ValidationInfo) -> str:
6969

7070
@field_validator("EMAILS_ENABLED", mode="before")
7171
def get_emails_enabled(cls, v: bool, info: ValidationInfo) -> bool:
72-
return bool(
73-
info.data.get("SMTP_HOST")
74-
and info.data.get("SMTP_PORT")
75-
and info.data.get("EMAILS_FROM_EMAIL")
76-
)
72+
return bool(info.data.get("SMTP_HOST") and info.data.get("SMTP_PORT") and info.data.get("EMAILS_FROM_EMAIL"))
7773

7874
EMAIL_TEST_USER: EmailStr = "[email protected]" # type: ignore
7975
FIRST_SUPERUSER: EmailStr

Diff for: {{cookiecutter.project_slug}}/backend/app/app/db/session.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@ def __new__(cls):
1717
cls.instance.mongo_client = motor_asyncio.AsyncIOMotorClient(
1818
settings.MONGO_DATABASE_URI, driver=DRIVER_INFO
1919
)
20-
cls.instance.engine = AIOEngine(
21-
client=cls.instance.mongo_client,
22-
database=settings.MONGO_DATABASE
23-
)
20+
cls.instance.engine = AIOEngine(client=cls.instance.mongo_client, database=settings.MONGO_DATABASE)
2421
return cls.instance
2522

2623

2724
def MongoDatabase() -> core.AgnosticDatabase:
2825
return _MongoClientSingleton().mongo_client[settings.MONGO_DATABASE]
2926

27+
3028
def get_engine() -> AIOEngine:
3129
return _MongoClientSingleton().engine
3230

31+
3332
async def ping():
3433
await MongoDatabase().command("ping")
3534

Diff for: {{cookiecutter.project_slug}}/backend/app/app/models/token.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
# Consider reworking to consolidate information to a userId. This may not work well
1111
class Token(Base):
1212
token: str
13-
authenticates_id: User = Reference()
13+
authenticates_id: User = Reference()

Diff for: {{cookiecutter.project_slug}}/backend/app/app/schemas/base_schema.py

+7-21
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
class BaseSchema(BaseModel):
1212
@property
1313
def as_db_dict(self):
14-
to_db = self.model_dump(
15-
exclude_defaults=True, exclude_none=True, exclude={"identifier, id"}
16-
)
14+
to_db = self.model_dump(exclude_defaults=True, exclude_none=True, exclude={"identifier, id"})
1715
for key in ["id", "identifier"]:
1816
if key in self.model_dump().keys():
1917
to_db[key] = self.model_dump()[key].hex
@@ -23,16 +21,12 @@ def as_db_dict(self):
2321
class MetadataBaseSchema(BaseSchema):
2422
# Receive via API
2523
# https://www.dublincore.org/specifications/dublin-core/dcmi-terms/#section-3
26-
title: Optional[str] = Field(
27-
None, description="A human-readable title given to the resource."
28-
)
24+
title: Optional[str] = Field(None, description="A human-readable title given to the resource.")
2925
description: Optional[str] = Field(
3026
None,
3127
description="A short description of the resource.",
3228
)
33-
isActive: Optional[bool] = Field(
34-
default=True, description="Whether the resource is still actively maintained."
35-
)
29+
isActive: Optional[bool] = Field(default=True, description="Whether the resource is still actively maintained.")
3630
isPrivate: Optional[bool] = Field(
3731
default=True,
3832
description="Whether the resource is private to team members with appropriate authorisation.",
@@ -44,22 +38,14 @@ class MetadataBaseCreate(MetadataBaseSchema):
4438

4539

4640
class MetadataBaseUpdate(MetadataBaseSchema):
47-
identifier: UUID = Field(
48-
..., description="Automatically generated unique identity for the resource."
49-
)
41+
identifier: UUID = Field(..., description="Automatically generated unique identity for the resource.")
5042

5143

5244
class MetadataBaseInDBBase(MetadataBaseSchema):
5345
# Identifier managed programmatically
54-
identifier: UUID = Field(
55-
..., description="Automatically generated unique identity for the resource."
56-
)
57-
created: date = Field(
58-
..., description="Automatically generated date resource was created."
59-
)
60-
isActive: bool = Field(
61-
..., description="Whether the resource is still actively maintained."
62-
)
46+
identifier: UUID = Field(..., description="Automatically generated unique identity for the resource.")
47+
created: date = Field(..., description="Automatically generated date resource was created.")
48+
isActive: bool = Field(..., description="Whether the resource is still actively maintained.")
6349
isPrivate: bool = Field(
6450
...,
6551
description="Whether the resource is private to team members with appropriate authorisation.",

Diff for: {{cookiecutter.project_slug}}/backend/app/app/tests/api/api_v1/test_users.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212

1313
@pytest.mark.asyncio
14-
async def test_get_users_superuser_me(
15-
client: TestClient, superuser_token_headers: Dict[str, str]
16-
) -> None:
14+
async def test_get_users_superuser_me(client: TestClient, superuser_token_headers: Dict[str, str]) -> None:
1715
r = client.get(f"{settings.API_V1_STR}/users/", headers=superuser_token_headers)
1816
current_user = r.json()
1917
assert current_user
@@ -23,9 +21,7 @@ async def test_get_users_superuser_me(
2321

2422

2523
@pytest.mark.asyncio
26-
async def test_get_users_normal_user_me(
27-
client: TestClient, normal_user_token_headers: Dict[str, str]
28-
) -> None:
24+
async def test_get_users_normal_user_me(client: TestClient, normal_user_token_headers: Dict[str, str]) -> None:
2925
r = client.get(f"{settings.API_V1_STR}/users/", headers=normal_user_token_headers)
3026
current_user = r.json()
3127
assert current_user
@@ -35,9 +31,7 @@ async def test_get_users_normal_user_me(
3531

3632

3733
@pytest.mark.asyncio
38-
async def test_create_user_new_email(
39-
client: TestClient, superuser_token_headers: dict, db: AgnosticDatabase
40-
) -> None:
34+
async def test_create_user_new_email(client: TestClient, superuser_token_headers: dict, db: AgnosticDatabase) -> None:
4135
username = random_email()
4236
password = random_lower_string()
4337
data = {"email": username, "password": password}
@@ -74,9 +68,7 @@ async def test_create_user_existing_username(
7468

7569

7670
@pytest.mark.asyncio
77-
async def test_retrieve_users(
78-
client: TestClient, superuser_token_headers: dict, db: AgnosticDatabase
79-
) -> None:
71+
async def test_retrieve_users(client: TestClient, superuser_token_headers: dict, db: AgnosticDatabase) -> None:
8072
username = random_email()
8173
password = random_lower_string()
8274
user_in = UserCreate(email=username, password=password)

Diff for: {{cookiecutter.project_slug}}/backend/app/app/tests/conftest.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,5 @@ def superuser_token_headers(client: TestClient) -> Dict[str, str]:
4747

4848

4949
@pytest_asyncio.fixture(scope="module")
50-
async def normal_user_token_headers(
51-
client: TestClient, db: AgnosticDatabase
52-
) -> Dict[str, str]:
53-
return await authentication_token_from_email(
54-
client=client, email=settings.EMAIL_TEST_USER, db=db
55-
)
50+
async def normal_user_token_headers(client: TestClient, db: AgnosticDatabase) -> Dict[str, str]:
51+
return await authentication_token_from_email(client=client, email=settings.EMAIL_TEST_USER, db=db)

Diff for: {{cookiecutter.project_slug}}/backend/app/app/tests/crud/test_user.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ async def test_authenticate_user(db: AgnosticDatabase) -> None:
2424
password = random_lower_string()
2525
user_in = UserCreate(email=email, password=password)
2626
user = await crud.user.create(db, obj_in=user_in)
27-
authenticated_user = await crud.user.authenticate(
28-
db, email=email, password=password
29-
)
27+
authenticated_user = await crud.user.authenticate(db, email=email, password=password)
3028
assert authenticated_user
3129
assert user.email == authenticated_user.email
3230

@@ -103,6 +101,4 @@ async def test_update_user(db: AgnosticDatabase) -> None:
103101
user_2 = await crud.user.get(db, id=user.id)
104102
assert user_2
105103
assert user.email == user_2.email
106-
assert verify_password(
107-
plain_password=new_password, hashed_password=user_2.hashed_password
108-
)
104+
assert verify_password(plain_password=new_password, hashed_password=user_2.hashed_password)

Diff for: {{cookiecutter.project_slug}}/backend/app/app/tests/utils/user.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
from app.tests.utils.utils import random_email, random_lower_string
1111

1212

13-
def user_authentication_headers(
14-
*, client: TestClient, email: str, password: str
15-
) -> Dict[str, str]:
13+
def user_authentication_headers(*, client: TestClient, email: str, password: str) -> Dict[str, str]:
1614
data = {"username": email, "password": password}
1715

1816
r = client.post(f"{settings.API_V1_STR}/login/oauth", data=data)
@@ -22,9 +20,7 @@ def user_authentication_headers(
2220
return headers
2321

2422

25-
async def authentication_token_from_email(
26-
*, client: TestClient, email: str, db: AgnosticDatabase
27-
) -> Dict[str, str]:
23+
async def authentication_token_from_email(*, client: TestClient, email: str, db: AgnosticDatabase) -> Dict[str, str]:
2824
"""
2925
Return a valid token for the user with given email.
3026

0 commit comments

Comments
 (0)