def test_volume_absent(self): ''' Test to check that a block volume exists. ''' name = 'mycloud' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(return_value=False) mock_lst = MagicMock(side_effect=[[], [name], [name]]) with patch.dict(cloud.__salt__, { 'cloud.volume_list': mock_lst, 'cloud.volume_delete': mock }): with patch.object(salt.utils.cloud, 'check_name', MagicMock(return_value=True)): comt = ('Invalid characters in name.') ret.update({'comment': comt}) self.assertDictEqual(cloud.volume_absent(name), ret) comt = ('Volume is absent.') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(cloud.volume_absent(name), ret) with patch.dict(cloud.__opts__, {'test': True}): comt = ('Volume {0} will be deleted.'.format(name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual(cloud.volume_absent(name), ret) with patch.dict(cloud.__opts__, {'test': False}): comt = ('Volume {0} failed to delete.'.format(name)) ret.update({'comment': comt, 'result': False}) self.assertDictEqual(cloud.volume_absent(name), ret)
def test_volume_absent(): """ Test to check that a block volume exists. """ name = "mycloud" ret = {"name": name, "result": False, "changes": {}, "comment": ""} mock = MagicMock(return_value=False) mock_lst = MagicMock(side_effect=[[], [name], [name]]) with patch.dict(cloud.__salt__, { "cloud.volume_list": mock_lst, "cloud.volume_delete": mock }): with patch.object(salt.utils.cloud, "check_name", MagicMock(return_value=True)): comt = "Invalid characters in name." ret.update({"comment": comt}) assert cloud.volume_absent(name) == ret comt = "Volume is absent." ret.update({"comment": comt, "result": True}) assert cloud.volume_absent(name) == ret with patch.dict(cloud.__opts__, {"test": True}): comt = "Volume {} will be deleted.".format(name) ret.update({"comment": comt, "result": None}) assert cloud.volume_absent(name) == ret with patch.dict(cloud.__opts__, {"test": False}): comt = "Volume {} failed to delete.".format(name) ret.update({"comment": comt, "result": False}) assert cloud.volume_absent(name) == ret
def test_volume_absent(self): ''' Test to check that a block volume exists. ''' name = 'mycloud' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(return_value=False) mock_lst = MagicMock(side_effect=[[], [name], [name]]) with patch.dict(cloud.__salt__, {'cloud.volume_list': mock_lst, 'cloud.volume_delete': mock}): with patch.object(salt.utils.cloud, 'check_name', MagicMock(return_value=True)): comt = ('Invalid characters in name.') ret.update({'comment': comt}) self.assertDictEqual(cloud.volume_absent(name), ret) comt = ('Volume is absent.') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(cloud.volume_absent(name), ret) with patch.dict(cloud.__opts__, {'test': True}): comt = ('Volume {0} will be deleted.'.format(name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual(cloud.volume_absent(name), ret) with patch.dict(cloud.__opts__, {'test': False}): comt = ('Volume {0} failed to delete.'.format(name)) ret.update({'comment': comt, 'result': False}) self.assertDictEqual(cloud.volume_absent(name), ret)