2026-09-14 09:35:45 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from shared_backend.coreconfig import Info, Store
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StoreDefaultsTests(unittest.TestCase):
|
|
|
|
|
def test_seeds_from_fallback(self):
|
2026-09-18 13:11:49 +02:00
|
|
|
store = Store(
|
|
|
|
|
Info(
|
|
|
|
|
auth_guard_url="http://auth.example.com",
|
|
|
|
|
carrier_node_url="http://carrier.example.com",
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-09-14 09:35:45 +02:00
|
|
|
info = store.get()
|
|
|
|
|
self.assertEqual(info.auth_guard_url, "http://auth.example.com")
|
|
|
|
|
self.assertEqual(info.carrier_node_url, "http://carrier.example.com")
|
|
|
|
|
self.assertEqual(info.carrier_node_urls, ["http://carrier.example.com"])
|
|
|
|
|
|
|
|
|
|
def test_defaults_to_empty(self):
|
|
|
|
|
store = Store()
|
|
|
|
|
info = store.get()
|
|
|
|
|
self.assertEqual(info.auth_guard_url, "")
|
|
|
|
|
self.assertEqual(info.carrier_node_urls, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StoreSetTests(unittest.TestCase):
|
|
|
|
|
def test_partial_push_does_not_clobber_other_field(self):
|
2026-09-18 13:11:49 +02:00
|
|
|
store = Store(
|
|
|
|
|
Info(
|
|
|
|
|
auth_guard_url="http://auth.example.com",
|
|
|
|
|
carrier_node_url="http://carrier.example.com",
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-09-14 09:35:45 +02:00
|
|
|
store.set(Info(carrier_node_url="http://carrier2.example.com"))
|
|
|
|
|
info = store.get()
|
|
|
|
|
self.assertEqual(info.auth_guard_url, "http://auth.example.com")
|
|
|
|
|
self.assertEqual(info.carrier_node_url, "http://carrier2.example.com")
|
|
|
|
|
|
|
|
|
|
def test_blank_auth_guard_url_ignored(self):
|
|
|
|
|
store = Store(Info(auth_guard_url="http://auth.example.com"))
|
|
|
|
|
store.set(Info(auth_guard_url=""))
|
|
|
|
|
self.assertEqual(store.auth_guard_url, "http://auth.example.com")
|
|
|
|
|
|
|
|
|
|
def test_on_update_called_with_resulting_info(self):
|
|
|
|
|
store = Store()
|
|
|
|
|
seen = []
|
|
|
|
|
store.on_update(seen.append)
|
|
|
|
|
store.set(Info(auth_guard_url="http://auth.example.com"))
|
|
|
|
|
self.assertEqual(len(seen), 1)
|
|
|
|
|
self.assertEqual(seen[0].auth_guard_url, "http://auth.example.com")
|
|
|
|
|
|
|
|
|
|
def test_from_json_round_trip(self):
|
|
|
|
|
payload = {
|
|
|
|
|
"authGuardUrl": "http://auth.example.com",
|
|
|
|
|
"carrierNodeUrl": "http://carrier.example.com",
|
|
|
|
|
"carrierNodeUrls": ["http://carrier.example.com", "http://carrier2.example.com"],
|
|
|
|
|
}
|
|
|
|
|
info = Info.from_json(payload)
|
2026-09-18 13:11:49 +02:00
|
|
|
self.assertEqual(
|
|
|
|
|
info.carrier_node_urls, ["http://carrier.example.com", "http://carrier2.example.com"]
|
|
|
|
|
)
|
2026-09-14 09:35:45 +02:00
|
|
|
self.assertEqual(info.to_json()["carrierNodeUrl"], "http://carrier.example.com")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|