def test_present(self): ''' Test to ensure the SQS queue exists. ''' name = 'mysqs' attributes = {'DelaySeconds': 20} base_ret = {'name': name, 'changes': {}} mock = MagicMock( side_effect=[{'result': b} for b in [False, False, True, True]], ) mock_bool = MagicMock(return_value={'error': 'create error'}) mock_attr = MagicMock(return_value={'result': {}}) with patch.dict(boto_sqs.__salt__, {'boto_sqs.exists': mock, 'boto_sqs.create': mock_bool, 'boto_sqs.get_attributes': mock_attr}): with patch.dict(boto_sqs.__opts__, {'test': False}): comt = ['Failed to create SQS queue {0}: create error'.format( name, )] ret = base_ret.copy() ret.update({'result': False, 'comment': comt}) self.assertDictEqual(boto_sqs.present(name), ret) with patch.dict(boto_sqs.__opts__, {'test': True}): comt = ['SQS queue {0} is set to be created.'.format(name)] ret = base_ret.copy() ret.update({ 'result': None, 'comment': comt, 'pchanges': {'old': None, 'new': 'mysqs'}, }) self.assertDictEqual(boto_sqs.present(name), ret) diff = textwrap.dedent('''\ --- +++ @@ -1 +1 @@ -{} +DelaySeconds: 20 ''') comt = [ 'SQS queue mysqs present.', 'Attribute(s) DelaySeconds set to be updated:\n{0}'.format( diff, ), ] ret.update({ 'comment': comt, 'pchanges': {'attributes': {'diff': diff}}, }) self.assertDictEqual(boto_sqs.present(name, attributes), ret) comt = ['SQS queue mysqs present.'] ret = base_ret.copy() ret.update({'result': True, 'comment': comt}) self.assertDictEqual(boto_sqs.present(name), ret)
def test_present(self): ''' Test to ensure the SQS queue exists. ''' name = 'mysqs' attributes = {'ReceiveMessageWaitTimeSeconds': 20} ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[False, False, True, True]) mock_bool = MagicMock(return_value=False) mock_attr = MagicMock(return_value={}) with patch.dict(boto_sqs.__salt__, {'boto_sqs.exists': mock, 'boto_sqs.create': mock_bool, 'boto_sqs.get_attributes': mock_attr}): with patch.dict(boto_sqs.__opts__, {'test': False}): comt = ('Failed to create {0} AWS queue'.format(name)) ret.update({'comment': comt}) self.assertDictEqual(boto_sqs.present(name), ret) with patch.dict(boto_sqs.__opts__, {'test': True}): comt = ('AWS SQS queue {0} is set to be created.'.format(name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual(boto_sqs.present(name), ret) comt = ('Attribute(s) ReceiveMessageWaitTimeSeconds' ' to be set on mysqs.') ret.update({'comment': comt}) self.assertDictEqual(boto_sqs.present(name, attributes), ret) comt = ('mysqs present. Attributes set.') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(boto_sqs.present(name), ret)
def test_present(self): ''' Test to ensure the SQS queue exists. ''' name = 'mysqs' attributes = {'ReceiveMessageWaitTimeSeconds': 20} ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[False, False, True, True]) mock_bool = MagicMock(return_value=False) mock_attr = MagicMock(return_value={}) with patch.dict( boto_sqs.__salt__, { 'boto_sqs.exists': mock, 'boto_sqs.create': mock_bool, 'boto_sqs.get_attributes': mock_attr }): with patch.dict(boto_sqs.__opts__, {'test': False}): comt = ('Failed to create {0} AWS queue'.format(name)) ret.update({'comment': comt}) self.assertDictEqual(boto_sqs.present(name), ret) with patch.dict(boto_sqs.__opts__, {'test': True}): comt = ('AWS SQS queue {0} is set to be created.'.format(name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual(boto_sqs.present(name), ret) comt = ('Attribute(s) ReceiveMessageWaitTimeSeconds' ' to be set on mysqs.') ret.update({'comment': comt}) self.assertDictEqual(boto_sqs.present(name, attributes), ret) comt = ('mysqs present. Attributes set.') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(boto_sqs.present(name), ret)
def test_present(self): ''' Test to ensure the SQS queue exists. ''' name = 'mysqs' attributes = {'DelaySeconds': 20} base_ret = {'name': name, 'changes': {}} mock = MagicMock( side_effect=[{'result': b} for b in [False, False, True, True]], ) mock_bool = MagicMock(return_value={'error': 'create error'}) mock_attr = MagicMock(return_value={'result': {}}) with patch.dict(boto_sqs.__salt__, {'boto_sqs.exists': mock, 'boto_sqs.create': mock_bool, 'boto_sqs.get_attributes': mock_attr}): with patch.dict(boto_sqs.__opts__, {'test': False}): comt = ['Failed to create SQS queue {0}: create error'.format( name, )] ret = base_ret.copy() ret.update({'result': False, 'comment': comt}) self.assertDictEqual(boto_sqs.present(name), ret) with patch.dict(boto_sqs.__opts__, {'test': True}): comt = ['SQS queue {0} is set to be created.'.format(name)] ret = base_ret.copy() ret.update({ 'result': None, 'comment': comt, 'pchanges': {'old': None, 'new': 'mysqs'}, }) self.assertDictEqual(boto_sqs.present(name), ret) diff = textwrap.dedent('''\ --- +++ @@ -1 +1 @@ -{} +DelaySeconds: 20 ''').splitlines() # Difflib adds a trailing space after the +++/--- lines, # programatically add them back here. Having them in the test # file itself is not feasible since a few popular plugins for # vim will remove trailing whitespace. for idx in (0, 1): diff[idx] += ' ' diff = '\n'.join(diff) comt = [ 'SQS queue mysqs present.', 'Attribute(s) DelaySeconds set to be updated:\n{0}'.format( diff, ), ] ret.update({ 'comment': comt, 'pchanges': {'attributes': {'diff': diff}}, }) self.assertDictEqual(boto_sqs.present(name, attributes), ret) comt = ['SQS queue mysqs present.'] ret = base_ret.copy() ret.update({'result': True, 'comment': comt}) self.assertDictEqual(boto_sqs.present(name), ret)
def test_present(self): """ Test to ensure the SQS queue exists. """ name = "mysqs" attributes = {"DelaySeconds": 20} base_ret = {"name": name, "changes": {}} mock = MagicMock(side_effect=[{ "result": b } for b in [False, False, True, True]], ) mock_bool = MagicMock(return_value={"error": "create error"}) mock_attr = MagicMock(return_value={"result": {}}) with patch.dict( boto_sqs.__salt__, { "boto_sqs.exists": mock, "boto_sqs.create": mock_bool, "boto_sqs.get_attributes": mock_attr, }, ): with patch.dict(boto_sqs.__opts__, {"test": False}): comt = [ "Failed to create SQS queue {0}: create error".format( name, ) ] ret = base_ret.copy() ret.update({"result": False, "comment": comt}) self.assertDictEqual(boto_sqs.present(name), ret) with patch.dict(boto_sqs.__opts__, {"test": True}): comt = ["SQS queue {0} is set to be created.".format(name)] ret = base_ret.copy() ret.update({ "result": None, "comment": comt, "changes": { "old": None, "new": "mysqs" }, }) self.assertDictEqual(boto_sqs.present(name), ret) diff = textwrap.dedent("""\ --- +++ @@ -1 +1 @@ -{} +DelaySeconds: 20 """).splitlines() # Difflib adds a trailing space after the +++/--- lines, # programatically add them back here. Having them in the test # file itself is not feasible since a few popular plugins for # vim will remove trailing whitespace. for idx in (0, 1): diff[idx] += " " diff = "\n".join(diff) comt = [ "SQS queue mysqs present.", "Attribute(s) DelaySeconds set to be updated:\n{0}".format( diff, ), ] ret.update({ "comment": comt, "changes": { "attributes": { "diff": diff } } }) self.assertDictEqual(boto_sqs.present(name, attributes), ret) comt = ["SQS queue mysqs present."] ret = base_ret.copy() ret.update({"result": True, "comment": comt}) self.assertDictEqual(boto_sqs.present(name), ret)
def test_present(): """ Test to ensure the SQS queue exists. """ name = "mysqs" attributes = {"DelaySeconds": 20} base_ret = {"name": name, "changes": {}} mock = MagicMock(side_effect=[{ "result": b } for b in [False, False, True, True]], ) mock_bool = MagicMock(return_value={"error": "create error"}) mock_attr = MagicMock(return_value={"result": {}}) with patch.dict( boto_sqs.__salt__, { "boto_sqs.exists": mock, "boto_sqs.create": mock_bool, "boto_sqs.get_attributes": mock_attr, }, ): with patch.dict(boto_sqs.__opts__, {"test": False}): comt = [ "Failed to create SQS queue {}: create error".format(name, ) ] ret = base_ret.copy() ret.update({"result": False, "comment": comt}) assert boto_sqs.present(name) == ret with patch.dict(boto_sqs.__opts__, {"test": True}): comt = ["SQS queue {} is set to be created.".format(name)] ret = base_ret.copy() ret.update({ "result": None, "comment": comt, "changes": { "old": None, "new": "mysqs" }, }) assert boto_sqs.present(name) == ret diff = textwrap.dedent("""\ --- +++ @@ -1 +1 @@ -{} +DelaySeconds: 20 """).splitlines() for idx in (0, 1): diff[idx] += " " diff = "\n".join(diff) comt = [ "SQS queue mysqs present.", "Attribute(s) DelaySeconds set to be updated:\n{}".format( diff, ), ] ret.update({ "comment": comt, "changes": { "attributes": { "diff": diff } } }) assert boto_sqs.present(name, attributes) == ret comt = ["SQS queue mysqs present."] ret = base_ret.copy() ret.update({"result": True, "comment": comt}) assert boto_sqs.present(name) == ret