示例#1
0
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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
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)
示例#5
0
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)
示例#6
0
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)
示例#7
0
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)
示例#8
0
def test_send_no_user_token():
    with pytest.raises(PMUserError) as e:
        Pushover.send("message", api_token="xxx")
    assert "user_token" in str(e)
示例#9
0
def test_send_no_tokens():
    with pytest.raises(PMUserError) as e:
        Pushover.send("message")
    assert "api_token" in str(e)
示例#10
0
def test_send():
    assert Pushover.send("Hallo 123 :-)",
                         api_token="Adrvcc6svnbFQ8hmAx5tDhbWU8nDK6",
                         user_token="go8cCpgmWMdm9j2jpm4TmdzuHpVUjh")
示例#11
0
def test_send_no_tokens():
    with pytest.raises(PMUserError) as e:
        Pushover.send("message")
    assert "api_token" in str(e)
示例#12
0
    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())
示例#13
0
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)
示例#14
0
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)
示例#15
0
def test_send_no_user_token():
    with pytest.raises(PMUserError) as e:
        Pushover.send("message", api_token="xxx")
    assert "user_token" in str(e)
示例#16
0
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)
    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())
示例#18
0
def test_send():
    assert Pushover.send("Hallo 123 :-)", api_token="Adrvcc6svnbFQ8hmAx5tDhbWU8nDK6",
                         user_token="go8cCpgmWMdm9j2jpm4TmdzuHpVUjh")