Skip to content

Commit 0b107e2

Browse files
run ruff lint fixes
1 parent eb4ac0a commit 0b107e2

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
from typing import Any
2+
3+
from fastapi import APIRouter, BackgroundTasks, File, HTTPException, UploadFile
4+
25
from app.api.deps import CurrentUser, SessionDep
36
from app.models import Document, DocumentCreate, DocumentPublic
4-
from fastapi import APIRouter, BackgroundTasks, File, UploadFile, HTTPException
5-
from app.s3 import upload_file_to_s3, generate_s3_url
7+
from app.s3 import generate_s3_url, upload_file_to_s3
68

79
router = APIRouter(prefix="/documents", tags=["documents"])
8-
10+
911
@router.post("/", response_model=DocumentPublic)
1012
def create_document(
1113
*, session: SessionDep, current_user: CurrentUser,
12-
background_tasks: BackgroundTasks,
13-
file: UploadFile = File(...),
14+
background_tasks: BackgroundTasks, # noqa: ARG001
15+
file: UploadFile = File(...),
1416
) -> Any:
1517
key = None
1618
try:
17-
user_id = current_user.id
1819
key = upload_file_to_s3(file, str(current_user.id))
1920
except Exception as e:
2021
raise HTTPException(500, f"Failed to upload file. Error: {str(e)}")
2122

2223
try:
2324
url = generate_s3_url(key)
24-
except Exception as e:
25+
except Exception:
2526
raise HTTPException(500, f"Could not generate URL for file key: {key}")
2627

2728
document_in = DocumentCreate(
2829
filename=file.filename,
2930
content_type=file.content_type,
30-
size=file.size,
31+
size=file.size,
3132
s3_url=url,
3233
)
3334

@@ -42,4 +43,4 @@ def create_document(
4243
print("Document created, starting background task...")
4344
# background_tasks.add_task(generate_questions, document.id)
4445

45-
return document
46+
return document

backend/app/core/db.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def init_db(session: Session) -> None:
1616
# Tables should be created with Alembic migrations
1717
# But if you don't want to use migrations, create
1818
# the tables un-commenting the next lines
19-
from sqlmodel import SQLModel
2019

2120
# This works because the models are already imported and registered from app.models
2221
SQLModel.metadata.create_all(engine)

backend/app/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ class TokenPayload(SQLModel):
118118

119119
class NewPassword(SQLModel):
120120
token: str
121-
new_password: str = Field(min_length=8, max_length=40)
121+
new_password: str = Field(min_length=8, max_length=40)

backend/app/s3.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import boto3
21
import uuid
2+
3+
import boto3
34
from fastapi import UploadFile
5+
46
from app.core.config import settings
57

68
s3 = boto3.client(
@@ -25,4 +27,4 @@ def upload_file_to_s3(file: UploadFile, user_id: str) -> str:
2527

2628

2729
def generate_s3_url(key: str) -> str:
28-
return f"https://{settings.S3_BUCKET_NAME}.s3.amazonaws.com/{key}"
30+
return f"https://{settings.S3_BUCKET_NAME}.s3.amazonaws.com/{key}"

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import uuid
21

3-
from fastapi.testclient import TestClient
4-
from sqlmodel import Session
2+
import io
53
from unittest.mock import patch
4+
5+
from fastapi.testclient import TestClient
6+
67
from app.core.config import settings
7-
from app.tests.utils.document import create_random_document
8-
import io
98

109

1110
def skip_test_create_document(
@@ -45,7 +44,7 @@ def test_create_document(
4544
},
4645
)
4746

48-
assert response.status_code == 200, f"Unexpected response status code"
47+
assert response.status_code == 200, "Unexpected response status code"
4948
content = response.json()
5049
assert "id" in content, "actual response: " + str(content)
5150
assert "document-slug" in content["s3_url"], "S3 URL should match mocked value"

0 commit comments

Comments
 (0)