Files
gartenmanager/backend/tests/test_beds.py
Faultier314 4305d104e5
Some checks failed
Tests / Backend Tests (push) Failing after 5m42s
Tests / Frontend Tests (push) Failing after 1m11s
feat: add CI/CD pipelines, test suite, and ci/staging branch
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 10:13:12 +02:00

96 lines
2.5 KiB
Python

import uuid
async def test_get_beds(client, auth_headers):
resp = await client.get("/api/v1/beds", headers=auth_headers)
assert resp.status_code == 200
assert isinstance(resp.json(), list)
async def test_get_beds_unauthenticated(client):
resp = await client.get("/api/v1/beds")
assert resp.status_code == 401
async def test_create_bed(client, auth_headers):
resp = await client.post(
"/api/v1/beds",
headers=auth_headers,
json={
"name": "Testbeet",
"width_m": "1.5",
"length_m": "3.0",
"location": "sonnig",
"soil_type": "normal",
},
)
assert resp.status_code == 201
data = resp.json()
assert data["name"] == "Testbeet"
assert data["tenant_id"] is not None
async def test_get_bed_by_id(client, auth_headers):
create = await client.post(
"/api/v1/beds",
headers=auth_headers,
json={
"name": "Einzelbeet",
"width_m": "2.0",
"length_m": "4.0",
"location": "halbschatten",
},
)
bed_id = create.json()["id"]
resp = await client.get(f"/api/v1/beds/{bed_id}", headers=auth_headers)
assert resp.status_code == 200
data = resp.json()
assert data["id"] == bed_id
assert "plantings" in data
async def test_get_bed_not_found(client, auth_headers):
resp = await client.get(f"/api/v1/beds/{uuid.uuid4()}", headers=auth_headers)
assert resp.status_code == 404
async def test_update_bed(client, auth_headers):
create = await client.post(
"/api/v1/beds",
headers=auth_headers,
json={
"name": "Altbeet",
"width_m": "1.0",
"length_m": "2.0",
"location": "sonnig",
},
)
bed_id = create.json()["id"]
resp = await client.put(
f"/api/v1/beds/{bed_id}",
headers=auth_headers,
json={"name": "Neubeet"},
)
assert resp.status_code == 200
assert resp.json()["name"] == "Neubeet"
async def test_delete_bed_requires_tenant_admin(client, auth_headers):
# test_user has READ_WRITE, not TENANT_ADMIN → delete should fail
create = await client.post(
"/api/v1/beds",
headers=auth_headers,
json={
"name": "ZuLoeschenBeet",
"width_m": "1.0",
"length_m": "1.0",
"location": "schatten",
},
)
bed_id = create.json()["id"]
resp = await client.delete(f"/api/v1/beds/{bed_id}", headers=auth_headers)
assert resp.status_code == 403