<s> import boto <EOL> from boto . ec2 . cloudwatch . alarm import MetricAlarm <EOL> import sure <EOL> from moto import mock_cloudwatch <EOL> def alarm_fixture ( name = "<STR_LIT>" , action = None ) : <EOL> action = action or [ '<STR_LIT>' ] <EOL> return MetricAlarm ( <EOL> name = name , <EOL> comparison = '<STR_LIT>' , <EOL> threshold = <NUM_LIT> , <EOL> period = <NUM_LIT> , <EOL> evaluation_periods = <NUM_LIT:5> , <EOL> statistic = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> dimensions = { '<STR_LIT>' : [ '<STR_LIT>' ] } , <EOL> alarm_actions = action , <EOL> ok_actions = [ '<STR_LIT>' ] , <EOL> insufficient_data_actions = [ '<STR_LIT>' ] , <EOL> unit = '<STR_LIT>' , <EOL> ) <EOL> @ mock_cloudwatch <EOL> def test_create_alarm ( ) : <EOL> conn = boto . connect_cloudwatch ( ) <EOL> alarm = alarm_fixture ( ) <EOL> conn . create_alarm ( alarm ) <EOL> alarms = conn . describe_alarms ( ) <EOL> alarms . should . have . length_of ( <NUM_LIT:1> ) <EOL> alarm = alarms [ <NUM_LIT:0> ] <EOL> alarm . name . should . equal ( '<STR_LIT>' ) <EOL> alarm . comparison . should . equal ( '<STR_LIT>' ) <EOL> alarm . threshold . should . equal ( <NUM_LIT> ) <EOL> alarm . period . should . equal ( <NUM_LIT> ) <EOL> alarm . evaluation_periods . should . equal ( <NUM_LIT:5> ) <EOL> alarm . statistic . should . equal ( '<STR_LIT>' ) <EOL> alarm . description . should . equal ( '<STR_LIT>' ) <EOL> dict ( alarm . dimensions ) . should . equal ( { '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> list ( alarm . alarm_actions ) . should . equal ( [ '<STR_LIT>' ] ) <EOL> list ( alarm . ok_actions ) . should . equal ( [ '<STR_LIT>' ] ) <EOL> list ( alarm . insufficient_data_actions ) . should . equal ( [ '<STR_LIT>' ] ) <EOL> alarm . unit . should . equal ( '<STR_LIT>' ) <EOL> @ mock_cloudwatch <EOL> def test_delete_alarm ( ) : <EOL> conn = boto . connect_cloudwatch ( ) <EOL> alarms = conn . describe_alarms ( ) <EOL> alarms . should . have . length_of ( <NUM_LIT:0> ) <EOL> alarm = alarm_fixture ( ) <EOL> conn . create_alarm ( alarm ) <EOL> alarms = conn . describe_alarms ( ) <EOL> alarms . should . have . length_of ( <NUM_LIT:1> ) <EOL> alarms [ <NUM_LIT:0> ] . delete ( ) <EOL> alarms = conn . describe_alarms ( ) <EOL> alarms . should . have . length_of ( <NUM_LIT:0> ) <EOL> @ mock_cloudwatch <EOL> def test_put_metric_data ( ) : <EOL> conn = boto . connect_cloudwatch ( ) <EOL> conn . put_metric_data ( <EOL> namespace = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> value = <NUM_LIT> , <EOL> dimensions = { '<STR_LIT>' : [ '<STR_LIT>' ] } , <EOL> ) <EOL> metrics = conn . list_metrics ( ) <EOL> metrics . should . have . length_of ( <NUM_LIT:1> ) <EOL> metric = metrics [ <NUM_LIT:0> ] <EOL> metric . namespace . should . equal ( '<STR_LIT>' ) <EOL> metric . name . should . equal ( '<STR_LIT>' ) <EOL> dict ( metric . dimensions ) . should . equal ( { '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> @ mock_cloudwatch <EOL> def test_describe_alarms ( ) : <EOL> conn = boto . connect_cloudwatch ( ) <EOL> alarms = conn . describe_alarms ( ) <EOL> alarms . should . have . length_of ( <NUM_LIT:0> ) <EOL> conn . create_alarm ( alarm_fixture ( name = "<STR_LIT>" , action = "<STR_LIT>" ) ) <EOL> conn . create_alarm ( alarm_fixture ( name = "<STR_LIT>" , action = "<STR_LIT>" ) ) <EOL> conn . create_alarm ( alarm_fixture ( name = "<STR_LIT>" , action = "<STR_LIT>" ) ) <EOL> conn . create_alarm ( alarm_fixture ( name = "<STR_LIT>" , action = "<STR_LIT>" ) ) <EOL> alarms = conn . describe_alarms ( ) <EOL> alarms . should . have . length_of ( <NUM_LIT:4> ) <EOL> alarms = conn . describe_alarms ( alarm_name_prefix = "<STR_LIT>" ) <EOL> alarms . should . have . length_of ( <NUM_LIT:2> ) <EOL> alarms = conn . describe_alarms ( alarm_names = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> alarms . should . have . length_of ( <NUM_LIT:3> ) <EOL> alarms = conn . describe_alarms ( action_prefix = "<STR_LIT>" ) <EOL> alarms . should . have . length_of ( <NUM_LIT:2> ) <EOL> for alarm in conn . describe_alarms ( ) : <EOL> alarm . delete ( ) <EOL> alarms = conn . describe_alarms ( ) <EOL> alarms . should . have . length_of ( <NUM_LIT:0> ) <EOL> @ mock_cloudwatch <EOL> def test_describe_state_value_unimplemented ( ) : <EOL> conn = boto . connect_cloudwatch ( ) <EOL> conn . describe_alarms ( ) <EOL> conn . describe_alarms . when . called_with ( state_value = "<STR_LIT:foo>" ) . should . throw ( NotImplementedError ) </s>
