Skip to content

Commit 28e3662

Browse files
ruff format app
1 parent 0b107e2 commit 28e3662

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

backend/app/api/routes/documents.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88

99
router = APIRouter(prefix="/documents", tags=["documents"])
1010

11+
1112
@router.post("/", response_model=DocumentPublic)
1213
def create_document(
13-
*, session: SessionDep, current_user: CurrentUser,
14-
background_tasks: BackgroundTasks, # noqa: ARG001
15-
file: UploadFile = File(...),
14+
*,
15+
session: SessionDep,
16+
current_user: CurrentUser,
17+
background_tasks: BackgroundTasks, # noqa: ARG001
18+
file: UploadFile = File(...),
1619
) -> Any:
1720
key = None
1821
try:
@@ -32,8 +35,9 @@ def create_document(
3235
s3_url=url,
3336
)
3437

35-
document = Document.model_validate(document_in, update={"owner_id": current_user.id})
36-
38+
document = Document.model_validate(
39+
document_in, update={"owner_id": current_user.id}
40+
)
3741

3842
session.add(document)
3943
session.commit()

backend/app/crud.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def authenticate(*, session: Session, email: str, password: str) -> User | None:
4646
return db_user
4747

4848

49-
def create_document(*, session: Session, document_in: DocumentCreate, owner_id: uuid.UUID) -> Document:
49+
def create_document(
50+
*, session: Session, document_in: DocumentCreate, owner_id: uuid.UUID
51+
) -> Document:
5052
db_document = Document.model_validate(document_in, update={"owner_id": owner_id})
5153
session.add(db_document)
5254
session.commit()

backend/app/models.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class UpdatePassword(SQLModel):
4343
class User(UserBase, table=True):
4444
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
4545
hashed_password: str
46-
documents: list["Document"] = Relationship(back_populates="owner", cascade_delete=True)
46+
documents: list["Document"] = Relationship(
47+
back_populates="owner", cascade_delete=True
48+
)
4749

4850

4951
# Properties to return via API, id is always required
@@ -59,16 +61,18 @@ class UsersPublic(SQLModel):
5961
# Shared properties
6062
class DocumentBase(SQLModel):
6163
filename: str = Field(min_length=1, max_length=255)
62-
s3_url: str | None = Field(default=None, max_length=255) # URL to the document in S3
64+
s3_url: str | None = Field(
65+
default=None, max_length=255
66+
) # URL to the document in S3
6367
content_type: str | None = Field(default=None, max_length=255)
64-
size: int | None = Field(default=None, ge=0) # Size in bytes
65-
68+
size: int | None = Field(default=None, ge=0) # Size in bytes
6669

6770

6871
# Properties to receive on document creation
6972
class DocumentCreate(DocumentBase):
7073
pass
7174

75+
7276
# Properties to receive on document update
7377
class DocumentUpdate(DocumentBase):
7478
filename: str | None = Field(default=None, min_length=1, max_length=255) # type: ignore
@@ -88,13 +92,15 @@ class Document(DocumentBase, table=True):
8892
# id: uuid.UUID
8993
# owner_id: uuid.UUID
9094

95+
9196
class DocumentPublic(DocumentBase):
9297
id: uuid.UUID
9398
owner_id: uuid.UUID
9499
filename: str
95100
content_type: str | None = None
96101
size: int | None = None
97102

103+
98104
class DocumentsPublic(SQLModel):
99105
data: list[DocumentPublic]
100106
count: int

backend/app/s3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
region_name=settings.AWS_REGION,
1313
)
1414

15+
1516
def upload_file_to_s3(file: UploadFile, user_id: str) -> str:
1617
safe_filename = file.filename or ""
1718
extension = safe_filename.split(".")[-1] if "." in safe_filename else ""

backend/app/tests/api/routes/test_documents.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import io
32
from unittest.mock import patch
43

@@ -10,15 +9,13 @@
109
def skip_test_create_document(
1110
client: TestClient, superuser_token_headers: dict[str, str]
1211
) -> None:
13-
'''Test creating a document with a file upload with the real S3 service.'''
12+
"""Test creating a document with a file upload with the real S3 service."""
1413
file_content = b"%PDF-1.4 test file content"
1514

1615
response = client.post(
1716
f"{settings.API_V1_STR}/documents/",
1817
headers=superuser_token_headers,
19-
files={
20-
"file": ("example.pdf", io.BytesIO(file_content), "application/pdf")
21-
},
18+
files={"file": ("example.pdf", io.BytesIO(file_content), "application/pdf")},
2219
)
2320

2421
assert response.status_code == 200
@@ -29,13 +26,16 @@ def skip_test_create_document(
2926
# assert "id" in content
3027
# assert "owner_id" in content
3128

29+
3230
def test_create_document(
3331
client: TestClient, superuser_token_headers: dict[str, str]
3432
) -> None:
35-
'''Test creating a document with a file upload using mocked S3.'''
33+
"""Test creating a document with a file upload using mocked S3."""
3634
file_content = b"%PDF-1.4 test file content"
3735

38-
with patch("app.api.routes.documents.upload_file_to_s3", return_value="document-slug"):
36+
with patch(
37+
"app.api.routes.documents.upload_file_to_s3", return_value="document-slug"
38+
):
3939
response = client.post(
4040
f"{settings.API_V1_STR}/documents/",
4141
headers=superuser_token_headers,

0 commit comments

Comments
 (0)