Esempio n. 1
0
def test_apptuit_send_exception_repr():
    """
    Test __repr__ for ApptuitSendException
    """
    err = repr(
        ApptuitSendException("test", 400, 1, 1, [{
            "datapoint": "test",
            "error": "test_error"
        }]))
    assert_equals(
        err,
        "1 points failed with status: 400\ntest_error error occurred in the "
        "datapoint test\n")
Esempio n. 2
0
def test_apptuit_send_exception_without_status():
    """
    Test __str__ for ApptuitSendException without status_code parameter
    """
    err = str(
        ApptuitSendException("test",
                             success=1,
                             failed=1,
                             errors=[{
                                 "datapoint": "test",
                                 "error": "test_error"
                             }]))
    assert_equals(
        err, "1 points failed\ntest_error error occurred in the "
        "datapoint test\n")
def test_partially_successful_send(mock_post):
    """
        Test that we handle partially successful sends
    """
    mock_post.return_value.status_code = 400
    mock_post.side_effect = ApptuitSendException("failed to send some points",
                                                 400,
                                                 success=98,
                                                 failed=2,
                                                 errors=[])
    token = "asdashdsauh_8aeraerf"
    tags = {
        "host": "localhost",
        "region": "us-east-1",
        "service": "web-server"
    }
    registry = MetricsRegistry()
    reporter = ApptuitReporter(sanitize_mode=None,
                               registry=registry,
                               api_endpoint="http://localhost",
                               reporting_interval=1,
                               token=token,
                               prefix="apr.",
                               tags=tags)
    points_to_be_created = 100
    counters = [
        registry.counter("counter%d" % i) for i in range(points_to_be_created)
    ]
    for i in range(points_to_be_created):
        counters[i].inc()
    with assert_raises(ApptuitSendException):
        reporter.report_now()
    successful_points_sent = reporter._meta_metrics_registry. \
        counter(NUMBER_OF_SUCCESSFUL_POINTS).get_count()
    failed_points_count = reporter._meta_metrics_registry. \
        counter(NUMBER_OF_FAILED_POINTS).get_count()
    assert_equals(successful_points_sent, 98)
    assert_equals(failed_points_count, 2)