mirror of
https://github.com/ipnet-mesh/meshcore-hub.git
synced 2026-03-28 17:42:56 +01:00
- Create conftest.py with MockHttpClient for testing web routes - Add test_home.py with 9 tests for home page - Add test_members.py with 11 tests for members page and load_members function - Add test_network.py with 7 tests for network overview page - Add test_nodes.py with 15 tests for nodes list and detail pages - Add test_map.py with 12 tests for map page and data endpoint - Add test_messages.py with 13 tests for messages page with filtering - All 67 web tests pass, 184 total tests pass - Update TASKS.md to mark Phase 5 as 100% complete (186/221 total)
86 lines
3.1 KiB
Python
86 lines
3.1 KiB
Python
"""Tests for the network overview page route."""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from tests.test_web.conftest import MockHttpClient
|
|
|
|
|
|
class TestNetworkPage:
|
|
"""Tests for the network overview page."""
|
|
|
|
def test_network_returns_200(self, client: TestClient) -> None:
|
|
"""Test that network page returns 200 status code."""
|
|
response = client.get("/network")
|
|
assert response.status_code == 200
|
|
|
|
def test_network_returns_html(self, client: TestClient) -> None:
|
|
"""Test that network page returns HTML content."""
|
|
response = client.get("/network")
|
|
assert "text/html" in response.headers["content-type"]
|
|
|
|
def test_network_contains_network_name(self, client: TestClient) -> None:
|
|
"""Test that network page contains the network name."""
|
|
response = client.get("/network")
|
|
assert "Test Network" in response.text
|
|
|
|
def test_network_displays_stats(
|
|
self, client: TestClient, mock_http_client: MockHttpClient
|
|
) -> None:
|
|
"""Test that network page displays statistics."""
|
|
response = client.get("/network")
|
|
# Check for stats from mock response
|
|
assert response.status_code == 200
|
|
# The mock returns total_nodes: 10, active_nodes: 5, etc.
|
|
# These should be displayed in the page
|
|
assert "10" in response.text # total_nodes
|
|
assert "5" in response.text # active_nodes
|
|
|
|
def test_network_displays_message_counts(
|
|
self, client: TestClient, mock_http_client: MockHttpClient
|
|
) -> None:
|
|
"""Test that network page displays message counts."""
|
|
response = client.get("/network")
|
|
assert response.status_code == 200
|
|
# Mock returns total_messages: 100, messages_today: 15
|
|
assert "100" in response.text
|
|
assert "15" in response.text
|
|
|
|
|
|
class TestNetworkPageAPIErrors:
|
|
"""Tests for network page handling API errors."""
|
|
|
|
def test_network_handles_api_error(
|
|
self, web_app: any, mock_http_client: MockHttpClient
|
|
) -> None:
|
|
"""Test that network page handles API errors gracefully."""
|
|
# Set error response for stats endpoint
|
|
mock_http_client.set_response(
|
|
"GET", "/api/v1/dashboard/stats", status_code=500, json_data=None
|
|
)
|
|
web_app.state.http_client = mock_http_client
|
|
|
|
client = TestClient(web_app, raise_server_exceptions=True)
|
|
response = client.get("/network")
|
|
|
|
# Should still return 200 (page renders with defaults)
|
|
assert response.status_code == 200
|
|
|
|
def test_network_handles_api_not_found(
|
|
self, web_app: any, mock_http_client: MockHttpClient
|
|
) -> None:
|
|
"""Test that network page handles API 404 gracefully."""
|
|
mock_http_client.set_response(
|
|
"GET",
|
|
"/api/v1/dashboard/stats",
|
|
status_code=404,
|
|
json_data={"detail": "Not found"},
|
|
)
|
|
web_app.state.http_client = mock_http_client
|
|
|
|
client = TestClient(web_app, raise_server_exceptions=True)
|
|
response = client.get("/network")
|
|
|
|
# Should still return 200 (page renders with defaults)
|
|
assert response.status_code == 200
|