Files
backup-tool/backend/tests/test_sources.py
T
alex 0d0f41d616 feat: add sources CRUD API with tests
- Full CRUD endpoints for backup sources
- Pydantic validation for source types
- pytest tests for create, list, get, delete
2026-05-11 20:59:11 +02:00

65 lines
2.1 KiB
Python

import pytest
from httpx import AsyncClient
from app.main import app
@pytest.mark.asyncio
async def test_create_source():
async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.post("/api/sources/", json={
"name": "Test Source",
"type": "local",
"config": {"path": "/tmp/test"}
})
assert response.status_code == 200
data = response.json()
assert data["name"] == "Test Source"
assert data["type"] == "local"
assert "id" in data
@pytest.mark.asyncio
async def test_list_sources():
async with AsyncClient(app=app, base_url="http://test") as ac:
# Create source first
await ac.post("/api/sources/", json={
"name": "Test Source",
"type": "local",
"config": {"path": "/tmp/test"}
})
response = await ac.get("/api/sources/")
assert response.status_code == 200
data = response.json()
assert len(data) >= 1
@pytest.mark.asyncio
async def test_get_source():
async with AsyncClient(app=app, base_url="http://test") as ac:
create_resp = await ac.post("/api/sources/", json={
"name": "Test Source",
"type": "local",
"config": {"path": "/tmp/test"}
})
source_id = create_resp.json()["id"]
response = await ac.get(f"/api/sources/{source_id}")
assert response.status_code == 200
assert response.json()["id"] == source_id
@pytest.mark.asyncio
async def test_delete_source():
async with AsyncClient(app=app, base_url="http://test") as ac:
create_resp = await ac.post("/api/sources/", json={
"name": "Delete Me",
"type": "local",
"config": {"path": "/tmp/test"}
})
source_id = create_resp.json()["id"]
response = await ac.delete(f"/api/sources/{source_id}")
assert response.status_code == 200
# Verify deletion
async with AsyncClient(app=app, base_url="http://test") as ac:
get_resp = await ac.get(f"/api/sources/{source_id}")
assert get_resp.status_code == 404