- load server sync creds from db/upload_creds.env like uploads do - fall back from YARIS_DEVICE_KEY to existing YARIS_API_KEY - document shared credential flow for server-synced identity - add test coverage for sync credential fallback Co-authored-by: Copilot <[email protected]>
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
import unittest
|
|
import os
|
|
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.dict(os.environ, {"YARIS_SERVER_URL": "https://example.test", "YARIS_API_KEY": "upload-key"}, clear=True)
|
|
def test_sync_credentials_fall_back_to_upload_api_key(self):
|
|
server_url, device_key = app_device_sync._server_credentials()
|
|
|
|
self.assertEqual(server_url, "https://example.test")
|
|
self.assertEqual(device_key, "upload-key")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|