def test_present(self): """ Test to ensure the cloudwatch alarm exists. """ name = "my test alarm" attributes = { "metric": "ApproximateNumberOfMessagesVisible", "namespace": "AWS/SQS", } ret = {"name": name, "result": None, "changes": {}, "comment": ""} mock = MagicMock(side_effect=[["ok_actions"], [], []]) mock_bool = MagicMock(return_value=True) with patch.dict( boto_cloudwatch_alarm.__salt__, { "boto_cloudwatch.get_alarm": mock, "boto_cloudwatch.create_or_update_alarm": mock_bool, }, ): with patch.dict(boto_cloudwatch_alarm.__opts__, {"test": True}): comt = "alarm my test alarm is to be created/updated." ret.update({"comment": comt}) self.assertDictEqual( boto_cloudwatch_alarm.present(name, attributes), ret) comt = "alarm my test alarm is to be created/updated." ret.update({"comment": comt}) self.assertDictEqual( boto_cloudwatch_alarm.present(name, attributes), ret) with patch.dict(boto_cloudwatch_alarm.__opts__, {"test": False}): changes = { "new": { "metric": "ApproximateNumberOfMessagesVisible", "namespace": "AWS/SQS", } } comt = "alarm my test alarm is to be created/updated." ret.update({"changes": changes, "comment": "", "result": True}) self.assertDictEqual( boto_cloudwatch_alarm.present(name, attributes), ret)
def test_present(self): ''' Test to ensure the cloudwatch alarm exists. ''' name = 'my test alarm' attributes = { 'metric': 'ApproximateNumberOfMessagesVisible', 'namespace': 'AWS/SQS' } ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[['ok_actions'], [], []]) mock_bool = MagicMock(return_value=True) with patch.dict( boto_cloudwatch_alarm.__salt__, { 'boto_cloudwatch.get_alarm': mock, 'boto_cloudwatch.create_or_update_alarm': mock_bool }): with patch.dict(boto_cloudwatch_alarm.__opts__, {'test': True}): comt = ('alarm my test alarm is to be created/updated.') ret.update({'comment': comt}) self.assertDictEqual( boto_cloudwatch_alarm.present(name, attributes), ret) comt = ('alarm my test alarm is to be created/updated.') ret.update({'comment': comt}) self.assertDictEqual( boto_cloudwatch_alarm.present(name, attributes), ret) with patch.dict(boto_cloudwatch_alarm.__opts__, {'test': False}): changes = { 'new': { 'metric': 'ApproximateNumberOfMessagesVisible', 'namespace': 'AWS/SQS' } } comt = ('alarm my test alarm is to be created/updated.') ret.update({'changes': changes, 'comment': '', 'result': True}) self.assertDictEqual( boto_cloudwatch_alarm.present(name, attributes), ret)
def test_present(self): ''' Test to ensure the cloudwatch alarm exists. ''' name = 'my test alarm' attributes = {'metric': 'ApproximateNumberOfMessagesVisible', 'namespace': 'AWS/SQS'} ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[['ok_actions'], [], []]) mock_bool = MagicMock(return_value=True) with patch.dict(boto_cloudwatch_alarm.__salt__, {'boto_cloudwatch.get_alarm': mock, 'boto_cloudwatch.create_or_update_alarm': mock_bool}): with patch.dict(boto_cloudwatch_alarm.__opts__, {'test': True}): comt = ('alarm my test alarm is to be created/updated.') ret.update({'comment': comt}) self.assertDictEqual(boto_cloudwatch_alarm.present(name, attributes), ret) comt = ('alarm my test alarm is to be created/updated.') ret.update({'comment': comt}) self.assertDictEqual(boto_cloudwatch_alarm.present(name, attributes), ret) with patch.dict(boto_cloudwatch_alarm.__opts__, {'test': False}): changes = {'new': {'metric': 'ApproximateNumberOfMessagesVisible', 'namespace': 'AWS/SQS'}} comt = ('alarm my test alarm is to be created/updated.') ret.update({'changes': changes, 'comment': '', 'result': True}) self.assertDictEqual(boto_cloudwatch_alarm.present(name, attributes), ret)