115 lines
3.3 KiB
Python
115 lines
3.3 KiB
Python
import uuid
|
|
|
|
|
|
async def test_get_plants(client, auth_headers):
|
|
resp = await client.get("/api/v1/plants", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), list)
|
|
|
|
|
|
async def test_get_plants_unauthenticated(client):
|
|
resp = await client.get("/api/v1/plants")
|
|
assert resp.status_code == 401
|
|
|
|
|
|
async def test_get_plant_families(client, auth_headers):
|
|
resp = await client.get("/api/v1/plant-families", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), list)
|
|
|
|
|
|
async def test_create_plant(client, auth_headers, test_family):
|
|
resp = await client.post(
|
|
"/api/v1/plants",
|
|
headers=auth_headers,
|
|
json={
|
|
"name": "Testtomate",
|
|
"family_id": str(test_family.id),
|
|
"nutrient_demand": "stark",
|
|
"water_demand": "viel",
|
|
"spacing_cm": 50,
|
|
"sowing_start_month": 3,
|
|
"sowing_end_month": 5,
|
|
"rest_years": 3,
|
|
},
|
|
)
|
|
assert resp.status_code == 201
|
|
data = resp.json()
|
|
assert data["name"] == "Testtomate"
|
|
assert data["tenant_id"] is not None
|
|
return data["id"]
|
|
|
|
|
|
async def test_get_plant_by_id(client, auth_headers, test_family):
|
|
create = await client.post(
|
|
"/api/v1/plants",
|
|
headers=auth_headers,
|
|
json={
|
|
"name": "Testsalat",
|
|
"family_id": str(test_family.id),
|
|
"nutrient_demand": "mittel",
|
|
"water_demand": "mittel",
|
|
"spacing_cm": 30,
|
|
"sowing_start_month": 3,
|
|
"sowing_end_month": 6,
|
|
"rest_years": 0,
|
|
},
|
|
)
|
|
plant_id = create.json()["id"]
|
|
|
|
resp = await client.get(f"/api/v1/plants/{plant_id}", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["id"] == plant_id
|
|
|
|
|
|
async def test_get_plant_not_found(client, auth_headers):
|
|
resp = await client.get(f"/api/v1/plants/{uuid.uuid4()}", headers=auth_headers)
|
|
assert resp.status_code == 404
|
|
|
|
|
|
async def test_update_plant(client, auth_headers, test_family):
|
|
create = await client.post(
|
|
"/api/v1/plants",
|
|
headers=auth_headers,
|
|
json={
|
|
"name": "Altname",
|
|
"family_id": str(test_family.id),
|
|
"nutrient_demand": "schwach",
|
|
"water_demand": "wenig",
|
|
"spacing_cm": 20,
|
|
"sowing_start_month": 4,
|
|
"sowing_end_month": 6,
|
|
"rest_years": 1,
|
|
},
|
|
)
|
|
plant_id = create.json()["id"]
|
|
|
|
resp = await client.put(
|
|
f"/api/v1/plants/{plant_id}",
|
|
headers=auth_headers,
|
|
json={"name": "Neuname"},
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["name"] == "Neuname"
|
|
|
|
|
|
async def test_delete_plant(client, auth_headers, test_family):
|
|
create = await client.post(
|
|
"/api/v1/plants",
|
|
headers=auth_headers,
|
|
json={
|
|
"name": "ZuLoeschenPflanze",
|
|
"family_id": str(test_family.id),
|
|
"nutrient_demand": "mittel",
|
|
"water_demand": "mittel",
|
|
"spacing_cm": 25,
|
|
"sowing_start_month": 4,
|
|
"sowing_end_month": 7,
|
|
"rest_years": 0,
|
|
},
|
|
)
|
|
plant_id = create.json()["id"]
|
|
|
|
resp = await client.delete(f"/api/v1/plants/{plant_id}", headers=auth_headers)
|
|
assert resp.status_code == 204
|