def test_tastypie_api_operation_name_fail_no_tastypie(tracked_requests):
    with app_with_scout() as app:
        skip_if_no_tastypie()
        with pretend_package_unavailable("tastypie"):
            response = TestApp(app).get("/tastypie-api/v1/user/", {"format": "json"})

    assert response.status_int == 200
    span = tracked_requests[0].complete_spans[-2]
    assert span.operation == "Controller/tastypie.resources.wrapper"
def test_report_app_metadata_no_pkg_resources(send):
    with pretend_package_unavailable("pkg_resources"):
        report_app_metadata()

    assert send.call_count == 1
    (command, ), kwargs = send.call_args
    assert kwargs == {}

    message = command.message()
    assert message["ApplicationEvent"]["event_type"] == "scout.metadata"
    assert message["ApplicationEvent"]["event_value"]["libraries"] == []
def test_report_app_metadata_no_importlib_metadata(mock_send):
    if sys.version_info >= (3, 8):
        module_name = "importlib"
    else:
        module_name = "importlib_metadata"
    with pretend_package_unavailable(module_name):
        report_app_metadata()

    assert mock_send.call_count == 1
    (command,), kwargs = mock_send.call_args
    assert kwargs == {}

    message = command.message()
    assert message["ApplicationEvent"]["event_type"] == "scout.metadata"
    assert message["ApplicationEvent"]["event_value"]["libraries"] == []
def test_error_monitor_tastypie_request_components_fail_no_tastypie(
    tracked_requests, error_monitor_errors
):
    with app_with_scout(DEBUG_PROPAGATE_EXCEPTIONS=False) as app:
        skip_if_no_tastypie()
        with pretend_package_unavailable("tastypie"):
            response = TestApp(app).get(
                "/tastypie-api/v1/crash/1/", {"format": "json"}, expect_errors=True
            )

    assert response.status_int == 500
    assert len(error_monitor_errors) == 1
    error = error_monitor_errors[0]
    assert error["request_components"] == {
        "module": "tastypie.resources",
        "controller": "wrapper",
        "action": "GET",
    }