Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/agent_features/test_lambda_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Context(object):
memory_limit_in_mb = 128


# The lambda_hander has been deprecated for 3+ years
@pytest.mark.skip(reason="The lambda_handler has been deprecated")
@pytest.mark.parametrize("is_cold", (False, True))
def test_lambda_transaction_attributes(is_cold, monkeypatch):
# setup copies of the attribute lists for this test only
Expand Down Expand Up @@ -139,6 +141,8 @@ def _test():
_test()


# The lambda_hander has been deprecated for 3+ years
@pytest.mark.skip(reason="The lambda_handler has been deprecated")
@validate_transaction_trace_attributes(_expected_attributes)
@validate_transaction_event_attributes(_expected_attributes)
@override_application_settings(_override_settings)
Expand Down Expand Up @@ -193,6 +197,8 @@ def test_lambda_malformed_request_headers():
}


# The lambda_hander has been deprecated for 3+ years
@pytest.mark.skip(reason="The lambda_handler has been deprecated")
@validate_transaction_trace_attributes(_malformed_response_attributes)
@validate_transaction_event_attributes(_malformed_response_attributes)
@override_application_settings(_override_settings)
Expand Down Expand Up @@ -229,6 +235,8 @@ def handler(event, context):
}


# The lambda_hander has been deprecated for 3+ years
@pytest.mark.skip(reason="The lambda_handler has been deprecated")
@validate_transaction_trace_attributes(_no_status_code_response)
@validate_transaction_event_attributes(_no_status_code_response)
@override_application_settings(_override_settings)
Expand All @@ -253,6 +261,8 @@ def handler(event, context):
)


# The lambda_hander has been deprecated for 3+ years
@pytest.mark.skip(reason="The lambda_handler has been deprecated")
@pytest.mark.parametrize("event,arn", ((empty_event, None), (firehose_event, "arn:aws:kinesis:EXAMPLE")))
def test_lambda_event_source_arn_attribute(event, arn):
if arn is None:
Expand Down Expand Up @@ -285,6 +295,8 @@ def _test():
_test()


