Fix linting and type errors in web tests

- Remove unused imports (AsyncMock, patch, pytest)
- Fix type annotations: use Any instead of any
This commit is contained in:
Claude
2025-12-03 15:15:05 +00:00
parent 65c77afbe0
commit 166f3b7384
7 changed files with 24 additions and 34 deletions
+3 -7
View File
@@ -4,7 +4,7 @@ import json
import tempfile
from pathlib import Path
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import MagicMock
import pytest
from fastapi.testclient import TestClient
@@ -261,9 +261,7 @@ def members_file() -> Any:
]
}
with tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False
) as f:
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
json.dump(members_data, f)
f.flush()
yield f.name
@@ -273,9 +271,7 @@ def members_file() -> Any:
@pytest.fixture
def web_app_with_members(
mock_http_client: MockHttpClient, members_file: str
) -> Any:
def web_app_with_members(mock_http_client: MockHttpClient, members_file: str) -> Any:
"""Create a web app with a members file configured."""
app = create_app(
api_url="http://localhost:8000",
-1
View File
@@ -1,6 +1,5 @@
"""Tests for the home page route."""
import pytest
from fastapi.testclient import TestClient
+5 -4
View File
@@ -1,6 +1,7 @@
"""Tests for the map page routes."""
import pytest
from typing import Any
from fastapi.testclient import TestClient
from tests.test_web.conftest import MockHttpClient
@@ -89,7 +90,7 @@ class TestMapDataAPIErrors:
"""Tests for map data handling API errors."""
def test_map_data_handles_api_error(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that map data handles API errors gracefully."""
mock_http_client.set_response(
@@ -111,7 +112,7 @@ class TestMapDataFiltering:
"""Tests for map data location filtering."""
def test_map_data_filters_invalid_lat(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that map data filters nodes with invalid latitude."""
mock_http_client.set_response(
@@ -143,7 +144,7 @@ class TestMapDataFiltering:
assert len(data["nodes"]) == 0
def test_map_data_filters_missing_lon(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that map data filters nodes with missing longitude."""
mock_http_client.set_response(
+4 -13
View File
@@ -4,7 +4,6 @@ import json
import tempfile
from pathlib import Path
import pytest
from fastapi.testclient import TestClient
from meshcore_hub.web.routes.members import load_members
@@ -68,9 +67,7 @@ class TestLoadMembers:
{"name": "Bob", "callsign": "W2XYZ"},
]
with tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False
) as f:
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
json.dump(members_data, f)
f.flush()
path = f.name
@@ -92,9 +89,7 @@ class TestLoadMembers:
]
}
with tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False
) as f:
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
json.dump(members_data, f)
f.flush()
path = f.name
@@ -109,9 +104,7 @@ class TestLoadMembers:
def test_load_members_invalid_json(self) -> None:
"""Test load_members with invalid JSON returns empty list."""
with tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False
) as f:
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
f.write("not valid json {")
f.flush()
path = f.name
@@ -126,9 +119,7 @@ class TestLoadMembers:
"""Test load_members with dict but no members key returns empty list."""
data = {"other_key": "value"}
with tempfile.NamedTemporaryFile(
mode="w", suffix=".json", delete=False
) as f:
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
json.dump(data, f)
f.flush()
path = f.name
+4 -3
View File
@@ -1,6 +1,7 @@
"""Tests for the messages page route."""
import pytest
from typing import Any
from fastapi.testclient import TestClient
from tests.test_web.conftest import MockHttpClient
@@ -84,7 +85,7 @@ class TestMessagesPageAPIErrors:
"""Tests for messages page handling API errors."""
def test_messages_handles_api_error(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that messages page handles API errors gracefully."""
mock_http_client.set_response(
@@ -99,7 +100,7 @@ class TestMessagesPageAPIErrors:
assert response.status_code == 200
def test_messages_handles_api_not_found(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that messages page handles API 404 gracefully."""
mock_http_client.set_response(
+4 -3
View File
@@ -1,6 +1,7 @@
"""Tests for the network overview page route."""
import pytest
from typing import Any
from fastapi.testclient import TestClient
from tests.test_web.conftest import MockHttpClient
@@ -51,7 +52,7 @@ class TestNetworkPageAPIErrors:
"""Tests for network page handling API errors."""
def test_network_handles_api_error(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that network page handles API errors gracefully."""
# Set error response for stats endpoint
@@ -67,7 +68,7 @@ class TestNetworkPageAPIErrors:
assert response.status_code == 200
def test_network_handles_api_not_found(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that network page handles API 404 gracefully."""
mock_http_client.set_response(
+4 -3
View File
@@ -1,6 +1,7 @@
"""Tests for the nodes page routes."""
import pytest
from typing import Any
from fastapi.testclient import TestClient
from tests.test_web.conftest import MockHttpClient
@@ -104,7 +105,7 @@ class TestNodesPageAPIErrors:
"""Tests for nodes pages handling API errors."""
def test_nodes_handles_api_error(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that nodes page handles API errors gracefully."""
mock_http_client.set_response(
@@ -119,7 +120,7 @@ class TestNodesPageAPIErrors:
assert response.status_code == 200
def test_node_detail_handles_not_found(
self, web_app: any, mock_http_client: MockHttpClient
self, web_app: Any, mock_http_client: MockHttpClient
) -> None:
"""Test that node detail page handles 404 from API."""
mock_http_client.set_response(