示例#1
0
def test_tastypie_api_operation_name_fail_no_wrapper(tracked_requests):
    with app_with_scout() as app:
        skip_if_no_tastypie()
        url = "/tastypie-api/v1/user/"
        view_func = resolve(url).func
        with delete_attributes(view_func, "__wrapped__"):
            response = TestApp(app).get(url, {"format": "json"})

    assert response.status_int == 200
    span = tracked_requests[0].complete_spans[-2]
    assert span.operation == "Controller/tastypie.resources.wrapper"
示例#2
0
def test_request_no_absolute_url(caplog, tracked_request):
    ensure_installed()
    delete_absolute_url = delete_attributes(urllib3.HTTPConnectionPool,
                                            "_absolute_url")
    with httpretty.enabled(allow_net_connect=False), delete_absolute_url:
        httpretty.register_uri(httpretty.GET,
                               "https://example.com/",
                               body="Hello World!")

        http = urllib3.PoolManager()
        response = http.request("GET", "https://example.com")

    assert response.status == 200
    assert response.data == b"Hello World!"
    assert len(tracked_request.complete_spans) == 1
    span = tracked_request.complete_spans[0]
    assert span.operation == "HTTP/GET"
    assert span.tags["url"] == "Unknown"
示例#3
0
def test_ensure_installed_fail_no_client_bulk(caplog):
    mock_not_patched = mock.patch(
        "scout_apm.instruments.elasticsearch.have_patched_client", new=False)
    mock_no_bulk = delete_attributes(elasticsearch.Elasticsearch, "bulk")
    with mock_not_patched, mock_no_bulk:
        ensure_installed()

    assert len(caplog.record_tuples) == 2
    assert caplog.record_tuples[0] == (
        "scout_apm.instruments.elasticsearch",
        logging.DEBUG,
        "Instrumenting elasticsearch.",
    )
    logger, level, message = caplog.record_tuples[1]
    assert logger == "scout_apm.instruments.elasticsearch"
    assert level == logging.WARNING
    assert message.startswith(
        "Failed to instrument elasticsearch.Elasticsearch.bulk: AttributeError"
    )