def test_absent(self): ''' Test to verify that the specified ruby is not installed with rbenv. ''' name = 'myqueue' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[False, True]) mock_def = MagicMock(return_value='2.7') mock_ver = MagicMock(return_value=['2.7']) with patch.dict( rbenv.__salt__, { 'rbenv.is_installed': mock, 'rbenv.default': mock_def, 'rbenv.versions': mock_ver }): with patch.dict(rbenv.__opts__, {'test': True}): comt = ('Ruby myqueue is set to be uninstalled') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(rbenv.absent(name), ret) with patch.dict(rbenv.__opts__, {'test': False}): comt = ('Rbenv not installed, myqueue not either') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(rbenv.absent(name), ret) comt = ('Ruby myqueue is already absent') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(rbenv.absent(name), ret)
def test_absent(self): ''' Test to verify that the specified ruby is not installed with rbenv. ''' name = 'myqueue' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[False, True]) mock_def = MagicMock(return_value='2.7') mock_ver = MagicMock(return_value=['2.7']) with patch.dict(rbenv.__salt__, {'rbenv.is_installed': mock, 'rbenv.default': mock_def, 'rbenv.versions': mock_ver}): with patch.dict(rbenv.__opts__, {'test': True}): comt = ('Ruby myqueue is set to be uninstalled') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(rbenv.absent(name), ret) with patch.dict(rbenv.__opts__, {'test': False}): comt = ('Rbenv not installed, myqueue not either') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(rbenv.absent(name), ret) comt = ('Ruby myqueue is already absent') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(rbenv.absent(name), ret)
def test_absent(self): ''' Test to verify that the specified ruby is not installed with rbenv. ''' # rbenv.is_installed is used for all tests here. mock_is = MagicMock(side_effect=[ False, True, True, True, False, True, True, True, True, True ]) # rbenv.uninstall_ruby is only called when an action is # attempted (ie. Successfully... or Failed...) mock_uninstalled = MagicMock(side_effect=[True, False, False, True]) mock_def = MagicMock(return_value='2.3.4') mock_ver = MagicMock(return_value=['2.3.4', '2.4.1']) with patch.dict( rbenv.__salt__, { 'rbenv.is_installed': mock_is, 'rbenv.default': mock_def, 'rbenv.versions': mock_ver, 'rbenv.uninstall_ruby': mock_uninstalled }): with patch.dict(rbenv.__opts__, {'test': True}): name = '1.9.3-p551' comt = 'Rbenv not installed, {0} not either'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'result': True } self.assertDictEqual(rbenv.absent(name), ret) comt = 'Ruby {0} is already uninstalled'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'result': True } self.assertDictEqual(rbenv.absent(name), ret) name = '2.3.4' comt = 'Ruby {0} is set to be uninstalled'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'default': True, 'result': None } self.assertDictEqual(rbenv.absent('2.3.4'), ret) name = '2.4.1' comt = 'Ruby {0} is set to be uninstalled'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'default': False, 'result': None } self.assertDictEqual(rbenv.absent('2.4.1'), ret) with patch.dict(rbenv.__opts__, {'test': False}): name = '1.9.3-p551' comt = 'Rbenv not installed, {0} not either'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'result': True } self.assertDictEqual(rbenv.absent(name), ret) comt = 'Ruby {0} is already absent'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'result': True } self.assertDictEqual(rbenv.absent(name), ret) name = '2.3.4' comt = 'Successfully removed ruby' ret = { 'name': name, 'changes': { name: 'Uninstalled' }, 'comment': comt, 'default': True, 'result': True } self.assertDictEqual(rbenv.absent(name), ret) comt = 'Failed to uninstall ruby' ret = { 'name': name, 'changes': {}, 'comment': comt, 'default': True, 'result': False } self.assertDictEqual(rbenv.absent(name), ret) name = '2.4.1' comt = 'Failed to uninstall ruby' ret = { 'name': name, 'changes': {}, 'comment': comt, 'default': False, 'result': False } self.assertDictEqual(rbenv.absent(name), ret) comt = 'Successfully removed ruby' ret = { 'name': name, 'changes': { name: 'Uninstalled' }, 'comment': comt, 'default': False, 'result': True } self.assertDictEqual(rbenv.absent(name), ret)
def test_absent(self): """ Test to verify that the specified ruby is not installed with rbenv. """ # rbenv.is_installed is used for all tests here. mock_is = MagicMock(side_effect=[ False, True, True, True, False, True, True, True, True, True ]) # rbenv.uninstall_ruby is only called when an action is # attempted (ie. Successfully... or Failed...) mock_uninstalled = MagicMock(side_effect=[True, False, False, True]) mock_def = MagicMock(return_value="2.3.4") mock_ver = MagicMock(return_value=["2.3.4", "2.4.1"]) with patch.dict( rbenv.__salt__, { "rbenv.is_installed": mock_is, "rbenv.default": mock_def, "rbenv.versions": mock_ver, "rbenv.uninstall_ruby": mock_uninstalled, }, ): with patch.dict(rbenv.__opts__, {"test": True}): name = "1.9.3-p551" comt = "Rbenv not installed, {0} not either".format(name) ret = { "name": name, "changes": {}, "comment": comt, "result": True } self.assertDictEqual(rbenv.absent(name), ret) comt = "Ruby {0} is already uninstalled".format(name) ret = { "name": name, "changes": {}, "comment": comt, "result": True } self.assertDictEqual(rbenv.absent(name), ret) name = "2.3.4" comt = "Ruby {0} is set to be uninstalled".format(name) ret = { "name": name, "changes": {}, "comment": comt, "default": True, "result": None, } self.assertDictEqual(rbenv.absent("2.3.4"), ret) name = "2.4.1" comt = "Ruby {0} is set to be uninstalled".format(name) ret = { "name": name, "changes": {}, "comment": comt, "default": False, "result": None, } self.assertDictEqual(rbenv.absent("2.4.1"), ret) with patch.dict(rbenv.__opts__, {"test": False}): name = "1.9.3-p551" comt = "Rbenv not installed, {0} not either".format(name) ret = { "name": name, "changes": {}, "comment": comt, "result": True } self.assertDictEqual(rbenv.absent(name), ret) comt = "Ruby {0} is already absent".format(name) ret = { "name": name, "changes": {}, "comment": comt, "result": True } self.assertDictEqual(rbenv.absent(name), ret) name = "2.3.4" comt = "Successfully removed ruby" ret = { "name": name, "changes": { name: "Uninstalled" }, "comment": comt, "default": True, "result": True, } self.assertDictEqual(rbenv.absent(name), ret) comt = "Failed to uninstall ruby" ret = { "name": name, "changes": {}, "comment": comt, "default": True, "result": False, } self.assertDictEqual(rbenv.absent(name), ret) name = "2.4.1" comt = "Failed to uninstall ruby" ret = { "name": name, "changes": {}, "comment": comt, "default": False, "result": False, } self.assertDictEqual(rbenv.absent(name), ret) comt = "Successfully removed ruby" ret = { "name": name, "changes": { name: "Uninstalled" }, "comment": comt, "default": False, "result": True, } self.assertDictEqual(rbenv.absent(name), ret)