mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
Update tests with new out_path_hash_mode field and surface error on path hash mode set failure
This commit is contained in:
@@ -123,7 +123,12 @@ async def update_radio_config(update: RadioConfigUpdate) -> RadioConfigResponse:
|
||||
status_code=400, detail="Firmware does not support path hash mode setting"
|
||||
)
|
||||
logger.info("Setting path hash mode to %d", update.path_hash_mode)
|
||||
await mc.commands.set_path_hash_mode(update.path_hash_mode)
|
||||
result = await mc.commands.set_path_hash_mode(update.path_hash_mode)
|
||||
if result is not None and result.type == EventType.ERROR:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"Failed to set path hash mode: {result.payload}",
|
||||
)
|
||||
radio_manager.path_hash_mode = update.path_hash_mode
|
||||
|
||||
# Sync time with system clock
|
||||
|
||||
@@ -288,6 +288,7 @@ function makeContact(overrides: Partial<Contact> = {}): Contact {
|
||||
last_read_at: null,
|
||||
first_seen: null,
|
||||
...overrides,
|
||||
out_path_hash_mode: overrides.out_path_hash_mode ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ const mockContact: Contact = {
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
|
||||
@@ -29,6 +29,7 @@ function createContact(overrides: Partial<Contact> = {}): Contact {
|
||||
last_read_at: null,
|
||||
first_seen: null,
|
||||
...overrides,
|
||||
out_path_hash_mode: overrides.out_path_hash_mode ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ const contacts: Contact[] = [
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
|
||||
@@ -228,6 +228,7 @@ describe('SearchView', () => {
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
|
||||
@@ -23,6 +23,7 @@ function makeContact(public_key: string, name: string, type = 1): Contact {
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
|
||||
@@ -196,6 +196,7 @@ describe('resolveContactFromHashToken', () => {
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
@@ -212,6 +213,7 @@ describe('resolveContactFromHashToken', () => {
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
@@ -228,6 +230,7 @@ describe('resolveContactFromHashToken', () => {
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
|
||||
@@ -49,6 +49,7 @@ function makeContact(suffix: string): Contact {
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
|
||||
@@ -45,6 +45,7 @@ function makeContact(pubkey: string): Contact {
|
||||
flags: 0,
|
||||
last_path: null,
|
||||
last_path_len: -1,
|
||||
out_path_hash_mode: 0,
|
||||
last_advert: null,
|
||||
lat: null,
|
||||
lon: null,
|
||||
|
||||
@@ -66,6 +66,7 @@ export interface Contact {
|
||||
flags: number;
|
||||
last_path: string | null;
|
||||
last_path_len: number;
|
||||
out_path_hash_mode: number;
|
||||
last_advert: number | null;
|
||||
lat: number | null;
|
||||
lon: number | null;
|
||||
|
||||
@@ -90,6 +90,7 @@ export interface Contact {
|
||||
flags: number;
|
||||
last_path: string | null;
|
||||
last_path_len: number;
|
||||
out_path_hash_mode: number;
|
||||
last_advert: number | null;
|
||||
lat: number | null;
|
||||
lon: number | null;
|
||||
|
||||
@@ -161,6 +161,27 @@ class TestUpdateRadioConfig:
|
||||
|
||||
assert exc.value.status_code == 400
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_propagates_radio_error_when_setting_path_hash_mode(self):
|
||||
mc = _mock_meshcore_with_info()
|
||||
mc.commands.set_path_hash_mode = AsyncMock(
|
||||
return_value=_radio_result(EventType.ERROR, {"error": "nope"})
|
||||
)
|
||||
|
||||
with (
|
||||
patch("app.routers.radio.require_connected", return_value=mc),
|
||||
patch.object(radio_manager, "_meshcore", mc),
|
||||
patch.object(radio_manager, "path_hash_mode_supported", True),
|
||||
patch.object(radio_manager, "path_hash_mode", 0),
|
||||
):
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
await update_radio_config(RadioConfigUpdate(path_hash_mode=1))
|
||||
|
||||
assert exc.value.status_code == 500
|
||||
assert "Failed to set path hash mode" in str(exc.value.detail)
|
||||
assert radio_manager.path_hash_mode == 0
|
||||
mc.commands.send_appstart.assert_not_awaited()
|
||||
|
||||
|
||||
class TestPrivateKeyImport:
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user