# The lambda_hander has been deprecated for 3+ years
@pytest.mark.skip(reason="The lambda_handler has been deprecated")
@pytest.mark.parametrize(
"api",
(
Expand Down
2 changes: 2 additions & 0 deletions tests/agent_features/test_serverless_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def _test_inbound_dt_payload_acceptance():
_test_inbound_dt_payload_acceptance()


# The lambda_hander has been deprecated for 3+ years
@pytest.mark.skip(reason="The lambda_handler has been deprecated")
@pytest.mark.parametrize("arn_set", (True, False))
def test_payload_metadata_arn(serverless_application, arn_set):
# If the session object gathers the arn from the settings object before the
Expand Down
51 changes: 28 additions & 23 deletions tests/cross_agent/test_lambda_event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,65 +14,70 @@

import json
import os

import pytest
from testing_support.fixtures import override_application_settings
from testing_support.validators.validate_transaction_event_attributes import (
validate_transaction_event_attributes,
)

from newrelic.api.lambda_handler import lambda_handler
from testing_support.fixtures import override_application_settings
from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes

CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
FIXTURE_DIR = os.path.normpath(os.path.join(CURRENT_DIR, 'fixtures'))
FIXTURE = os.path.join(FIXTURE_DIR, 'lambda_event_source.json')
FIXTURE_DIR = os.path.normpath(os.path.join(CURRENT_DIR, "fixtures"))
FIXTURE = os.path.join(FIXTURE_DIR, "lambda_event_source.json")
tests = {}
events = {}


def _load_tests():
with open(FIXTURE, 'r') as fh:
with open(FIXTURE, "r") as fh:
for test in json.loads(fh.read()):
test_name = test.pop('name')
test_name = test.pop("name")

test_file = test_name + '.json'
path = os.path.join(FIXTURE_DIR, 'lambda_event_source', test_file)
with open(path, 'r') as fh:
test_file = test_name + ".json"
path = os.path.join(FIXTURE_DIR, "lambda_event_source", test_file)
with open(path, "r") as fh:
events[test_name] = json.loads(fh.read())

tests[test_name] = test
return tests.keys()


class Context(object):
aws_request_id = 'cookies'
invoked_function_arn = 'arn'
function_name = 'cats'
function_version = '$LATEST'
aws_request_id = "cookies"
invoked_function_arn = "arn"
function_name = "cats"
function_version = "$LATEST"
memory_limit_in_mb = 128


@lambda_handler()
def handler(event, context):
return {
'statusCode': '200',
'body': '{}',
'headers': {
'Content-Type': 'application/json',
'Content-Length': 2,
"statusCode": "200",
"body": "{}",
"headers": {
"Content-Type": "application/json",
"Content-Length": 2,
},
}


@pytest.mark.parametrize('test_name', _load_tests())
# The lambda_hander has been deprecated for 3+ years
@pytest.mark.skip(reason="The lambda_handler has been deprecated")
@pytest.mark.parametrize("test_name", _load_tests())
def test_lambda_event_source(test_name):
_exact = {'user': {}, 'intrinsic': {}, 'agent': {}}
_exact = {"user": {}, "intrinsic": {}, "agent": {}}

expected_arn = tests[test_name].get('aws.lambda.eventSource.arn', None)
expected_arn = tests[test_name].get("aws.lambda.eventSource.arn", None)
if expected_arn:
_exact['agent']['aws.lambda.eventSource.arn'] = expected_arn
_exact["agent"]["aws.lambda.eventSource.arn"] = expected_arn
else:
pytest.skip("Nothing to test!")
return

@override_application_settings({'attributes.include': ['aws.*']})
@override_application_settings({"attributes.include": ["aws.*"]})
@validate_transaction_event_attributes({}, exact_attrs=_exact)
def _test():
handler(events[test_name], Context)
Expand Down
3 changes: 2 additions & 1 deletion tests/external_boto3/test_boto3_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple

MOTO_VERSION = tuple(int(v) for v in moto.__version__.split(".")[:3])
MOTO_VERSION = get_package_version_tuple("moto")

# patch earlier versions of moto to support py37
if sys.version_info >= (3, 7) and MOTO_VERSION <= (1, 3, 1):
Expand Down
3 changes: 2 additions & 1 deletion tests/external_boto3/test_boto3_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple

MOTO_VERSION = tuple(int(v) for v in moto.__version__.split(".")[:3])
MOTO_VERSION = get_package_version_tuple("moto")

# patch earlier versions of moto to support py37
if sys.version_info >= (3, 7) and MOTO_VERSION <= (1, 3, 1):
Expand Down
3 changes: 2 additions & 1 deletion tests/external_boto3/test_boto3_sns.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple

MOTO_VERSION = tuple(int(v) for v in moto.__version__.split(".")[:3])
MOTO_VERSION = get_package_version_tuple("moto")

# patch earlier versions of moto to support py37
if sys.version_info >= (3, 7) and MOTO_VERSION <= (1, 3, 1):
Expand Down
5 changes: 3 additions & 2 deletions tests/external_botocore/test_botocore_dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple

MOTO_VERSION = tuple(int(v) for v in moto.__version__.split(".")[:3])
MOTO_VERSION = get_package_version_tuple("moto")

# patch earlier versions of moto to support py37
if sys.version_info >= (3, 7) and MOTO_VERSION <= (1, 3, 1):
Expand Down Expand Up @@ -80,7 +81,7 @@
background_task=True,
)
@background_task()
@moto.mock_dynamodb2
@moto.mock_dynamodb
def test_dynamodb():
session = botocore.session.get_session()
client = session.create_client(
Expand Down
3 changes: 2 additions & 1 deletion tests/external_botocore/test_botocore_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple

MOTO_VERSION = tuple(int(v) for v in moto.__version__.split(".")[:3])
MOTO_VERSION = get_package_version_tuple("moto")

# patch earlier versions of moto to support py37
if sys.version_info >= (3, 7) and MOTO_VERSION <= (1, 3, 1):
Expand Down
5 changes: 3 additions & 2 deletions tests/external_botocore/test_botocore_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple

MOTO_VERSION = tuple(int(v) for v in moto.__version__.split(".")[:3])
BOTOCORE_VERSION = tuple(int(v) for v in botocore.__version__.split(".")[:3])
MOTO_VERSION = MOTO_VERSION = get_package_version_tuple("moto")
BOTOCORE_VERSION = get_package_version_tuple("botocore")


# patch earlier versions of moto to support py37
Expand Down
9 changes: 5 additions & 4 deletions tests/external_botocore/test_botocore_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version
from newrelic.common.package_version_utils import get_package_version_tuple

MOTO_VERSION = tuple(int(v) for v in moto.__version__.split(".")[:3])
MOTO_VERSION = get_package_version_tuple("moto")
BOTOCORE_VERSION = get_package_version_tuple("botocore")

# patch earlier versions of moto to support py37
if sys.version_info >= (3, 7) and MOTO_VERSION <= (1, 3, 1):
Expand All @@ -36,8 +37,8 @@
moto.packages.responses.responses.re._pattern_type = re.Pattern

url = "sqs.us-east-1.amazonaws.com"
botocore_version = tuple([int(n) for n in get_package_version("botocore").split(".")])
if botocore_version < (1, 29, 0):

if BOTOCORE_VERSION < (1, 29, 0):
url = "queue.amazonaws.com"

AWS_ACCESS_KEY_ID = "AAAAAAAAAAAACCESSKEY"
Expand Down
14 changes: 10 additions & 4 deletions tests/external_requests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
from testing_support.validators.validate_external_node_params import (
validate_external_node_params,
)
from testing_support.validators.validate_transaction_errors import validate_transaction_errors
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
from testing_support.validators.validate_transaction_errors import (
validate_transaction_errors,
)
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple


def get_requests_version():
return tuple(map(int, requests.__version__.split(".")[:2]))
return get_package_version_tuple("requests")


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -89,7 +95,7 @@ def test_https_request_get(server, metrics):
@background_task(name="test_requests:test_https_request_get")
def _test():
try:
requests.get("https://localhost:%d/" % server.port, verify=False)
requests.get("https://localhost:%d/" % server.port, verify=False) # nosec
except Exception:
pass

Expand Down
18 changes: 10 additions & 8 deletions tests/external_urllib3/test_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@
cache_outgoing_headers,
insert_incoming_headers,
)
from testing_support.fixtures import (
cat_enabled,
override_application_settings,
)
from testing_support.util import version2tuple
from testing_support.fixtures import cat_enabled, override_application_settings
from testing_support.validators.validate_cross_process_headers import (
validate_cross_process_headers,
)
from testing_support.validators.validate_external_node_params import (
validate_external_node_params,
)
from testing_support.validators.validate_transaction_errors import validate_transaction_errors
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
from testing_support.validators.validate_transaction_errors import (
validate_transaction_errors,
)
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)

from newrelic.api.background_task import background_task
from newrelic.common.package_version_utils import get_package_version_tuple


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -185,7 +187,7 @@ def _test():
# HTTPConnection class. Previously the httplib/http.client HTTPConnection class
# was used. We test httplib in a different test directory so we skip this test.
@pytest.mark.skipif(
version2tuple(urllib3.__version__) < (1, 8), reason="urllib3.connection.HTTPConnection added in 1.8"
get_package_version_tuple("urllib3") < (1, 8), reason="urllib3.connection.HTTPConnection added in 1.8"
)
def test_HTTPConnection_port_included(server):
scoped = [("External/localhost:%d/urllib3/" % server.port, 1)]
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ deps =
external_botocore-botocorelatest: botocore
external_botocore-botocore128: botocore<1.29
external_botocore-botocore0125: botocore<1.26
external_botocore-{py37,py38,py39,py310,py311}: moto[awslambda,ec2,iam]<3.0
external_botocore-{py37,py38,py39,py310,py311}: moto[awslambda,ec2,iam]
external_botocore-py27: rsa<4.7.1
external_botocore-py27: moto[awslambda,ec2,iam]<2.0
external_feedparser-feedparser05: feedparser<6
Expand Down