From f7ce1c73fe2f904a3ec0f790ebbb7f02fe4e7b5a Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Tue, 21 Sep 2021 20:58:46 +0000 Subject: [PATCH] CloudWatch - duplicate deprecated tests (#3853) --- tests/test_cloudwatch/test_cloudwatch.py | 6 ++ .../test_cloudwatch/test_cloudwatch_boto3.py | 83 ++++++++++++++++++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/tests/test_cloudwatch/test_cloudwatch.py b/tests/test_cloudwatch/test_cloudwatch.py index eb042c0e0..7fe002bcc 100644 --- a/tests/test_cloudwatch/test_cloudwatch.py +++ b/tests/test_cloudwatch/test_cloudwatch.py @@ -29,6 +29,7 @@ def alarm_fixture(name="tester", action=None): ) +# Has boto3 equivalent @mock_cloudwatch_deprecated def test_create_alarm(): conn = boto.connect_cloudwatch() @@ -56,6 +57,7 @@ def test_create_alarm(): assert "tester" in alarm.alarm_arn +# Has boto3 equivalent @mock_cloudwatch_deprecated def test_delete_alarm(): conn = boto.connect_cloudwatch() @@ -75,6 +77,7 @@ def test_delete_alarm(): alarms.should.have.length_of(0) +# Has boto3 equivalent @mock_cloudwatch_deprecated def test_put_metric_data(): conn = boto.connect_cloudwatch() @@ -95,6 +98,7 @@ def test_put_metric_data(): dict(metric.dimensions).should.equal({"InstanceId": ["i-0123456,i-0123457"]}) +# Has boto3 equivalent @mock_cloudwatch_deprecated def test_describe_alarms(): conn = boto.connect_cloudwatch() @@ -130,6 +134,7 @@ def test_describe_alarms(): alarms.should.have.length_of(0) +# Has boto3 equivalent @mock_cloudwatch_deprecated def test_describe_alarms_for_metric(): conn = boto.connect_cloudwatch() @@ -146,6 +151,7 @@ def test_describe_alarms_for_metric(): alarms.should.have.length_of(1) +# Has boto3 equivalent @mock_cloudwatch_deprecated def test_get_metric_statistics(): conn = boto.connect_cloudwatch() diff --git a/tests/test_cloudwatch/test_cloudwatch_boto3.py b/tests/test_cloudwatch/test_cloudwatch_boto3.py index 1fc197094..147b6e5a2 100644 --- a/tests/test_cloudwatch/test_cloudwatch_boto3.py +++ b/tests/test_cloudwatch/test_cloudwatch_boto3.py @@ -92,7 +92,88 @@ def test_get_dashboard_fail(): except ClientError as err: err.response["Error"]["Code"].should.equal("ResourceNotFound") else: - raise RuntimeError("Should of raised error") + raise RuntimeError("Should have raised error") + + +@mock_cloudwatch +def test_create_alarm(): + region = "eu-west-1" + cloudwatch = boto3.client("cloudwatch", region) + + name = "tester" + cloudwatch.put_metric_alarm( + AlarmActions=["arn:alarm"], + AlarmDescription="A test", + AlarmName=name, + ComparisonOperator="GreaterThanOrEqualToThreshold", + Dimensions=[{"Name": "InstanceId", "Value": "i-0123457"}], + EvaluationPeriods=5, + InsufficientDataActions=["arn:insufficient"], + Namespace="{0}_namespace".format(name), + MetricName="{0}_metric".format(name), + OKActions=["arn:ok"], + Period=60, + Statistic="Average", + Threshold=2, + Unit="Seconds", + ) + + alarms = cloudwatch.describe_alarms()["MetricAlarms"] + alarms.should.have.length_of(1) + alarm = alarms[0] + alarm.should.have.key("AlarmName").equal("tester") + alarm.should.have.key("Namespace").equal("tester_namespace") + alarm.should.have.key("MetricName").equal("tester_metric") + alarm.should.have.key("ComparisonOperator").equal("GreaterThanOrEqualToThreshold") + alarm.should.have.key("Threshold").equal(2.0) + alarm.should.have.key("Period").equal(60) + alarm.should.have.key("EvaluationPeriods").equal(5) + alarm.should.have.key("Statistic").should.equal("Average") + alarm.should.have.key("AlarmDescription").equal("A test") + alarm.should.have.key("Dimensions").equal( + [{"Name": "InstanceId", "Value": "i-0123457"}] + ) + alarm.should.have.key("AlarmActions").equal(["arn:alarm"]) + alarm.should.have.key("OKActions").equal(["arn:ok"]) + alarm.should.have.key("InsufficientDataActions").equal(["arn:insufficient"]) + alarm.should.have.key("Unit").equal("Seconds") + alarm.should.have.key("AlarmArn").equal( + "arn:aws:cloudwatch:{}:{}:alarm:{}".format(region, ACCOUNT_ID, name) + ) + + +@mock_cloudwatch +def test_delete_alarm(): + cloudwatch = boto3.client("cloudwatch", region_name="eu-central-1") + + alarms = cloudwatch.describe_alarms()["MetricAlarms"] + alarms.should.have.length_of(0) + + name = "tester" + cloudwatch.put_metric_alarm( + AlarmActions=["arn:alarm"], + AlarmDescription="A test", + AlarmName=name, + ComparisonOperator="GreaterThanOrEqualToThreshold", + Dimensions=[{"Name": "InstanceId", "Value": "i-0123457"}], + EvaluationPeriods=5, + InsufficientDataActions=["arn:insufficient"], + Namespace="{0}_namespace".format(name), + MetricName="{0}_metric".format(name), + OKActions=["arn:ok"], + Period=60, + Statistic="Average", + Threshold=2, + Unit="Seconds", + ) + + alarms = cloudwatch.describe_alarms()["MetricAlarms"] + alarms.should.have.length_of(1) + + cloudwatch.delete_alarms(AlarmNames=[name]) + + alarms = cloudwatch.describe_alarms()["MetricAlarms"] + alarms.should.have.length_of(0) @mock_cloudwatch