def test_control_db_utilization_enable(self, mock_execute_recover_machine): mock_execute_recover_machine.return_value = True my_alarm = { "detail": { "state": { "value": "OK", } } } for stage in STAGES: os.environ['STAGE'] = stage handler.control_db_utilization(my_alarm, self.context) mock_execute_recover_machine.assert_called_with({}, {}) os.environ['STAGE'] = 'UNKNOWN' with self.assertRaises(Exception) as context: handler.control_db_utilization(self.initial_event, self.context)
def test_control_db_utilization_disable(self, mock_disable_triggers): mock_disable_triggers.return_value = True my_alarm = { "detail": { "state": { "value": "ALARM", } } } for stage in STAGES: os.environ['STAGE'] = stage handler.control_db_utilization(my_alarm, self.context) mock_disable_triggers.assert_called_with(TRIGGER[stage]) os.environ['STAGE'] = 'UNKNOWN' with self.assertRaises(Exception) as context: handler.control_db_utilization(self.initial_event, self.context)
def test_control_db_utilization_dont_enable_triggers_when_db_off(self, mock_enable_triggers, mock_describe_db_clusters): mock_enable_triggers.return_value = True my_alarm = { "detail": { "state": { "value": "OK", } } } for stage in STAGES: os.environ['STAGE'] = stage mock_describe_db_clusters.return_value = "SomebodyElsesDb" handler.control_db_utilization(my_alarm, self.context) mock_enable_triggers.assert_not_called() os.environ['STAGE'] = 'UNKNOWN' with self.assertRaises(Exception) as context: handler.control_db_utilization(self.initial_event, self.context)
def test_control_db_utilization_enable_lambda_trigger_when_db_on( self, mock_enable_lambda_trigger, mock_describe_db_clusters): mock_enable_lambda_trigger.return_value = True my_alarm = { "detail": { "state": { "value": "OK", } } } for stage in STAGES: os.environ['STAGE'] = stage mock_describe_db_clusters.return_value = DB[stage] handler.control_db_utilization(my_alarm, self.context) mock_enable_lambda_trigger.assert_called_with( my_alarm, self.context) os.environ['STAGE'] = 'UNKNOWN' with self.assertRaises(Exception) as context: handler.control_db_utilization(self.initial_event, self.context)