- send X-Device-Name and X-Api-Key to /api/device-config - require YARIS_DEVICE_NAME alongside shared upload creds - fix server create_device output to match actual Pi env names - document shared upload/config sync credential requirements Co-authored-by: Copilot <[email protected]>
78 lines
2.3 KiB
Python
78 lines
2.3 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_DEVICE_NAME": "yaris-2013",
|
|
"YARIS_API_KEY": "upload-key",
|
|
},
|
|
clear=True,
|
|
)
|
|
def test_sync_credentials_fall_back_to_upload_api_key(self):
|
|
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()
|