from __future__ import annotations import pytest from httpx import AsyncClient @pytest.mark.asyncio async def test_device_crud_flow(client: AsyncClient, auth_headers: dict) -> None: """Test full device CRUD lifecycle.""" # Create response = await client.post( "/api/v1/devices", json={"device_uid": "test-device-001", "name": "Test Sensor", "device_type": "temperature"}, headers=auth_headers, ) assert response.status_code == 201 device = response.json() device_id = device["id"] assert device["device_uid"] == "test-device-001" # Read response = await client.get(f"/api/v1/devices/{device_id}", headers=auth_headers) assert response.status_code == 200 assert response.json()["name"] == "Test Sensor" # Update response = await client.patch( f"/api/v1/devices/{device_id}", json={"name": "Updated Sensor"}, headers=auth_headers, ) assert response.status_code == 200 assert response.json()["name"] == "Updated Sensor" # List response = await client.get("/api/v1/devices", headers=auth_headers) assert response.status_code == 200 assert response.json()["total"] >= 1 # Delete response = await client.delete(f"/api/v1/devices/{device_id}", headers=auth_headers) assert response.status_code == 204