mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
fix(gateway): validate multiplex adapter config by platform
This commit is contained in:
parent
bd44ef8645
commit
64746b4bd3
7 changed files with 97 additions and 20 deletions
|
|
@ -27,15 +27,29 @@ from plugins.platforms.homeassistant.adapter import (
|
|||
|
||||
|
||||
class TestCheckRequirements:
|
||||
def test_returns_true_when_aiohttp_present(self, monkeypatch):
|
||||
def test_returns_true_without_token_when_aiohttp_available(self, monkeypatch):
|
||||
monkeypatch.delenv("HASS_TOKEN", raising=False)
|
||||
assert check_ha_requirements() is True
|
||||
|
||||
def test_returns_true_with_token(self, monkeypatch):
|
||||
monkeypatch.setenv("HASS_TOKEN", "test-token")
|
||||
assert check_ha_requirements() is True
|
||||
|
||||
@patch("plugins.platforms.homeassistant.adapter.AIOHTTP_AVAILABLE", False)
|
||||
def test_returns_false_without_aiohttp(self, monkeypatch):
|
||||
monkeypatch.setenv("HASS_TOKEN", "test-token")
|
||||
assert check_ha_requirements() is False
|
||||
|
||||
def test_validate_config_accepts_platform_token(self, monkeypatch):
|
||||
monkeypatch.delenv("HASS_TOKEN", raising=False)
|
||||
config = PlatformConfig(enabled=True, token="config-token")
|
||||
assert validate_ha_config(config) is True
|
||||
|
||||
def test_validate_config_rejects_missing_token(self, monkeypatch):
|
||||
monkeypatch.delenv("HASS_TOKEN", raising=False)
|
||||
config = PlatformConfig(enabled=True, token="")
|
||||
assert validate_ha_config(config) is False
|
||||
|
||||
|
||||
class TestValidateConfig:
|
||||
def test_returns_false_without_token_in_config_or_env(self, monkeypatch):
|
||||
|
|
|
|||
|
|
@ -916,13 +916,32 @@ class TestMattermostRequirements:
|
|||
monkeypatch.delenv("MATTERMOST_TOKEN", raising=False)
|
||||
monkeypatch.delenv("MATTERMOST_URL", raising=False)
|
||||
from plugins.platforms.mattermost.adapter import check_mattermost_requirements
|
||||
assert check_mattermost_requirements() is False
|
||||
assert check_mattermost_requirements() is True
|
||||
|
||||
def test_check_requirements_without_url(self, monkeypatch):
|
||||
monkeypatch.setenv("MATTERMOST_TOKEN", "test-token")
|
||||
monkeypatch.delenv("MATTERMOST_URL", raising=False)
|
||||
from plugins.platforms.mattermost.adapter import check_mattermost_requirements
|
||||
assert check_mattermost_requirements() is False
|
||||
assert check_mattermost_requirements() is True
|
||||
|
||||
def test_validate_config_accepts_platform_values(self, monkeypatch):
|
||||
monkeypatch.delenv("MATTERMOST_TOKEN", raising=False)
|
||||
monkeypatch.delenv("MATTERMOST_URL", raising=False)
|
||||
from plugins.platforms.mattermost.adapter import validate_mattermost_config
|
||||
|
||||
config = PlatformConfig(
|
||||
enabled=True,
|
||||
token="cfg-token",
|
||||
extra={"url": "https://mm.example.com"},
|
||||
)
|
||||
assert validate_mattermost_config(config) is True
|
||||
|
||||
def test_validate_config_rejects_missing_url(self, monkeypatch):
|
||||
monkeypatch.delenv("MATTERMOST_URL", raising=False)
|
||||
from plugins.platforms.mattermost.adapter import validate_mattermost_config
|
||||
|
||||
config = PlatformConfig(enabled=True, token="cfg-token", extra={})
|
||||
assert validate_mattermost_config(config) is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -302,7 +302,29 @@ class TestSignalHelpers:
|
|||
from gateway.platforms.signal import check_signal_requirements
|
||||
monkeypatch.delenv("SIGNAL_HTTP_URL", raising=False)
|
||||
monkeypatch.delenv("SIGNAL_ACCOUNT", raising=False)
|
||||
assert check_signal_requirements() is False
|
||||
assert check_signal_requirements() is True
|
||||
|
||||
def test_validate_signal_config_accepts_platform_values(self, monkeypatch):
|
||||
monkeypatch.delenv("SIGNAL_HTTP_URL", raising=False)
|
||||
monkeypatch.delenv("SIGNAL_ACCOUNT", raising=False)
|
||||
from gateway.platforms.signal import validate_signal_config
|
||||
|
||||
config = PlatformConfig(
|
||||
enabled=True,
|
||||
extra={
|
||||
"http_url": "http://localhost:8080",
|
||||
"account": "+155****4567",
|
||||
},
|
||||
)
|
||||
assert validate_signal_config(config) is True
|
||||
|
||||
def test_validate_signal_config_rejects_missing_account(self, monkeypatch):
|
||||
monkeypatch.delenv("SIGNAL_HTTP_URL", raising=False)
|
||||
monkeypatch.delenv("SIGNAL_ACCOUNT", raising=False)
|
||||
from gateway.platforms.signal import validate_signal_config
|
||||
|
||||
config = PlatformConfig(enabled=True, extra={"http_url": "http://localhost:8080"})
|
||||
assert validate_signal_config(config) is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue