A Python port of the Invisible Internet Project (I2P)
at main 67 lines 1.9 kB view raw
1"""Tests for REST API routes — TDD: tests before implementation.""" 2 3import pytest 4from i2p_apps.console.app import create_app 5 6 7@pytest.fixture 8def client(): 9 app = create_app({"TESTING": True}) 10 return app.test_client() 11 12 13class TestAPIStatus: 14 def test_status_endpoint(self, client): 15 resp = client.get("/api/v1/status") 16 assert resp.status_code == 200 17 data = resp.get_json() 18 assert "state" in data 19 assert "uptime" in data 20 assert "version" in data 21 22 def test_status_has_network(self, client): 23 resp = client.get("/api/v1/status") 24 data = resp.get_json() 25 assert "network" in data 26 assert "active_peers" in data["network"] 27 28 29class TestAPIPeers: 30 def test_peers_endpoint(self, client): 31 resp = client.get("/api/v1/peers") 32 assert resp.status_code == 200 33 data = resp.get_json() 34 assert "peers" in data 35 assert isinstance(data["peers"], list) 36 37 38class TestAPITunnels: 39 def test_tunnels_endpoint(self, client): 40 resp = client.get("/api/v1/tunnels") 41 assert resp.status_code == 200 42 data = resp.get_json() 43 assert "tunnels" in data 44 assert isinstance(data["tunnels"], list) 45 46 47class TestAPIConfig: 48 def test_get_config(self, client): 49 resp = client.get("/api/v1/config") 50 assert resp.status_code == 200 51 data = resp.get_json() 52 assert isinstance(data, dict) 53 54 def test_post_config(self, client): 55 resp = client.post( 56 "/api/v1/config", 57 json={"test.key": "test_value"}, 58 ) 59 assert resp.status_code == 200 60 data = resp.get_json() 61 assert data["status"] == "ok" 62 63 64class TestAPIRouter: 65 def test_router_action_invalid(self, client): 66 resp = client.post("/api/v1/router/invalid_action") 67 assert resp.status_code == 400