Pipelinen parannuksia building blockeilla

This commit is contained in:
Jaakko Vanhala
2026-04-12 18:48:14 +03:00
parent c1a5f8aff5
commit b2ee8b9031
175 changed files with 13311 additions and 237 deletions

View File

@@ -0,0 +1,57 @@
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from main import app
from models import Base
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_task():
response = client.post("/tasks/", json={"title": "Test Task", "description": "This is a test task"})
assert response.status_code == 201
assert response.json()["title"] == "Test Task"
assert response.json()["description"] == "This is a test task"
def test_get_tasks():
response = client.get("/tasks/")
assert response.status_code == 200
assert len(response.json()) > 0
def test_get_task_by_id():
response = client.post("/tasks/", json={"title": "Test Task", "description": "This is a test task"})
task_id = response.json()["id"]
response = client.get(f"/tasks/{task_id}")
assert response.status_code == 200
assert response.json()["id"] == task_id
def test_get_task_by_id_not_found():
response = client.get("/tasks/999")
assert response.status_code == 404
def test_update_task():
response = client.post("/tasks/", json={"title": "Test Task", "description": "This is a test task"})
task_id = response.json()["id"]
updated_data = {"title": "Updated Test Task"}
response = client.put(f"/tasks/{task_id}", json=updated_data)
assert response.status_code == 200
assert response.json()["title"] == "Updated Test Task"
def test_delete_task():
response = client.post("/tasks/", json={"title": "Test Task", "description": "This is a test task"})
task_id = response.json()["id"]
response = client.delete(f"/tasks/{task_id}")
assert response.status_code == 204
response = client.get(f"/tasks/{task_id}")
assert response.status_code == 404