Release v3.0.0
- Bump version to 3.0.0 and update docs - Fix Debian payload to include TUI and install /usr/bin/sensorpajen-tui wrapper - Make systemd unit upgrades safer and ignore deb build artifacts
This commit is contained in:
@@ -3,6 +3,12 @@ import os
|
||||
from pathlib import Path
|
||||
from sensorpajen.discovery_manager import DiscoveryManager, DiscoveredSensor
|
||||
|
||||
|
||||
class _DummyCompletedProcess:
|
||||
def __init__(self, returncode: int = 0, stderr: bytes = b""):
|
||||
self.returncode = returncode
|
||||
self.stderr = stderr
|
||||
|
||||
def test_discovery_manager_init(tmp_path):
|
||||
db_file = tmp_path / "sensors.db"
|
||||
manager = DiscoveryManager(str(db_file))
|
||||
@@ -55,3 +61,94 @@ def test_discovery_manager_persistence(tmp_path):
|
||||
assert len(pending) == 1
|
||||
assert pending[0].mac == mac
|
||||
assert pending[0].name == "ATC_123456"
|
||||
|
||||
|
||||
def test_send_ntfy_notification_disabled(monkeypatch, tmp_path):
|
||||
from sensorpajen import discovery_manager as dm_mod
|
||||
|
||||
monkeypatch.setattr(dm_mod.config, "NTFY_ENABLED", False)
|
||||
monkeypatch.setattr(dm_mod.config, "NTFY_TOKEN", "token")
|
||||
|
||||
called = {"run": False}
|
||||
|
||||
def _fake_run(*args, **kwargs):
|
||||
called["run"] = True
|
||||
return _DummyCompletedProcess(0)
|
||||
|
||||
monkeypatch.setattr(dm_mod.subprocess, "run", _fake_run)
|
||||
|
||||
manager = dm_mod.DiscoveryManager(str(tmp_path / "dummy.db"))
|
||||
sensor = dm_mod.DiscoveredSensor(
|
||||
mac="AA",
|
||||
name="N",
|
||||
rssi=-1,
|
||||
first_seen="now",
|
||||
last_seen="now",
|
||||
sample_reading={"temperature": 1, "humidity": 2, "battery_percent": 3},
|
||||
)
|
||||
|
||||
manager.send_ntfy_notification(sensor)
|
||||
assert called["run"] is False
|
||||
|
||||
|
||||
def test_send_ntfy_notification_missing_token(monkeypatch, tmp_path):
|
||||
from sensorpajen import discovery_manager as dm_mod
|
||||
|
||||
monkeypatch.setattr(dm_mod.config, "NTFY_ENABLED", True)
|
||||
monkeypatch.setattr(dm_mod.config, "NTFY_TOKEN", "")
|
||||
|
||||
called = {"run": False}
|
||||
|
||||
def _fake_run(*args, **kwargs):
|
||||
called["run"] = True
|
||||
return _DummyCompletedProcess(0)
|
||||
|
||||
monkeypatch.setattr(dm_mod.subprocess, "run", _fake_run)
|
||||
|
||||
manager = dm_mod.DiscoveryManager(str(tmp_path / "dummy2.db"))
|
||||
sensor = dm_mod.DiscoveredSensor(
|
||||
mac="AA",
|
||||
name="N",
|
||||
rssi=-1,
|
||||
first_seen="now",
|
||||
last_seen="now",
|
||||
sample_reading={"temperature": 1, "humidity": 2, "battery_percent": 3},
|
||||
)
|
||||
|
||||
manager.send_ntfy_notification(sensor)
|
||||
assert called["run"] is False
|
||||
|
||||
|
||||
def test_send_ntfy_notification_message_mentions_tui(monkeypatch, tmp_path):
|
||||
from sensorpajen import discovery_manager as dm_mod
|
||||
|
||||
monkeypatch.setattr(dm_mod.config, "NTFY_ENABLED", True)
|
||||
monkeypatch.setattr(dm_mod.config, "NTFY_TOKEN", "token")
|
||||
monkeypatch.setattr(dm_mod.config, "NTFY_URL", "https://ntfy.sh")
|
||||
monkeypatch.setattr(dm_mod.config, "NTFY_TOPIC", "sensorpajen")
|
||||
|
||||
captured = {"args": None}
|
||||
|
||||
def _fake_run(args, capture_output=True, timeout=10):
|
||||
captured["args"] = args
|
||||
return _DummyCompletedProcess(0)
|
||||
|
||||
monkeypatch.setattr(dm_mod.subprocess, "run", _fake_run)
|
||||
|
||||
manager = dm_mod.DiscoveryManager(str(tmp_path / "sensors.db"))
|
||||
sensor = dm_mod.DiscoveredSensor(
|
||||
mac="AA:BB",
|
||||
name="ATC_123",
|
||||
rssi=-1,
|
||||
first_seen="2025-01-01T00:00:00",
|
||||
last_seen="2025-01-01T00:00:00",
|
||||
sample_reading={"temperature": 10, "humidity": 20, "battery_percent": 30},
|
||||
)
|
||||
|
||||
manager.send_ntfy_notification(sensor)
|
||||
|
||||
assert captured["args"] is not None
|
||||
# curl args: [..., "-d", message, url]
|
||||
assert "-d" in captured["args"]
|
||||
message = captured["args"][captured["args"].index("-d") + 1]
|
||||
assert "sensorpajen-tui" in message
|
||||
|
||||
Reference in New Issue
Block a user