@@ -1183,12 +1183,20 @@ def test_add_new_relic_with_ingest_key(aws_credentials, mock_function_config):
11831183 )
11841184
11851185 # Verify ingest key is used for NEW_RELIC_LICENSE_KEY
1186- assert update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_LICENSE_KEY" ] == "test-ingest-key-12345"
1187- assert update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_LAMBDA_EXTENSION_ENABLED" ] == "true"
1186+ assert (
1187+ update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_LICENSE_KEY" ]
1188+ == "test-ingest-key-12345"
1189+ )
1190+ assert (
1191+ update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_LAMBDA_EXTENSION_ENABLED" ]
1192+ == "true"
1193+ )
11881194
11891195
11901196@mock_aws
1191- def test_add_new_relic_without_license_key_or_ingest_key (aws_credentials , mock_function_config ):
1197+ def test_add_new_relic_without_license_key_or_ingest_key (
1198+ aws_credentials , mock_function_config
1199+ ):
11921200 """Test _add_new_relic function when neither license key nor ingest key is provided"""
11931201 session = boto3 .Session (region_name = "us-east-1" )
11941202
@@ -1206,11 +1214,14 @@ def test_add_new_relic_without_license_key_or_ingest_key(aws_credentials, mock_f
12061214 )
12071215
12081216 # When no license key or ingest key is provided, extension should be disabled
1209- assert update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_LAMBDA_EXTENSION_ENABLED" ] == "false"
1217+ assert (
1218+ update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_LAMBDA_EXTENSION_ENABLED" ]
1219+ == "false"
1220+ )
12101221 assert "NEW_RELIC_LICENSE_KEY" not in update_kwargs ["Environment" ]["Variables" ]
12111222
12121223
1213- @mock_aws
1224+ @mock_aws
12141225def test_add_new_relic_staging_region (aws_credentials , mock_function_config ):
12151226 """Test _add_new_relic function with staging region"""
12161227 session = boto3 .Session (region_name = "us-east-1" )
@@ -1231,24 +1242,35 @@ def test_add_new_relic_staging_region(aws_credentials, mock_function_config):
12311242 )
12321243
12331244 # Verify staging endpoints are set
1234- assert update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_TELEMETRY_ENDPOINT" ] == "https://staging-cloud-collector.newrelic.com/aws/lambda/v1"
1235- assert update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_LOG_ENDPOINT" ] == "https://staging-log-api.newrelic.com/log/v1"
1245+ assert (
1246+ update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_TELEMETRY_ENDPOINT" ]
1247+ == "https://staging-cloud-collector.newrelic.com/aws/lambda/v1"
1248+ )
1249+ assert (
1250+ update_kwargs ["Environment" ]["Variables" ]["NEW_RELIC_LOG_ENDPOINT" ]
1251+ == "https://staging-log-api.newrelic.com/log/v1"
1252+ )
12361253
12371254
1238- def test_install_with_both_api_key_and_ingest_key (aws_credentials , mock_function_config ):
1255+ def test_install_with_both_api_key_and_ingest_key (
1256+ aws_credentials , mock_function_config
1257+ ):
12391258 """Test install function fails when both API key and ingest key are provided"""
12401259 mock_session = MagicMock ()
12411260 mock_session .region_name = "us-east-1"
1242-
1243- with pytest .raises (UsageError , match = "Please provide either the --nr-api-key or the --nr-ingest-key flag, but not both" ):
1261+
1262+ with pytest .raises (
1263+ UsageError ,
1264+ match = "Please provide either the --nr-api-key or the --nr-ingest-key flag, but not both" ,
1265+ ):
12441266 install (
12451267 layer_install (
12461268 session = mock_session ,
12471269 nr_account_id = 12345 ,
12481270 nr_api_key = "test-api-key" ,
1249- nr_ingest_key = "test-ingest-key"
1271+ nr_ingest_key = "test-ingest-key" ,
12501272 ),
1251- "test-function"
1273+ "test-function" ,
12521274 )
12531275
12541276
@@ -1257,36 +1279,40 @@ def test_install_with_ingest_key_success(aws_credentials, mock_function_config):
12571279 mock_session = MagicMock ()
12581280 mock_session .region_name = "us-east-1"
12591281 mock_client = mock_session .client .return_value
1260-
1261- with patch ("newrelic_lambda_cli.layers._get_license_key_outputs" ) as mock_get_license_key_outputs , \
1262- patch ("newrelic_lambda_cli.layers.get_function" ) as mock_get_function , \
1263- patch ("newrelic_lambda_cli.layers._add_new_relic" ) as mock_add_new_relic :
1264-
1282+
1283+ with patch (
1284+ "newrelic_lambda_cli.layers._get_license_key_outputs"
1285+ ) as mock_get_license_key_outputs , patch (
1286+ "newrelic_lambda_cli.layers.get_function"
1287+ ) as mock_get_function , patch (
1288+ "newrelic_lambda_cli.layers._add_new_relic"
1289+ ) as mock_add_new_relic :
1290+
12651291 # Set up policy_arn so GraphQL validation is skipped
12661292 mock_get_license_key_outputs .return_value = (None , "12345" , "test-policy-arn" )
12671293 mock_get_function .return_value = mock_function_config ("python3.12" )
12681294 mock_add_new_relic .return_value = {
12691295 "FunctionName" : "test-function" ,
12701296 "Environment" : {"Variables" : {"NEW_RELIC_LICENSE_KEY" : "test-ingest-key" }},
1271- "Layers" : ["test-layer" ]
1297+ "Layers" : ["test-layer" ],
12721298 }
12731299 mock_client .update_function_configuration .return_value = {
12741300 "Configuration" : {
12751301 "Layers" : [{"Arn" : "existing-layer" }],
1276- "FunctionArn" : "test-function"
1302+ "FunctionArn" : "test-function" ,
12771303 }
12781304 }
1279-
1305+
12801306 result = install (
12811307 layer_install (
12821308 session = mock_session ,
12831309 nr_account_id = 12345 ,
12841310 nr_ingest_key = "test-ingest-key" ,
12851311 enable_extension = False ,
12861312 ),
1287- "test-function"
1313+ "test-function" ,
12881314 )
1289-
1315+
12901316 assert result is True
12911317 mock_client .update_function_configuration .assert_called_once ()
12921318
@@ -1297,26 +1323,27 @@ def test_install_with_apm_and_verbose(aws_credentials, mock_function_config):
12971323 mock_session = MagicMock ()
12981324 mock_session .region_name = "us-east-1"
12991325 mock_client = mock_session .client .return_value
1300-
1301- with patch ("newrelic_lambda_cli.layers._get_license_key_outputs" ) as mock_get_license_key_outputs , \
1302- patch ("newrelic_lambda_cli.layers.get_function" ) as mock_get_function , \
1303- patch ("newrelic_lambda_cli.layers._add_new_relic" ) as mock_add_new_relic :
1304-
1326+
1327+ with patch (
1328+ "newrelic_lambda_cli.layers._get_license_key_outputs"
1329+ ) as mock_get_license_key_outputs , patch (
1330+ "newrelic_lambda_cli.layers.get_function"
1331+ ) as mock_get_function , patch (
1332+ "newrelic_lambda_cli.layers._add_new_relic"
1333+ ) as mock_add_new_relic :
1334+
13051335 mock_get_license_key_outputs .return_value = (None , "12345" , "test-policy-arn" )
13061336 mock_get_function .return_value = mock_function_config ("python3.12" )
13071337 mock_add_new_relic .return_value = {
13081338 "FunctionName" : "test-function" ,
13091339 "Environment" : {"Variables" : {"NEW_RELIC_LICENSE_KEY" : "test-key" }},
1310- "Layers" : ["test-layer" ]
1340+ "Layers" : ["test-layer" ],
13111341 }
13121342 mock_client .update_function_configuration .return_value = {
1313- "Configuration" : {
1314- "Layers" : [],
1315- "FunctionArn" : "test-function"
1316- }
1343+ "Configuration" : {"Layers" : [], "FunctionArn" : "test-function" }
13171344 }
13181345 mock_client .tag_resource .return_value = {}
1319-
1346+
13201347 result = install (
13211348 layer_install (
13221349 session = mock_session ,
@@ -1327,9 +1354,9 @@ def test_install_with_apm_and_verbose(aws_credentials, mock_function_config):
13271354 verbose = True ,
13281355 enable_extension = False ,
13291356 ),
1330- "test-function"
1357+ "test-function" ,
13311358 )
1332-
1359+
13331360 assert result is True
13341361 mock_client .tag_resource .assert_called_once ()
13351362
@@ -1339,56 +1366,62 @@ def test_install_function_not_found(aws_credentials):
13391366 """Test install function when function is not found"""
13401367 mock_session = MagicMock ()
13411368 mock_session .region_name = "us-east-1"
1342-
1369+
13431370 with patch ("newrelic_lambda_cli.layers.get_function" ) as mock_get_function :
13441371 mock_get_function .return_value = None
1345-
1372+
13461373 result = install (
13471374 layer_install (
13481375 session = mock_session ,
13491376 nr_account_id = 12345 ,
13501377 nr_api_key = "test-api-key" ,
13511378 ),
1352- "nonexistent-function"
1379+ "nonexistent-function" ,
13531380 )
1354-
1381+
13551382 assert result is False
13561383
13571384
13581385def test_install_secret_account_mismatch (aws_credentials ):
13591386 """Test install with managed secret account ID mismatch"""
13601387 mock_session = MagicMock ()
13611388 mock_session .region_name = "us-east-1"
1362-
1363- with patch ("newrelic_lambda_cli.layers._get_license_key_outputs" ) as mock_get_license_key_outputs , \
1364- patch ("newrelic_lambda_cli.layers.get_function" ) as mock_get_function :
1365-
1389+
1390+ with patch (
1391+ "newrelic_lambda_cli.layers._get_license_key_outputs"
1392+ ) as mock_get_license_key_outputs , patch (
1393+ "newrelic_lambda_cli.layers.get_function"
1394+ ) as mock_get_function :
1395+
13661396 # Different account ID in existing secret
13671397 mock_get_license_key_outputs .return_value = (None , "99999" , "test-policy-arn" )
13681398 mock_get_function .return_value = {"Configuration" : {"FunctionArn" : "test" }}
1369-
1399+
13701400 with pytest .raises (UsageError , match = "A managed secret already exists" ):
13711401 install (
13721402 layer_install (
13731403 session = mock_session ,
13741404 nr_account_id = 12345 , # Different from secret account ID
13751405 nr_ingest_key = "test-ingest-key" ,
13761406 ),
1377- "test-function"
1407+ "test-function" ,
13781408 )
13791409
13801410
13811411def test_install_extension_without_secret_or_api_key (aws_credentials ):
13821412 """Test install with extension enabled but no secret or API key"""
13831413 mock_session = MagicMock ()
13841414 mock_session .region_name = "us-east-1"
1385-
1386- with patch ("newrelic_lambda_cli.layers._get_license_key_outputs" ) as mock_get_license_key_outputs , \
1387- patch ("newrelic_lambda_cli.layers.get_function" ) as mock_get_function :
1388-
1415+
1416+ with patch (
1417+ "newrelic_lambda_cli.layers._get_license_key_outputs"
1418+ ) as mock_get_license_key_outputs , patch (
1419+ "newrelic_lambda_cli.layers.get_function"
1420+ ) as mock_get_function :
1421+
13891422 mock_get_license_key_outputs .return_value = (None , None , None ) # No secret
13901423 mock_get_function .return_value = {"Configuration" : {"FunctionArn" : "test" }}
1391-
1424+
13921425 with pytest .raises (UsageError , match = "In order to use `--enable-extension`" ):
13931426 install (
13941427 layer_install (
@@ -1397,5 +1430,5 @@ def test_install_extension_without_secret_or_api_key(aws_credentials):
13971430 enable_extension = True ,
13981431 nr_ingest_key = "test-ingest-key" ,
13991432 ),
1400- "test-function"
1433+ "test-function" ,
14011434 )
0 commit comments