def test_send_success(): graphite = new_publisher() v = Validation("low", priority=Priority.LOW) success = Success("bar", v) graphite.send(success) assert graphite._graphite.counter["passed"] == 1 assert graphite._graphite.counter["failed"] == 0
def test_get_email_settings(tmpdir, smtpserver, httpserver): email_pub = create_default_email_publisher(tmpdir, smtpserver) http_validator = \ HttpValidation.get(httpserver.url).expect_status_codes([200]) email_type = "test_alert" subject = "subject test line" body = "body test" recipient_array = [{"real_name": "Test Recipient", "address": "*****@*****.**"}] sender = {"real_name": "Alarmageddon Monitor", "address": "*****@*****.**"} email_settings = {"email_type": email_type, "subject": subject, "body": body, "sender": sender, "recipients": recipient_array } emailer.enrich(http_validator, email_settings) result = Success("validation name", http_validator) enriched_email_settings = email_pub.get_email_settings(result) assert enriched_email_settings['email_type'] == email_type assert enriched_email_settings['subject'] == subject assert enriched_email_settings['body'] == body assert enriched_email_settings['sender'] == sender assert enriched_email_settings['recipients'] == recipient_array
def test_generate_id_different_result_same_valid(): pub = PagerDutyPublisher("url", "token") v = Validation("low", priority=Priority.CRITICAL) v2 = Validation("low", priority=Priority.CRITICAL) failure = Failure("bar", v, "unable to transmogrify") another = Success("foo", v2, "to transmogrify") assert pub._generate_id(failure) == pub._generate_id(another)
def test_does_not_publish_success(goodserver): publisher = HttpPublisher(name="Test", url=goodserver.url, publish_successes=False) publisher.send( Success("success", Validation("validation", priority=Priority.NORMAL), "description")) assert not request_sent
def test_reporter_shows_publish_error_info(env): reporter = env["reporter"] publishers = [FailingPublisher()] reporter.publishers = publishers reporter.collect(Success("success", Validation("valid"))) try: reporter.report() except ReportingFailure,e: assert "NOT_HIDDEN" in str(e)
def test_publishes_success_to_correct_url(goodserver): publisher = HttpPublisher(name="Test", success_url=goodserver.url + '/success', failure_url=goodserver.url + '/failure', publish_successes=True) publisher.send( Success("success", Validation("validation", priority=Priority.NORMAL), "description")) assert request_sent assert requested_url == '/success'
def test_construct_tree_batch(): pub = JUnitPublisher("should_not_be_created.xml") v = Validation("low", priority=Priority.CRITICAL) failure = Failure("bar", v, "message", time=30) success = Success("foo", v, time=20) tree = pub._construct_tree([failure, failure, success]).getroot() assert tree.get("failures") == str(2) assert tree.get("tests") == str(3) assert float(tree.get("time")) == 80 assert len(tree) == 3
def test_reporter_correctly_sends_success(env, valid): reporter = env["reporter"] publishers = [] for i in xrange(10): publishers.append(MockPublisher()) reporter.publishers = publishers reporter.collect(Success("success", Validation("valid"))) reporter.report() for pub in publishers: assert pub.successes == 1 assert pub.failures == 0
def test_construct_tree_success(): pub = JUnitPublisher("should_not_be_created.xml") v = Validation("low", priority=Priority.CRITICAL) success = Success("bar", v, time=30) tree = pub._construct_tree([success]).getroot() assert tree.get("failures") == str(0) assert tree.get("tests") == str(1) assert float(tree.get("time")) == 30 assert len(tree) == 1 for element in tree: assert float(element.get("time")) == 30 assert len(element) == 0
def test_reporter_correctly_batches(env): reporter = env["reporter"] publishers = [] for i in xrange(10): publishers.append(MockPublisher()) reporter.publishers = publishers reporter.collect(Failure("failed", Validation("valid"), "why it failed")) reporter.collect(Failure("failed2", Validation("valid"), "why it failed")) reporter.collect(Success("success", Validation("valid"))) reporter.report() for pub in publishers: assert pub.failures == 2 assert pub.successes == 1
def test_reporter_runs_all_publishers_before_raising(env, valid): reporter = env["reporter"] bad_pub = 5 publishers = [] for i in xrange(10): publishers.append(MockPublisher()) publishers[bad_pub] = FailingPublisher() reporter.publishers = publishers reporter.collect(Success("success", Validation("valid"))) with pytest.raises(ReportingFailure): reporter.report() for i,pub in enumerate(publishers): if i != bad_pub: assert pub.successes == 1 assert pub.failures == 0
def test_can_publish(tmpdir, smtpserver, httpserver): email_pub = create_default_email_publisher(tmpdir, smtpserver) http_validator = \ HttpValidation.get(httpserver.url).expect_status_codes([200]) email_settings = {"email_type": "test_alert", "subject": "subject test line", "body": "body test", "sender": {"real_name": "Alarmageddon Monitor", "address": "*****@*****.**"}, "recipients": [{"real_name": "Test Recipient", "address": "*****@*****.**"}] } emailer.enrich(http_validator, email_settings) result = Success("validation name", http_validator) assert email_pub._can_publish(result) is True
def _perform(validation, immutable_group_failures, results): start = time.time() try: validation.perform(immutable_group_failures) try: runtime = validation.get_elapsed_time() except NotImplementedError: runtime = time.time() - start if validation.timeout is not None and runtime > validation.timeout: result = Failure(validation.name, validation, "{} ran for {} (exceeded timeout of {})".format( validation, runtime, validation.timeout), time=runtime) else: result = Success(validation.name, validation, time=runtime) except Exception, e: result = Failure(validation.name, validation, str(e), time=time.time() - start)
def test_can_publish_requires_recipients(tmpdir, smtpserver, monkeypatch, httpserver): email_pub = create_default_email_publisher(tmpdir, smtpserver) http_validator = \ HttpValidation.get(httpserver.url).expect_status_codes([200]) email_settings = {"email_type": "test_alert", "subject": "subject test line", "body": "body test", "sender": {"real_name": "Alarmageddon Monitor", "address": "*****@*****.**"}, "recipients": [{"real_name": "Test Recipient", "address": "*****@*****.**"}] } emailer.enrich(http_validator, email_settings) temp_pub = EmailPublisher({"fake": "config"}) data = http_validator.get_enriched(temp_pub) monkeypatch.delitem(data['email_settings'], "recipients") result = Success("validation name", http_validator) assert email_pub._can_publish(result) is False
def test_get_runtime_context(tmpdir, smtpserver, httpserver): email_pub = create_default_email_publisher(tmpdir, smtpserver) http_validator = \ HttpValidation.get(httpserver.url).expect_status_codes([200]) email_type = "test_alert" subject = "subject test line" body = "body test" recipient_array = [{"real_name": "Test Recipient", "address": "*****@*****.**"}] sender = {"real_name": "Alarmageddon Monitor", "address": "*****@*****.**"} email_settings = {"email_type": email_type, "subject": subject, "body": body, "sender": sender, "recipients": recipient_array } context = {"custom_replacement": "hello world"} emailer.enrich(http_validator, email_settings, runtime_context=context) result = Success("validation name", http_validator) enriched_context = email_pub.get_runtime_context(result) assert enriched_context['custom_replacement'] == "hello world"
def test_successes_are_not_failures(): v = Validation("low", priority=Priority.LOW) s = Success("name", v, "desc") assert not s.is_failure()
def test_send_fails(): pub = JUnitPublisher("should_not_be_created.xml") v = Validation("low", priority=Priority.CRITICAL) success = Success("bar", v) with pytest.raises(NotImplementedError): pub.send(success)
def test_can_publish_requires_enrichment(tmpdir, smtpserver, httpserver): email_pub = create_default_email_publisher(tmpdir, smtpserver) http_validator = \ HttpValidation.get(httpserver.url).expect_status_codes([200]) result = Success("validation name", http_validator) assert email_pub._can_publish(result) is False
def testSendSuccess(no_post): pager = new_publisher() v = Validation("low", priority=Priority.CRITICAL) success = Success("bar", v) pager.send(success)
def test_successes_are_not_failures(): v = Validation("low", priority=Priority.LOW) s = Success("name", v, "desc") assert not s.is_failure()