mirror of
https://github.com/ipnet-mesh/meshcore-mqtt.git
synced 2026-03-28 17:42:39 +01:00
Fixed pre-commit checks, all 116 tests pass.
Co-authored-by: jinglemansweep <jinglemansweep@users.noreply.github.com>
This commit is contained in:
@@ -47,7 +47,9 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Mock the rate limiting queue to execute immediately
|
||||
mock_queue_command = AsyncMock()
|
||||
meshcore_worker._queue_rate_limited_command = mock_queue_command
|
||||
meshcore_worker._queue_rate_limited_command = ( # type: ignore[method-assign]
|
||||
mock_queue_command
|
||||
)
|
||||
|
||||
# Create login command message
|
||||
command_data = {"destination": "repeater_node", "password": "guest_password"}
|
||||
@@ -63,9 +65,7 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Verify the command was queued for rate-limited execution
|
||||
expected_data = {"command_type": "send_login", **command_data}
|
||||
mock_queue_command.assert_called_once_with(
|
||||
"send_login", expected_data
|
||||
)
|
||||
mock_queue_command.assert_called_once_with("send_login", expected_data)
|
||||
|
||||
async def test_send_login_command_missing_destination(
|
||||
self, meshcore_worker: MeshCoreWorker
|
||||
@@ -129,7 +129,9 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Mock the rate limiting queue to execute immediately
|
||||
mock_queue_command = AsyncMock()
|
||||
meshcore_worker._queue_rate_limited_command = mock_queue_command
|
||||
meshcore_worker._queue_rate_limited_command = ( # type: ignore[method-assign]
|
||||
mock_queue_command
|
||||
)
|
||||
|
||||
# Create logoff command message
|
||||
command_data = {"destination": "repeater_node"}
|
||||
@@ -145,9 +147,7 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Verify the command was queued for rate-limited execution
|
||||
expected_data = {"command_type": "send_logoff", **command_data}
|
||||
mock_queue_command.assert_called_once_with(
|
||||
"send_logoff", expected_data
|
||||
)
|
||||
mock_queue_command.assert_called_once_with("send_logoff", expected_data)
|
||||
|
||||
async def test_send_logoff_command_missing_destination(
|
||||
self, meshcore_worker: MeshCoreWorker
|
||||
@@ -160,7 +160,7 @@ class TestGuestPasswordAuthentication:
|
||||
meshcore_worker.meshcore = mock_meshcore
|
||||
|
||||
# Create logoff command message without destination
|
||||
command_data = {} # Missing destination
|
||||
command_data: dict[str, Any] = {} # Missing destination
|
||||
message = Message.create(
|
||||
message_type=MessageType.MQTT_COMMAND,
|
||||
source="mqtt",
|
||||
@@ -187,8 +187,10 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Mock the rate limiting methods to execute immediately
|
||||
mock_queue_command = AsyncMock()
|
||||
meshcore_worker._queue_rate_limited_command = mock_queue_command
|
||||
|
||||
meshcore_worker._queue_rate_limited_command = ( # type: ignore[method-assign]
|
||||
mock_queue_command
|
||||
)
|
||||
|
||||
# Create telemetry command message with password
|
||||
command_data = {"destination": "repeater_node", "password": "guest_password"}
|
||||
message = Message.create(
|
||||
@@ -203,9 +205,7 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Verify the command was queued for rate-limited execution
|
||||
expected_data = {"command_type": "send_telemetry_req", **command_data}
|
||||
mock_queue_command.assert_called_once_with(
|
||||
"send_telemetry_req", expected_data
|
||||
)
|
||||
mock_queue_command.assert_called_once_with("send_telemetry_req", expected_data)
|
||||
|
||||
async def test_send_telemetry_req_without_password(
|
||||
self, meshcore_worker: MeshCoreWorker
|
||||
@@ -219,8 +219,10 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Mock rate limiting methods to execute immediately
|
||||
mock_queue_command = AsyncMock()
|
||||
meshcore_worker._queue_rate_limited_command = mock_queue_command
|
||||
|
||||
meshcore_worker._queue_rate_limited_command = ( # type: ignore[method-assign]
|
||||
mock_queue_command
|
||||
)
|
||||
|
||||
# Create telemetry command message without password
|
||||
command_data = {"destination": "node123"}
|
||||
message = Message.create(
|
||||
@@ -235,9 +237,7 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Verify the command was queued for rate-limited execution
|
||||
expected_data = {"command_type": "send_telemetry_req", **command_data}
|
||||
mock_queue_command.assert_called_once_with(
|
||||
"send_telemetry_req", expected_data
|
||||
)
|
||||
mock_queue_command.assert_called_once_with("send_telemetry_req", expected_data)
|
||||
|
||||
async def test_execute_rate_limited_login_command(
|
||||
self, meshcore_worker: MeshCoreWorker
|
||||
@@ -250,7 +250,9 @@ class TestGuestPasswordAuthentication:
|
||||
meshcore_worker.meshcore = mock_meshcore
|
||||
|
||||
# Mock rate limiting to execute immediately
|
||||
meshcore_worker._rate_limited_send = AsyncMock(return_value="login_success")
|
||||
meshcore_worker._rate_limited_send = AsyncMock( # type: ignore[method-assign]
|
||||
return_value="login_success"
|
||||
)
|
||||
|
||||
# Create message data for rate-limited execution
|
||||
message_data = {
|
||||
@@ -282,7 +284,9 @@ class TestGuestPasswordAuthentication:
|
||||
meshcore_worker.meshcore = mock_meshcore
|
||||
|
||||
# Mock rate limiting to execute immediately
|
||||
meshcore_worker._rate_limited_send = AsyncMock(return_value="logoff_success")
|
||||
meshcore_worker._rate_limited_send = AsyncMock( # type: ignore[method-assign]
|
||||
return_value="logoff_success"
|
||||
)
|
||||
|
||||
# Create message data for rate-limited execution
|
||||
message_data = {
|
||||
@@ -309,11 +313,13 @@ class TestGuestPasswordAuthentication:
|
||||
mock_meshcore = MagicMock()
|
||||
mock_meshcore.commands = MagicMock()
|
||||
mock_meshcore.commands.send_login = AsyncMock(return_value="login_success")
|
||||
mock_meshcore.commands.send_telemetry_req = AsyncMock(return_value="telemetry_data")
|
||||
mock_meshcore.commands.send_telemetry_req = AsyncMock(
|
||||
return_value="telemetry_data"
|
||||
)
|
||||
meshcore_worker.meshcore = mock_meshcore
|
||||
|
||||
# Mock rate limiting to execute immediately
|
||||
meshcore_worker._rate_limited_send = AsyncMock()
|
||||
meshcore_worker._rate_limited_send = AsyncMock() # type: ignore[method-assign]
|
||||
meshcore_worker._rate_limited_send.side_effect = [
|
||||
"login_success", # First call (login)
|
||||
"telemetry_data", # Second call (telemetry)
|
||||
@@ -332,7 +338,7 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Verify both login and telemetry were called
|
||||
assert meshcore_worker._rate_limited_send.call_count == 2
|
||||
|
||||
|
||||
# Check first call (login)
|
||||
first_call = meshcore_worker._rate_limited_send.call_args_list[0]
|
||||
assert first_call[0][0] == "send_login(repeater_node)"
|
||||
@@ -353,11 +359,15 @@ class TestGuestPasswordAuthentication:
|
||||
# Setup mock MeshCore instance
|
||||
mock_meshcore = MagicMock()
|
||||
mock_meshcore.commands = MagicMock()
|
||||
mock_meshcore.commands.send_telemetry_req = AsyncMock(return_value="telemetry_data")
|
||||
mock_meshcore.commands.send_telemetry_req = AsyncMock(
|
||||
return_value="telemetry_data"
|
||||
)
|
||||
meshcore_worker.meshcore = mock_meshcore
|
||||
|
||||
# Mock rate limiting to execute immediately
|
||||
meshcore_worker._rate_limited_send = AsyncMock(return_value="telemetry_data")
|
||||
meshcore_worker._rate_limited_send = AsyncMock( # type: ignore[method-assign]
|
||||
return_value="telemetry_data"
|
||||
)
|
||||
|
||||
# Create message data for rate-limited execution
|
||||
message_data = {
|
||||
@@ -402,14 +412,18 @@ class TestGuestPasswordAuthentication:
|
||||
# Setup mock MeshCore instance that raises an exception
|
||||
mock_meshcore = MagicMock()
|
||||
mock_meshcore.commands = MagicMock()
|
||||
mock_meshcore.commands.send_login = AsyncMock(side_effect=Exception("Login failed"))
|
||||
mock_meshcore.commands.send_login = AsyncMock(
|
||||
side_effect=Exception("Login failed")
|
||||
)
|
||||
meshcore_worker.meshcore = mock_meshcore
|
||||
|
||||
# Mock the rate limiting to propagate the error
|
||||
async def mock_queue_command(command_type: str, command_data: dict) -> Any:
|
||||
raise Exception("Login failed")
|
||||
|
||||
meshcore_worker._queue_rate_limited_command = mock_queue_command
|
||||
meshcore_worker._queue_rate_limited_command = ( # type: ignore[method-assign]
|
||||
mock_queue_command
|
||||
)
|
||||
|
||||
# Create login command message
|
||||
command_data = {"destination": "repeater_node", "password": "guest_password"}
|
||||
@@ -447,6 +461,6 @@ class TestGuestPasswordAuthentication:
|
||||
|
||||
# Verify login command was NOT called due to type validation
|
||||
mock_meshcore.commands.send_login.assert_not_called()
|
||||
|
||||
|
||||
# The main test is that the error is handled gracefully without crashing
|
||||
# The future handling may vary based on implementation details
|
||||
# The future handling may vary based on implementation details
|
||||
|
||||
Reference in New Issue
Block a user