test_notify.py (1668B)
1 from simplefe import notify 2 3 4 def test_send_pushover_success(monkeypatch): 5 captured = {} 6 7 def fake_urlopen(request, timeout=10): 8 captured["url"] = request.full_url 9 captured["data"] = request.data 10 11 monkeypatch.setattr(notify.urllib.request, "urlopen", fake_urlopen) 12 result = notify.send_pushover("tok", "usr", "Title", "Message") 13 assert result is True 14 assert captured["url"] == notify.PUSHOVER_URL 15 assert b"token=tok" in captured["data"] 16 assert b"user=usr" in captured["data"] 17 18 19 def test_send_pushover_failure_returns_false(monkeypatch): 20 def fake_urlopen(request, timeout=10): 21 raise OSError("network down") 22 23 monkeypatch.setattr(notify.urllib.request, "urlopen", fake_urlopen) 24 assert notify.send_pushover("tok", "usr", "Title", "Message") is False 25 26 27 def test_trigger_jellyfin_scan_success(monkeypatch): 28 captured = {} 29 30 def fake_urlopen(request, timeout=10): 31 captured["url"] = request.full_url 32 captured["headers"] = dict(request.header_items()) 33 34 monkeypatch.setattr(notify.urllib.request, "urlopen", fake_urlopen) 35 result = notify.trigger_jellyfin_scan("http://host:8096", "task123", "jtoken") 36 assert result is True 37 assert captured["url"] == "http://host:8096/ScheduledTasks/Running/task123" 38 assert captured["headers"] == {"X-emby-token": "jtoken"} 39 40 41 def test_trigger_jellyfin_scan_failure_returns_false(monkeypatch): 42 def fake_urlopen(request, timeout=10): 43 raise OSError("unreachable") 44 45 monkeypatch.setattr(notify.urllib.request, "urlopen", fake_urlopen) 46 assert notify.trigger_jellyfin_scan("http://host:8096", "task123", "jtoken") is False