Pipelinen parannuksia building blockeilla
This commit is contained in:
11
zipit/loop_runs/v4_docker/Dockerfile
Normal file
11
zipit/loop_runs/v4_docker/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM python:3.12-slim
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
||||
ENV UV_CACHE_DIR=/tmp/uv-cache
|
||||
WORKDIR /app
|
||||
COPY pyproject.toml .
|
||||
RUN uv sync
|
||||
COPY *.py .
|
||||
RUN useradd -m appuser
|
||||
USER appuser
|
||||
EXPOSE 8000
|
||||
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
58
zipit/loop_runs/v4_docker/main.py
Normal file
58
zipit/loop_runs/v4_docker/main.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from fastapi import FastAPI, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
|
||||
from models import Todo, SessionLocal
|
||||
from schemas import TodoCreate, TodoResponse
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# Dependency to get database session
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
@app.post("/todos", response_model=TodoResponse, status_code=201)
|
||||
def create_todo(todo: TodoCreate, db: Session = Depends(get_db)):
|
||||
db_todo = Todo(**todo.model_dump())
|
||||
db.add(db_todo)
|
||||
db.commit()
|
||||
db.refresh(db_todo)
|
||||
return db_todo
|
||||
|
||||
@app.get("/todos", response_model=List[TodoResponse])
|
||||
def read_todos(status: Optional[str] = None, db: Session = Depends(get_db)):
|
||||
if status:
|
||||
todos = db.query(Todo).filter(Todo.status == status).all()
|
||||
else:
|
||||
todos = db.query(Todo).all()
|
||||
return todos
|
||||
|
||||
@app.get("/todos/{todo_id}", response_model=TodoResponse)
|
||||
def read_todo(todo_id: int, db: Session = Depends(get_db)):
|
||||
todo = db.query(Todo).filter(Todo.id == todo_id).first()
|
||||
if not todo:
|
||||
raise HTTPException(status_code=404, detail="Todo not found")
|
||||
return todo
|
||||
|
||||
@app.put("/todos/{todo_id}", response_model=TodoResponse)
|
||||
def update_todo(todo_id: int, todo: TodoCreate, db: Session = Depends(get_db)):
|
||||
db_todo = db.query(Todo).filter(Todo.id == todo_id).first()
|
||||
if not db_todo:
|
||||
raise HTTPException(status_code=404, detail="Todo not found")
|
||||
for key, value in todo.model_dump().items():
|
||||
setattr(db_todo, key, value)
|
||||
db.commit()
|
||||
db.refresh(db_todo)
|
||||
return db_todo
|
||||
|
||||
@app.delete("/todos/{todo_id}", status_code=204)
|
||||
def delete_todo(todo_id: int, db: Session = Depends(get_db)):
|
||||
db_todo = db.query(Todo).filter(Todo.id == todo_id).first()
|
||||
if not db_todo:
|
||||
raise HTTPException(status_code=404, detail="Todo not found")
|
||||
db.delete(db_todo)
|
||||
db.commit()
|
||||
18
zipit/loop_runs/v4_docker/models.py
Normal file
18
zipit/loop_runs/v4_docker/models.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Text, Date, Enum
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
DATABASE_URL = "sqlite:///./todos.db"
|
||||
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
Base = declarative_base()
|
||||
|
||||
class Todo(Base):
|
||||
__tablename__ = "todos"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String(255), nullable=False)
|
||||
description = Column(Text, nullable=True)
|
||||
due_date = Column(Date, nullable=True)
|
||||
status = Column(Enum('pending', 'completed'), nullable=False)
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
13
zipit/loop_runs/v4_docker/pyproject.toml
Normal file
13
zipit/loop_runs/v4_docker/pyproject.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[project]
|
||||
name = "todo-app"
|
||||
version = "0.1.0"
|
||||
description = "A simple todo application using FastAPI and SQLAlchemy"
|
||||
authors = [
|
||||
{ name="Your Name", email="your.email@example.com" }
|
||||
]
|
||||
|
||||
dependencies = [
|
||||
"fastapi",
|
||||
"uvicorn[standard]",
|
||||
"sqlalchemy"
|
||||
]
|
||||
145
zipit/loop_runs/v4_docker/report.json
Normal file
145
zipit/loop_runs/v4_docker/report.json
Normal file
@@ -0,0 +1,145 @@
|
||||
{
|
||||
"run_id": "v4_docker",
|
||||
"steps": [
|
||||
{
|
||||
"step": "requirements",
|
||||
"agent": "client",
|
||||
"attempts": [
|
||||
{
|
||||
"attempt": 1,
|
||||
"elapsed": 6.6,
|
||||
"errors": [],
|
||||
"code_length": 1106
|
||||
}
|
||||
],
|
||||
"final_errors": [],
|
||||
"passed": true
|
||||
},
|
||||
{
|
||||
"step": "models.py",
|
||||
"agent": "data",
|
||||
"attempts": [
|
||||
{
|
||||
"attempt": 1,
|
||||
"elapsed": 5.4,
|
||||
"errors": [
|
||||
"SQLite create_engine puuttuu connect_args={'check_same_thread': False}"
|
||||
],
|
||||
"code_length": 696
|
||||
},
|
||||
{
|
||||
"attempt": 2,
|
||||
"elapsed": 4.7,
|
||||
"errors": [],
|
||||
"code_length": 740
|
||||
}
|
||||
],
|
||||
"final_errors": [],
|
||||
"passed": true
|
||||
},
|
||||
{
|
||||
"step": "schemas.py",
|
||||
"agent": "coder",
|
||||
"attempts": [
|
||||
{
|
||||
"attempt": 1,
|
||||
"elapsed": 5.1,
|
||||
"errors": [
|
||||
"SyntaxError: invalid syntax (rivi 8)"
|
||||
],
|
||||
"code_length": 472
|
||||
},
|
||||
{
|
||||
"attempt": 2,
|
||||
"elapsed": 2.9,
|
||||
"errors": [
|
||||
"SyntaxError: invalid syntax (rivi 8)"
|
||||
],
|
||||
"code_length": 372
|
||||
},
|
||||
{
|
||||
"attempt": 3,
|
||||
"elapsed": 3.5,
|
||||
"errors": [
|
||||
"SyntaxError: invalid syntax (rivi 8)"
|
||||
],
|
||||
"code_length": 472
|
||||
}
|
||||
],
|
||||
"final_errors": [
|
||||
"SyntaxError: invalid syntax (rivi 8)"
|
||||
],
|
||||
"passed": false
|
||||
},
|
||||
{
|
||||
"step": "main.py",
|
||||
"agent": "coder",
|
||||
"attempts": [
|
||||
{
|
||||
"attempt": 1,
|
||||
"elapsed": 14.6,
|
||||
"errors": [
|
||||
"Kutsutaan 'Depends()' mutta sitä ei ole importattu eikä määritelty",
|
||||
"Kutsutaan 'Depends()' mutta sitä ei ole importattu eikä määritelty",
|
||||
"Kutsutaan 'Depends()' mutta sitä ei ole importattu eikä määritelty",
|
||||
"Kutsutaan 'Depends()' mutta sitä ei ole importattu eikä määritelty",
|
||||
"Kutsutaan 'Depends()' mutta sitä ei ole importattu eikä määritelty"
|
||||
],
|
||||
"code_length": 1984
|
||||
},
|
||||
{
|
||||
"attempt": 2,
|
||||
"elapsed": 14.0,
|
||||
"errors": [],
|
||||
"code_length": 1911
|
||||
}
|
||||
],
|
||||
"final_errors": [],
|
||||
"passed": true
|
||||
},
|
||||
{
|
||||
"step": "pyproject.toml",
|
||||
"agent": "coder",
|
||||
"attempts": [
|
||||
{
|
||||
"attempt": 1,
|
||||
"elapsed": 3.6,
|
||||
"errors": [],
|
||||
"code_length": 264
|
||||
}
|
||||
],
|
||||
"final_errors": [],
|
||||
"passed": true
|
||||
},
|
||||
{
|
||||
"step": "test_main.py",
|
||||
"agent": "qa",
|
||||
"attempts": [
|
||||
{
|
||||
"attempt": 1,
|
||||
"elapsed": 15.9,
|
||||
"errors": [],
|
||||
"code_length": 1779
|
||||
}
|
||||
],
|
||||
"final_errors": [],
|
||||
"passed": true
|
||||
},
|
||||
{
|
||||
"step": "Dockerfile",
|
||||
"agent": "tester",
|
||||
"attempts": [
|
||||
{
|
||||
"attempt": 1,
|
||||
"elapsed": 4.0,
|
||||
"errors": [],
|
||||
"code_length": 291
|
||||
}
|
||||
],
|
||||
"final_errors": [],
|
||||
"passed": true
|
||||
}
|
||||
],
|
||||
"model": "qwen2.5-coder:7b-instruct-q4_K_M",
|
||||
"summary": "6/7 passed"
|
||||
}
|
||||
30
zipit/loop_runs/v4_docker/requirements
Normal file
30
zipit/loop_runs/v4_docker/requirements
Normal file
@@ -0,0 +1,30 @@
|
||||
**PROJECT NAME:** Todo-sovellus
|
||||
|
||||
**GOAL:** The software is a simple task manager for individuals to keep track of their daily tasks and manage them efficiently.
|
||||
|
||||
**CORE FEATURES:**
|
||||
1. Create new todos with title, description, due date, and status.
|
||||
2. Read (view) all todos or filter by status (e.g., pending, completed).
|
||||
3. Update existing todos (change title, description, due date, status).
|
||||
4. Delete todos that are no longer needed.
|
||||
5. Mark a todo as complete.
|
||||
6. View the total number of todos and count by status.
|
||||
|
||||
**DATA MODEL:**
|
||||
1. **Todo**
|
||||
- id (integer, primary key)
|
||||
- title (string, required)
|
||||
- description (text, optional)
|
||||
- due_date (date, optional)
|
||||
- status (enum: 'pending', 'completed')
|
||||
|
||||
**API ENDPOINTS:**
|
||||
1. **GET /todos** - Retrieve all todos.
|
||||
2. **GET /todos?status=...** - Filter todos by status (e.g., `/todos?status=pending`).
|
||||
3. **POST /todos** - Create a new todo.
|
||||
4. **PUT /todos/{id}** - Update an existing todo.
|
||||
5. **DELETE /todos/{id}** - Delete a todo.
|
||||
|
||||
**CONSTRAINTS:**
|
||||
- Must use SQLite as the database.
|
||||
- No authentication is required for accessing endpoints.
|
||||
18
zipit/loop_runs/v4_docker/schemas.py
Normal file
18
zipit/loop_runs/v4_docker/schemas.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from datetime import date
|
||||
|
||||
class TodoCreate(BaseModel):
|
||||
title: str = Field(..., max_length=255)
|
||||
description: str | None = Field(None, max_length=255)
|
||||
due_date: date | None = Field(None)
|
||||
status: str = Field(..., in=["pending", "completed"])
|
||||
|
||||
class TodoResponse(BaseModel):
|
||||
id: int
|
||||
title: str
|
||||
description: str | None
|
||||
due_date: date | None
|
||||
status: str
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
59
zipit/loop_runs/v4_docker/test_main.py
Normal file
59
zipit/loop_runs/v4_docker/test_main.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from main import app
|
||||
from models import Base
|
||||
from main import get_db
|
||||
|
||||
engine = create_engine("sqlite:///:memory:", connect_args={"check_same_thread": False})
|
||||
TestSession = sessionmaker(bind=engine)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
def override_get_db():
|
||||
db = TestSession()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
client = TestClient(app)
|
||||
|
||||
def test_create_todo():
|
||||
response = client.post("/todos", json={"title": "Test Todo", "status": "pending"})
|
||||
assert response.status_code == 201
|
||||
todo = response.json()
|
||||
assert todo["title"] == "Test Todo"
|
||||
assert todo["status"] == "pending"
|
||||
|
||||
def test_read_todos():
|
||||
response = client.get("/todos")
|
||||
assert response.status_code == 200
|
||||
todos = response.json()
|
||||
assert len(todos) == 1
|
||||
|
||||
def test_get_todo_by_id():
|
||||
response = client.get("/todos/1")
|
||||
assert response.status_code == 200
|
||||
todo = response.json()
|
||||
assert todo["id"] == 1
|
||||
assert todo["title"] == "Test Todo"
|
||||
assert todo["status"] == "pending"
|
||||
|
||||
def test_get_todo_by_id_not_found():
|
||||
response = client.get("/todos/999")
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_update_todo():
|
||||
response = client.put("/todos/1", json={"title": "Updated Todo", "status": "completed"})
|
||||
assert response.status_code == 200
|
||||
todo = response.json()
|
||||
assert todo["id"] == 1
|
||||
assert todo["title"] == "Updated Todo"
|
||||
assert todo["status"] == "completed"
|
||||
|
||||
def test_delete_todo():
|
||||
response = client.delete("/todos/1")
|
||||
assert response.status_code == 204
|
||||
response = client.get("/todos/1")
|
||||
assert response.status_code == 404
|
||||
Reference in New Issue
Block a user