Files
yaris-obd/tests/test_app_device_config_runtime.py
Mathieu MoranandCopilot ba682fbf3a feat: add multi-device provisioning and local remote-config UI
- add multi-device portal device management, key rotation, and sync request APIs
- add Pi settings UI for remote server URL, device name, and API key
- add local test-connection and sync-now actions
- make upload and config sync reuse dynamic shared credentials
- add Phase 25.5c migration and docs updates

Co-authored-by: Copilot <[email protected]>
2026-08-10 18:02:09 -04:00

74 lines
2.3 KiB
Python

import unittest
from unittest.mock import Mock, patch
from modules import app_account, app_car, app_device_sync
class RuntimeDeviceConfigReloadTest(unittest.TestCase):
@patch.object(app_account.Account, "_load_config", return_value={})
@patch("modules.app_device_config.get_device_config")
def test_account_reload_runtime_config_uses_live_settings(
self,
get_device_config,
_load_config,
):
account = app_account.Account()
get_device_config.return_value = {
"owner_name": "alice",
"avatar_path": "img/alice.png",
}
account.reload_runtime_config()
self.assertEqual(account.name, "alice")
self.assertEqual(account.avatar_path, "img/alice.png")
@patch.object(app_car.Car, "_load_config", return_value={})
@patch("modules.app_device_config.get_device_config")
def test_car_reload_runtime_config_uses_live_settings(
self,
get_device_config,
_load_config,
):
car = app_car.Car()
get_device_config.return_value = {
"car_model": "Corolla",
"device_name": "Garage Pi",
}
car.reload_runtime_config()
self.assertEqual(car.model, "Corolla")
self.assertEqual(car.device_name, "Garage Pi")
class DeviceSyncReloadCallbackTest(unittest.TestCase):
def test_on_config_changed_calls_registered_callback(self):
callback = Mock()
original = app_device_sync._RELOAD_CALLBACK
try:
app_device_sync.register_reload_callback(callback)
app_device_sync._on_config_changed()
callback.assert_called_once_with()
finally:
app_device_sync._RELOAD_CALLBACK = original
@patch("modules.app_remote_config.server_credentials")
def test_sync_credentials_fall_back_to_upload_api_key(self, server_credentials):
server_credentials.return_value = {
"server_url": "https://example.test",
"device_name": "yaris-2013",
"api_key": "upload-key",
}
server_url, device_name, device_key = app_device_sync._server_credentials()
self.assertEqual(server_url, "https://example.test")
self.assertEqual(device_name, "yaris-2013")
self.assertEqual(device_key, "upload-key")
if __name__ == "__main__":
unittest.main()