improve error reporting in case we mess it up later

This commit is contained in:
J. Nick Koston
2026-05-01 09:08:07 -05:00
parent 45c78dd5d2
commit a6cd2a9f4d
2 changed files with 48 additions and 6 deletions
+35 -5
View File
@@ -832,20 +832,50 @@ def test_perform_ota_extended_protocol_app(
@pytest.mark.usefixtures("mock_time")
def test_perform_ota_extended_protocol_unsupported_type(
def test_perform_ota_non_app_type_requires_extended_protocol(
mock_socket: Mock, mock_file: io.BytesIO
) -> None:
"""Test OTA fails when OTA type is unsupported by the client."""
# Setup socket responses for recv calls
"""Non-app OTA type must fail when device only supports the legacy protocol."""
recv_responses = [
bytes([espota2.RESPONSE_OK]), # First byte of version response
bytes([espota2.OTA_VERSION_2_0]), # Version number
bytes([espota2.RESPONSE_HEADER_OK]), # Features response
bytes([espota2.RESPONSE_HEADER_OK]), # Legacy single-byte feature ack
]
mock_socket.recv.side_effect = recv_responses
with pytest.raises(espota2.OTAError, match="Unsupported OTA type"):
with pytest.raises(
espota2.OTAError, match="Device does not support extended OTA protocol"
):
espota2.perform_ota(
mock_socket,
"testpass",
mock_file,
"test.bin",
255,
)
@pytest.mark.usefixtures("mock_time")
def test_perform_ota_non_app_type_requires_partition_access(
mock_socket: Mock, mock_file: io.BytesIO
) -> None:
"""Non-app OTA type must fail when device advertises extended protocol but
not the partition-access feature."""
recv_responses = [
bytes([espota2.RESPONSE_OK]), # First byte of version response
bytes([espota2.OTA_VERSION_2_0]), # Version number
bytes([espota2.RESPONSE_FEATURE_FLAGS]), # Extended protocol marker
bytes(
[espota2.SERVER_FEATURE_SUPPORTS_COMPRESSION]
), # Compression only, no partition access
]
mock_socket.recv.side_effect = recv_responses
with pytest.raises(
espota2.OTAError, match="Device does not support partition access"
):
espota2.perform_ota(
mock_socket,
"testpass",