@@ -1266,7 +1266,7 @@ def lambda_handler(evt, ctx):
1266
1266
assert invocation ["_aws" ]["Timestamp" ] == metric_timestamp
1267
1267
1268
1268
1269
- def test_metric_with_wrong_custom_timestamp (namespace , metric ):
1269
+ def test_metric_custom_timestamp_more_than_14days_ago (namespace , metric ):
1270
1270
# GIVEN Metrics instance is initialized
1271
1271
my_metrics = Metrics (namespace = namespace )
1272
1272
@@ -1288,3 +1288,27 @@ def lambda_handler(evt, ctx):
1288
1288
"This metric doesn't meet the requirements and will be skipped by Amazon CloudWatch. "
1289
1289
"Ensure the timestamp is within 14 days past or 2 hours future."
1290
1290
)
1291
+
1292
+
1293
+ def test_metric_custom_timestamp_with_wrong_type (namespace , metric ):
1294
+ # GIVEN Metrics instance is initialized
1295
+ my_metrics = Metrics (namespace = namespace )
1296
+
1297
+ # Setting timestamp outside of contraints with 20 days before
1298
+ metric_timestamp = "timestamp_as_string"
1299
+
1300
+ # WHEN we set a wrong timestamp before to flush the metric
1301
+ @my_metrics .log_metrics
1302
+ def lambda_handler (evt , ctx ):
1303
+ my_metrics .add_metric (** metric )
1304
+ my_metrics .set_timestamp (metric_timestamp )
1305
+
1306
+ # THEN should raise a warning
1307
+ with warnings .catch_warnings (record = True ) as w :
1308
+ warnings .simplefilter ("default" )
1309
+ lambda_handler ({}, {})
1310
+ assert len (w ) == 1
1311
+ assert str (w [- 1 ].message ) == (
1312
+ "This metric doesn't meet the requirements and will be skipped by Amazon CloudWatch. "
1313
+ "Ensure the timestamp is within 14 days past or 2 hours future."
1314
+ )
0 commit comments