mirror of https://github.com/tiangolo/fastapi.git
[14350] Applying formatter
This commit is contained in:
parent
98cd5558d0
commit
88653cd0ba
|
|
@ -89,7 +89,9 @@ def create_task(task: TaskCreate, session=Depends(get_db)):
|
|||
VALUES (%s, %s, %s, %s, toTimestamp(now()), toTimestamp(now()))
|
||||
"""
|
||||
session.execute(query, (task_id, task.title, task.description, task.status))
|
||||
return Task(id=task_id, title=task.title, description=task.description, status=task.status)
|
||||
return Task(
|
||||
id=task_id, title=task.title, description=task.description, status=task.status
|
||||
)
|
||||
|
||||
|
||||
@app.get("/tasks/", response_model=List[Task])
|
||||
|
|
@ -108,7 +110,9 @@ def read_task(task_id: UUID, session=Depends(get_db)):
|
|||
row = session.execute(query, (task_id,)).one()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Task not found")
|
||||
return Task(id=row.id, title=row.title, description=row.description, status=row.status)
|
||||
return Task(
|
||||
id=row.id, title=row.title, description=row.description, status=row.status
|
||||
)
|
||||
|
||||
|
||||
@app.put("/tasks/{task_id}", response_model=Task)
|
||||
|
|
@ -124,10 +128,10 @@ def update_task(task_id: UUID, task: TaskCreate, session=Depends(get_db)):
|
|||
SET title = %s, description = %s, status = %s, updated_at = toTimestamp(now())
|
||||
WHERE id = %s
|
||||
"""
|
||||
session.execute(
|
||||
update_query, (task.title, task.description, task.status, task_id)
|
||||
session.execute(update_query, (task.title, task.description, task.status, task_id))
|
||||
return Task(
|
||||
id=task_id, title=task.title, description=task.description, status=task.status
|
||||
)
|
||||
return Task(id=task_id, title=task.title, description=task.description, status=task.status)
|
||||
|
||||
|
||||
@app.delete("/tasks/{task_id}")
|
||||
|
|
|
|||
|
|
@ -89,7 +89,9 @@ def create_task(task: TaskCreate, session=Depends(get_db)):
|
|||
VALUES (%s, %s, %s, %s, toTimestamp(now()), toTimestamp(now()))
|
||||
"""
|
||||
session.execute(query, (task_id, task.title, task.description, task.status))
|
||||
return Task(id=task_id, title=task.title, description=task.description, status=task.status)
|
||||
return Task(
|
||||
id=task_id, title=task.title, description=task.description, status=task.status
|
||||
)
|
||||
|
||||
|
||||
@app.get("/tasks/", response_model=List[Task])
|
||||
|
|
@ -108,7 +110,9 @@ def read_task(task_id: UUID, session=Depends(get_db)):
|
|||
row = session.execute(query, (task_id,)).one()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Task not found")
|
||||
return Task(id=row.id, title=row.title, description=row.description, status=row.status)
|
||||
return Task(
|
||||
id=row.id, title=row.title, description=row.description, status=row.status
|
||||
)
|
||||
|
||||
|
||||
@app.put("/tasks/{task_id}", response_model=Task)
|
||||
|
|
@ -124,10 +128,10 @@ def update_task(task_id: UUID, task: TaskCreate, session=Depends(get_db)):
|
|||
SET title = %s, description = %s, status = %s, updated_at = toTimestamp(now())
|
||||
WHERE id = %s
|
||||
"""
|
||||
session.execute(
|
||||
update_query, (task.title, task.description, task.status, task_id)
|
||||
session.execute(update_query, (task.title, task.description, task.status, task_id))
|
||||
return Task(
|
||||
id=task_id, title=task.title, description=task.description, status=task.status
|
||||
)
|
||||
return Task(id=task_id, title=task.title, description=task.description, status=task.status)
|
||||
|
||||
|
||||
@app.delete("/tasks/{task_id}")
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import sys
|
|||
from types import ModuleType
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
mock_cassandra = ModuleType('cassandra')
|
||||
mock_cassandra_cluster = ModuleType('cassandra.cluster')
|
||||
mock_cassandra = ModuleType("cassandra")
|
||||
mock_cassandra_cluster = ModuleType("cassandra.cluster")
|
||||
mock_cassandra_cluster.Cluster = MagicMock
|
||||
|
||||
# Set cluster attribute on cassandra module
|
||||
mock_cassandra.cluster = mock_cassandra_cluster
|
||||
|
||||
sys.modules['cassandra'] = mock_cassandra
|
||||
sys.modules['cassandra.cluster'] = mock_cassandra_cluster
|
||||
sys.modules["cassandra"] = mock_cassandra
|
||||
sys.modules["cassandra.cluster"] = mock_cassandra_cluster
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch
|
|||
from uuid import UUID
|
||||
|
||||
import pytest
|
||||
from dirty_equals import IsDict, IsStr, IsUUID
|
||||
from dirty_equals import IsDict, IsUUID
|
||||
from fastapi.testclient import TestClient
|
||||
from inline_snapshot import snapshot
|
||||
|
||||
|
|
@ -144,7 +144,11 @@ def test_crud_app(client: TestClient):
|
|||
|
||||
response = client.post(
|
||||
"/tasks/",
|
||||
json={"title": "Walk the dog", "description": "In the park", "status": "pending"},
|
||||
json={
|
||||
"title": "Walk the dog",
|
||||
"description": "In the park",
|
||||
"status": "pending",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
|
|
@ -204,7 +208,9 @@ def test_openapi_schema(client: TestClient):
|
|||
"required": True,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {"$ref": "#/components/schemas/TaskCreate"}
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TaskCreate"
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
@ -239,7 +245,9 @@ def test_openapi_schema(client: TestClient):
|
|||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {"$ref": "#/components/schemas/Task"},
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/Task"
|
||||
},
|
||||
"title": "Response Read Tasks Tasks Get",
|
||||
}
|
||||
}
|
||||
|
|
@ -257,7 +265,11 @@ def test_openapi_schema(client: TestClient):
|
|||
"name": "task_id",
|
||||
"in": "path",
|
||||
"required": True,
|
||||
"schema": {"type": "string", "format": "uuid", "title": "Task Id"},
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"title": "Task Id",
|
||||
},
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
|
@ -289,14 +301,20 @@ def test_openapi_schema(client: TestClient):
|
|||
"name": "task_id",
|
||||
"in": "path",
|
||||
"required": True,
|
||||
"schema": {"type": "string", "format": "uuid", "title": "Task Id"},
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"title": "Task Id",
|
||||
},
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"required": True,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {"$ref": "#/components/schemas/TaskCreate"}
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TaskCreate"
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
@ -329,7 +347,11 @@ def test_openapi_schema(client: TestClient):
|
|||
"name": "task_id",
|
||||
"in": "path",
|
||||
"required": True,
|
||||
"schema": {"type": "string", "format": "uuid", "title": "Task Id"},
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"title": "Task Id",
|
||||
},
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
|
@ -356,7 +378,9 @@ def test_openapi_schema(client: TestClient):
|
|||
"HTTPValidationError": {
|
||||
"properties": {
|
||||
"detail": {
|
||||
"items": {"$ref": "#/components/schemas/ValidationError"},
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/ValidationError"
|
||||
},
|
||||
"type": "array",
|
||||
"title": "Detail",
|
||||
}
|
||||
|
|
@ -377,7 +401,11 @@ def test_openapi_schema(client: TestClient):
|
|||
# TODO: remove when deprecating Pydantic v1
|
||||
{"type": "string", "title": "Description"}
|
||||
),
|
||||
"status": {"type": "string", "default": "pending", "title": "Status"},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"default": "pending",
|
||||
"title": "Status",
|
||||
},
|
||||
"id": {"type": "string", "format": "uuid", "title": "Id"},
|
||||
},
|
||||
"type": "object",
|
||||
|
|
@ -397,7 +425,11 @@ def test_openapi_schema(client: TestClient):
|
|||
# TODO: remove when deprecating Pydantic v1
|
||||
{"type": "string", "title": "Description"}
|
||||
),
|
||||
"status": {"type": "string", "default": "pending", "title": "Status"},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"default": "pending",
|
||||
"title": "Status",
|
||||
},
|
||||
},
|
||||
"type": "object",
|
||||
"required": ["title"],
|
||||
|
|
@ -406,7 +438,9 @@ def test_openapi_schema(client: TestClient):
|
|||
"ValidationError": {
|
||||
"properties": {
|
||||
"loc": {
|
||||
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
|
||||
"items": {
|
||||
"anyOf": [{"type": "string"}, {"type": "integer"}]
|
||||
},
|
||||
"type": "array",
|
||||
"title": "Location",
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue