test_api.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import pytest
  2. from fastapi.testclient import TestClient
  3. from api.routes import app
  4. @pytest.fixture
  5. def client():
  6. return TestClient(app)
  7. class TestAPIEndpoints:
  8. def test_get_status(self, client):
  9. response = client.get("/status")
  10. assert response.status_code == 200
  11. assert "status" in response.json()
  12. def test_get_robot_position(self, client):
  13. response = client.get("/robot/position")
  14. assert response.status_code == 200
  15. data = response.json()
  16. assert "x" in data
  17. assert "y" in data
  18. assert "z" in data
  19. def test_get_slots_status(self, client):
  20. response = client.get("/slots")
  21. assert response.status_code == 200
  22. slots = response.json()
  23. assert isinstance(slots, list)
  24. if len(slots) > 0:
  25. assert "id" in slots[0]
  26. assert "occupied" in slots[0]
  27. def test_emergency_stop(self, client):
  28. response = client.post("/robot/stop")
  29. assert response.status_code == 200
  30. assert response.json()["status"] == "stopped"