feat: publish dbussmsforward refactor
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
import unittest
|
||||
|
||||
from dbussmsforward.config import AppConfig, load_config_dict
|
||||
|
||||
|
||||
class ConfigModelTests(unittest.TestCase):
|
||||
def test_load_config_dict_maps_autmanpush_and_defaults(self):
|
||||
raw = {
|
||||
"daemon": {"mode": "web"},
|
||||
"notifications": {
|
||||
"autman_push": {
|
||||
"enabled": True,
|
||||
"api_url": "https://push.example/api",
|
||||
"access_token": "***",
|
||||
"method": "POST",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
config = load_config_dict(raw)
|
||||
|
||||
self.assertIsInstance(config, AppConfig)
|
||||
self.assertEqual(config.daemon.mode, "web")
|
||||
self.assertTrue(config.forwarding.enable_sms_code_extraction)
|
||||
self.assertTrue(config.notifications.autman_push.enabled)
|
||||
self.assertEqual(config.notifications.autman_push.api_url, "https://push.example/api")
|
||||
self.assertEqual(config.notifications.autman_push.access_token, "secret-token")
|
||||
self.assertEqual(config.notifications.autman_push.method, "POST")
|
||||
|
||||
def test_load_config_dict_accepts_legacy_appsettings_wrapper(self):
|
||||
raw = {
|
||||
"appSettings": {
|
||||
"DeviceName": "router-a",
|
||||
"SmsCodeKey": "验证码±code",
|
||||
"AutmanPushConfig": {
|
||||
"ApiUrl": "https://legacy.example/push",
|
||||
"AccessToken": "legacy-token",
|
||||
"Method": "GET",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
config = load_config_dict(raw)
|
||||
|
||||
self.assertEqual(config.forwarding.device_name, "router-a")
|
||||
self.assertEqual(config.forwarding.sms_code_key, "验证码±code")
|
||||
self.assertEqual(config.notifications.autman_push.api_url, "https://legacy.example/push")
|
||||
self.assertEqual(config.notifications.autman_push.access_token, "legacy-token")
|
||||
self.assertEqual(config.notifications.autman_push.method, "GET")
|
||||
|
||||
def test_load_config_dict_reads_sms_source_and_console_notification(self):
|
||||
raw = {
|
||||
"notifications": {"console": {"enabled": True}},
|
||||
"sms_source": {
|
||||
"kind": "file",
|
||||
"path": "/tmp/messages.json",
|
||||
"delete_after_read": True,
|
||||
"poll_interval_seconds": 9,
|
||||
},
|
||||
}
|
||||
|
||||
config = load_config_dict(raw)
|
||||
|
||||
self.assertTrue(config.notifications.console.enabled)
|
||||
self.assertEqual(config.sms_source.kind, "file")
|
||||
self.assertEqual(config.sms_source.path, "/tmp/messages.json")
|
||||
self.assertTrue(config.sms_source.delete_after_read)
|
||||
self.assertEqual(config.sms_source.poll_interval_seconds, 9)
|
||||
|
||||
def test_load_config_dict_reads_modemmanager_sms_source_options(self):
|
||||
raw = {
|
||||
"sms_source": {
|
||||
"kind": "modemmanager",
|
||||
"modem_object_path": "auto",
|
||||
"system_bus_address": "unix:path=/run/dbus/system_bus_socket",
|
||||
"storage_blacklist": ["SM", "mt", "sm"],
|
||||
"state_ready_values": [3, "4"],
|
||||
}
|
||||
}
|
||||
|
||||
config = load_config_dict(raw)
|
||||
|
||||
self.assertEqual(config.sms_source.kind, "modemmanager")
|
||||
self.assertEqual(config.sms_source.modem_object_path, "auto")
|
||||
self.assertEqual(config.sms_source.system_bus_address, "unix:path=/run/dbus/system_bus_socket")
|
||||
self.assertEqual(config.sms_source.storage_blacklist, ["sm", "mt"])
|
||||
self.assertEqual(config.sms_source.state_ready_values, [3, 4])
|
||||
|
||||
def test_load_config_dict_maps_all_notification_channels(self):
|
||||
raw = {
|
||||
"notifications": {
|
||||
"email": {
|
||||
"enabled": True,
|
||||
"smtp_host": "smtp.example.com",
|
||||
"smtp_port": 587,
|
||||
"enable_ssl": False,
|
||||
"email_key": "mail-key",
|
||||
"send_email": "sender@example.com",
|
||||
"receive_email": "receiver@example.com",
|
||||
},
|
||||
"pushplus": {
|
||||
"enabled": True,
|
||||
"token": "push-token",
|
||||
"endpoint": "https://pushplus.example/send",
|
||||
},
|
||||
"dingtalk": {
|
||||
"enabled": True,
|
||||
"access_token": "ding-token",
|
||||
"secret": "ding-secret",
|
||||
},
|
||||
"bark": {
|
||||
"enabled": True,
|
||||
"server_url": "https://bark.example",
|
||||
"bark_key": "bark-key",
|
||||
},
|
||||
"wecom_application": {
|
||||
"enabled": True,
|
||||
"corp_id": "corp-id",
|
||||
"agent_id": "1000001",
|
||||
"application_secret": "app-secret",
|
||||
},
|
||||
"telegram_bot": {
|
||||
"enabled": True,
|
||||
"enable_custom_api": True,
|
||||
"custom_api": "https://tg.example",
|
||||
"bot_token": "bot-token",
|
||||
"chat_id": "10001",
|
||||
},
|
||||
"shell": {
|
||||
"enabled": True,
|
||||
"shell_path": "/tmp/hook.sh",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
config = load_config_dict(raw)
|
||||
|
||||
self.assertTrue(config.notifications.email.enabled)
|
||||
self.assertEqual(config.notifications.email.smtp_host, "smtp.example.com")
|
||||
self.assertEqual(config.notifications.pushplus.endpoint, "https://pushplus.example/send")
|
||||
self.assertEqual(config.notifications.dingtalk.secret, "ding-secret")
|
||||
self.assertEqual(config.notifications.bark.bark_key, "bark-key")
|
||||
self.assertEqual(config.notifications.wecom_application.agent_id, "1000001")
|
||||
self.assertTrue(config.notifications.telegram_bot.enable_custom_api)
|
||||
self.assertEqual(config.notifications.telegram_bot.custom_api, "https://tg.example")
|
||||
self.assertEqual(config.notifications.shell.shell_path, "/tmp/hook.sh")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user