Example #1
0
def test_generate_id_different_valid_different_id():
    pub = PagerDutyPublisher("url", "token")
    v = Validation("low", priority=Priority.CRITICAL)
    v2 = Validation("what", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "unable to transmogrify")
    another = Failure("foo", v2, "to transmogrify")
    assert pub._generate_id(failure) != pub._generate_id(another)
def test_generate_id_different_valid_different_id():
    pub = PagerDutyPublisher("url", "token")
    v = Validation("low", priority=Priority.CRITICAL)
    v2 = Validation("what", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "unable to transmogrify")
    another = Failure("foo", v2, "to transmogrify")
    assert pub._generate_id(failure) != pub._generate_id(another)
def test_message_length_capped(httpserver):
    httpserver.serve_content(code=300, headers={"content-type": "text/plain"},
                             content='{"mode":"NORMAL"}')
    pub = PagerDutyPublisher(httpserver.url, "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "-"*2000)
    message = pub._construct_message(failure)
    assert len(message) == pagerduty.MAX_LEN
def test_publish_failure(httpserver):
    httpserver.serve_content(code=300, headers={"content-type": "text/plain"},
                             content='{"mode":"NORMAL"}')
    pub = PagerDutyPublisher(httpserver.url, "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "message")
    with pytest.raises(PublishFailure):
        pub.send(failure)
Example #5
0
def test_message_length_capped(httpserver):
    httpserver.serve_content(code=300,
                             headers={"content-type": "text/plain"},
                             content='{"mode":"NORMAL"}')
    pub = PagerDutyPublisher(httpserver.url, "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "-" * 2000)
    message = pub._construct_message(failure)
    assert len(message) == pagerduty.MAX_LEN
Example #6
0
def test_publish_failure(httpserver):
    httpserver.serve_content(code=300,
                             headers={"content-type": "text/plain"},
                             content='{"mode":"NORMAL"}')
    pub = PagerDutyPublisher(httpserver.url, "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "message")
    with pytest.raises(PublishFailure):
        pub.send(failure)
Example #7
0
def test_publish_retries(ratelimited):
    global cutoff
    cutoff = 3
    global hits
    hits = 0
    pub = PagerDutyPublisher(ratelimited.url, "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "message")
    pub.send(failure)
def test_publish_retries(ratelimited):
    global cutoff
    cutoff = 3
    global hits
    hits = 0
    pub = PagerDutyPublisher(ratelimited.url, "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "message")
    pub.send(failure)
def test_publish_stops_retrying(ratelimited):
    global cutoff
    cutoff = 4
    global hits
    hits = 0
    pub = PagerDutyPublisher(ratelimited.url, "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "message")
    with pytest.raises(PublishFailure):
        pub.send(failure)
Example #10
0
def test_publish_stops_retrying(ratelimited):
    global cutoff
    cutoff = 4
    global hits
    hits = 0
    pub = PagerDutyPublisher(ratelimited.url, "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "message")
    with pytest.raises(PublishFailure):
        pub.send(failure)
def test_environment_name_is_present(httpserver):
    environment = 'xanadu'

    pub = PagerDutyPublisher(httpserver.url, "token",
                             environment=environment)

    message = pub._construct_message(
        Failure("ternary computers not supported!",
                Validation("bit frobnication validation",
                           priority=Priority.CRITICAL),
                "unable to frobnicate bits!"))

    assert message.startswith("Failure in %s:" % environment)
def test_generate_id_consistency_ssh(tmpdir):

    pub = PagerDutyPublisher("url", "token")
    ssh_ctx = ssh.SshContext("ubuntu", ssh_key_file(tmpdir))
    ssh_ctx2 = ssh.SshContext("ubuntu", ssh_key_file(tmpdir))

    v = ssh.SshCommandValidation(ssh_ctx, "name", "cmd", hosts=["a fake host"])
    v2 = ssh.SshCommandValidation(ssh_ctx2, "name", "cmd", hosts=["a fake host"])

    failure = Failure("bar", v, "unable to transmogrify")
    another = Failure("foo", v2, "to transmogrify")

    assert pub._generate_id(failure) == pub._generate_id(another)
Example #13
0
def test_environment_name_is_present(httpserver):
    environment = 'xanadu'

    pub = PagerDutyPublisher(httpserver.url, "token", environment=environment)

    message = pub._construct_message(
        Failure(
            "ternary computers not supported!",
            Validation("bit frobnication validation",
                       priority=Priority.CRITICAL),
            "unable to frobnicate bits!"))

    assert message.startswith("Failure in %s:" % environment)
Example #14
0
def test_generate_id_consistency_ssh(tmpdir):

    pub = PagerDutyPublisher("url", "token")
    ssh_ctx = ssh.SshContext("ubuntu", ssh_key_file(tmpdir))
    ssh_ctx2 = ssh.SshContext("ubuntu", ssh_key_file(tmpdir))

    v = ssh.SshCommandValidation(ssh_ctx, "name", "cmd", hosts=["a fake host"])
    v2 = ssh.SshCommandValidation(ssh_ctx2,
                                  "name",
                                  "cmd",
                                  hosts=["a fake host"])

    failure = Failure("bar", v, "unable to transmogrify")
    another = Failure("foo", v2, "to transmogrify")

    assert pub._generate_id(failure) == pub._generate_id(another)
Example #15
0
def test_generate_id_reflexive():
    pub = PagerDutyPublisher("url", "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "unable to transmogrify")
    another = Failure("foo", v, "unable")
    assert pub._generate_id(failure) == pub._generate_id(another)
def test_generate_id_reflexive():
    pub = PagerDutyPublisher("url", "token")
    v = Validation("low", priority=Priority.CRITICAL)
    failure = Failure("bar", v, "unable to transmogrify")
    another = Failure("foo", v, "unable")
    assert pub._generate_id(failure) == pub._generate_id(another)
Example #17
0
def test_requires_api_key():
    with pytest.raises(ValueError):
        return PagerDutyPublisher(api_end_point="fakeurl", api_key="")
Example #18
0
def new_publisher():
    return PagerDutyPublisher(api_end_point="fakeurl", api_key="key")