def test_send_too_long_title(): with pytest.raises(PMUserError) as e: Pushover.send("x", title="a" * 251, api_token="xxx", user_token="asd") assert "exceeds" in str(e) with pytest.raises(PMException) as e: Pushover.send("x", title="a" * 250, api_token="xxx", user_token="asd") assert "status code: 400" in str(e)
def test_send_too_long_title(): with pytest.raises(PMUserError) as e: Pushover.send("x", title="a"*251, api_token="xxx", user_token="asd") assert "exceeds" in str(e) with pytest.raises(PMException) as e: Pushover.send("x", title="a"*250, api_token="xxx", user_token="asd") assert "status code: 400" in str(e)
def test_send_too_long_message(): with pytest.raises(PMUserError) as e: Pushover.send("x" * 1025, api_token="xxx", user_token="asd") assert "exceeds" in str(e) with pytest.raises(PMException) as e: Pushover.send("x" * 1024, api_token="xxx", user_token="asd") assert "status code: 400" in str(e)
def test_send_too_long_message(): with pytest.raises(PMUserError) as e: Pushover.send("x"*1025, api_token="xxx", user_token="asd") assert "exceeds" in str(e) with pytest.raises(PMException) as e: Pushover.send("x"*1024, api_token="xxx", user_token="asd") assert "status code: 400" in str(e)
def test_set_default_tokens(): with pytest.raises(PMUserError) as e: Pushover.send("message") assert "api_token" in str(e) Pushover.set_default_tokens("asd", "xxx") with pytest.raises(PMException) as e: Pushover.send("message") assert "status code: 400" in str(e)
def test_send_empty_message(): with pytest.raises(PMUserError) as e: Pushover.send("", api_token="xxx", user_token="asd") assert "has to be specified" in str(e)
def test_send_no_user_token(): with pytest.raises(PMUserError) as e: Pushover.send("message", api_token="xxx") assert "user_token" in str(e)
def test_send_no_tokens(): with pytest.raises(PMUserError) as e: Pushover.send("message") assert "api_token" in str(e)
def test_send(): assert Pushover.send("Hallo 123 :-)", api_token="Adrvcc6svnbFQ8hmAx5tDhbWU8nDK6", user_token="go8cCpgmWMdm9j2jpm4TmdzuHpVUjh")
sys.exit(0) print("Found low batteries: %s" % ", ".join(low)) # Load the resident to inform lars = ccu.residents.get_by_name("Lars") if lars is None: print("Failed to load resident \"Lars\".") sys.exit(1) if not lars.pushover_token: print("Lars has no pushover token configured. Terminating.") sys.exit(1) if not Config.pushover_api_token: print("There is no API token configured in the manager. Terminating.") sys.exit(1) if len(low) == 1: title = "1 device has low batteries" else: title = "%d devices have low batteries" % len(low) try: Pushover.send("Low batteries: %s" % ", ".join(low), title, api_token=Config.pushover_api_token, user_token=lars.pushover_token) except: print(traceback.format_exc())
def test_send_invalid_title_type(): with pytest.raises(PMUserError) as e: Pushover.send("x", title=b"asd", api_token="xxx", user_token="asd") assert "unicode" in str(e)