107 lines
3.8 KiB
Python
107 lines
3.8 KiB
Python
import json
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
PROJECT_ROOT = Path("/Users/chick/.Hermes/workspace/DbusSmsForward")
|
|
CLI_ENV = {**(__import__("os").environ), "PYTHONPATH": str(PROJECT_ROOT / "src")}
|
|
|
|
|
|
class EnvironmentCheckCliTests(unittest.TestCase):
|
|
def test_env_check_command_reports_missing_runtime_dependencies(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
root = Path(tmpdir)
|
|
config_path = root / "config.json"
|
|
config_path.write_text(
|
|
json.dumps(
|
|
{
|
|
"notifications": {
|
|
"autman_push": {
|
|
"enabled": True,
|
|
"api_url": "https://autman.example/push",
|
|
"access_token": "secret-token",
|
|
}
|
|
},
|
|
"sms_source": {
|
|
"kind": "modemmanager",
|
|
"system_bus_address": "unix:path=/tmp/does-not-exist-system-bus",
|
|
"modem_object_path": "auto",
|
|
},
|
|
},
|
|
ensure_ascii=False,
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"dbussmsforward.cli",
|
|
"env-check",
|
|
"--config",
|
|
str(config_path),
|
|
],
|
|
cwd=str(PROJECT_ROOT),
|
|
env=CLI_ENV,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
|
|
self.assertEqual(result.returncode, 2)
|
|
self.assertIn("status=fail", result.stdout)
|
|
self.assertIn("category=python_module name=dbus_next", result.stdout)
|
|
self.assertIn("category=file name=sms_source.system_bus_address", result.stdout)
|
|
self.assertIn("category=config name=notifications.autman_push.api_url", result.stdout)
|
|
self.assertIn("summary failed=", result.stdout)
|
|
|
|
def test_env_check_command_passes_for_file_source_console_only_config(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
root = Path(tmpdir)
|
|
config_path = root / "config.json"
|
|
messages_path = root / "messages.json"
|
|
messages_path.write_text("[]", encoding="utf-8")
|
|
config_path.write_text(
|
|
json.dumps(
|
|
{
|
|
"forwarding": {"device_name": "router-self-check"},
|
|
"notifications": {"console": {"enabled": True}},
|
|
"sms_source": {
|
|
"kind": "file",
|
|
"path": str(messages_path),
|
|
},
|
|
},
|
|
ensure_ascii=False,
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"dbussmsforward.cli",
|
|
"env-check",
|
|
"--config",
|
|
str(config_path),
|
|
],
|
|
cwd=str(PROJECT_ROOT),
|
|
env=CLI_ENV,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
|
|
self.assertEqual(result.returncode, 0, msg=result.stderr)
|
|
self.assertIn("status=ok category=config name=config_path", result.stdout)
|
|
self.assertIn("status=ok category=file name=sms_source.path", result.stdout)
|
|
self.assertIn("summary failed=0", result.stdout)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|