def test_installed(self): ''' Test to verify that the specified ruby is installed with rbenv. ''' name = 'rbenv-deps' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock_t = MagicMock(side_effect=[False, True, True]) mock_f = MagicMock(return_value=False) mock_def = MagicMock(return_value='2.7') mock_ver = MagicMock(return_value=['2.7']) with patch.dict(rbenv.__salt__, {'rbenv.is_installed': mock_f, 'rbenv.install': mock_t, 'rbenv.default': mock_def, 'rbenv.versions': mock_ver, 'rbenv.install_ruby': mock_t}): with patch.dict(rbenv.__opts__, {'test': True}): comt = ('Ruby rbenv-deps is set to be installed') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(rbenv.installed(name), ret) with patch.dict(rbenv.__opts__, {'test': False}): comt = ('Rbenv failed to install') ret.update({'comment': comt, 'result': False}) self.assertDictEqual(rbenv.installed(name), ret) comt = ('Successfully installed ruby') ret.update({'comment': comt, 'result': True, 'default': False, 'changes': {name: 'Installed'}}) self.assertDictEqual(rbenv.installed(name), ret)
def test_installed(self): ''' Test to verify that the specified ruby is installed with rbenv. ''' name = 'rbenv-deps' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock_t = MagicMock(side_effect=[False, True, True]) mock_f = MagicMock(return_value=False) mock_def = MagicMock(return_value='2.7') mock_ver = MagicMock(return_value=['2.7']) with patch.dict( rbenv.__salt__, { 'rbenv.is_installed': mock_f, 'rbenv.install': mock_t, 'rbenv.default': mock_def, 'rbenv.versions': mock_ver, 'rbenv.install_ruby': mock_t }): with patch.dict(rbenv.__opts__, {'test': True}): comt = ('Ruby rbenv-deps is set to be installed') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(rbenv.installed(name), ret) with patch.dict(rbenv.__opts__, {'test': False}): comt = ('Rbenv failed to install') ret.update({'comment': comt, 'result': False}) self.assertDictEqual(rbenv.installed(name), ret) comt = ('Successfully installed ruby') ret.update({ 'comment': comt, 'result': True, 'default': False, 'changes': { name: 'Installed' } }) self.assertDictEqual(rbenv.installed(name), ret)
def test_installed(self): ''' Test to verify that the specified ruby is installed with rbenv. ''' # rbenv.is_installed is used wherever test is False. mock_is = MagicMock(side_effect=[False, True, True, True, True]) # rbenv.install is only called when an action is attempted # (ie. Successfully... or Failed...) mock_i = MagicMock(side_effect=[False, False, False]) # rbenv.install_ruby is only called when rbenv is successfully # installed and an attempt to install a version of Ruby is # made. mock_ir = MagicMock(side_effect=[True, False]) 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.install': mock_i, 'rbenv.default': mock_def, 'rbenv.versions': mock_ver, 'rbenv.install_ruby': mock_ir }): with patch.dict(rbenv.__opts__, {'test': True}): name = '1.9.3-p551' comt = 'Ruby {0} is set to be installed'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'result': None } self.assertDictEqual(rbenv.installed(name), ret) name = '2.4.1' comt = 'Ruby {0} is already installed'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'default': False, 'result': True } self.assertDictEqual(rbenv.installed(name), ret) name = '2.3.4' comt = 'Ruby {0} is already installed'.format(name) ret = { 'name': name, 'changes': {}, 'comment': comt, 'default': True, 'result': True } self.assertDictEqual(rbenv.installed(name), ret) with patch.dict(rbenv.__opts__, {'test': False}): name = '2.4.1' comt = 'Rbenv failed to install' ret = { 'name': name, 'changes': {}, 'comment': comt, 'result': False } self.assertDictEqual(rbenv.installed(name), ret) comt = 'Requested ruby exists' ret = { 'name': name, 'comment': comt, 'default': False, 'changes': {}, 'result': True } self.assertDictEqual(rbenv.installed(name), ret) name = '2.3.4' comt = 'Requested ruby exists' ret = { 'name': name, 'comment': comt, 'default': True, 'changes': {}, 'result': True } self.assertDictEqual(rbenv.installed(name), ret) name = '1.9.3-p551' comt = 'Successfully installed ruby' ret = { 'name': name, 'comment': comt, 'default': False, 'changes': { name: 'Installed' }, 'result': True } self.assertDictEqual(rbenv.installed(name), ret) comt = 'Failed to install ruby' ret = { 'name': name, 'comment': comt, 'changes': {}, 'result': False } self.assertDictEqual(rbenv.installed(name), ret)
def test_installed(self): """ Test to verify that the specified ruby is installed with rbenv. """ # rbenv.is_installed is used wherever test is False. mock_is = MagicMock(side_effect=[False, True, True, True, True]) # rbenv.install is only called when an action is attempted # (ie. Successfully... or Failed...) mock_i = MagicMock(side_effect=[False, False, False]) # rbenv.install_ruby is only called when rbenv is successfully # installed and an attempt to install a version of Ruby is # made. mock_ir = MagicMock(side_effect=[True, False]) 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.install": mock_i, "rbenv.default": mock_def, "rbenv.versions": mock_ver, "rbenv.install_ruby": mock_ir, }, ): with patch.dict(rbenv.__opts__, {"test": True}): name = "1.9.3-p551" comt = "Ruby {0} is set to be installed".format(name) ret = { "name": name, "changes": {}, "comment": comt, "result": None } self.assertDictEqual(rbenv.installed(name), ret) name = "2.4.1" comt = "Ruby {0} is already installed".format(name) ret = { "name": name, "changes": {}, "comment": comt, "default": False, "result": True, } self.assertDictEqual(rbenv.installed(name), ret) name = "2.3.4" comt = "Ruby {0} is already installed".format(name) ret = { "name": name, "changes": {}, "comment": comt, "default": True, "result": True, } self.assertDictEqual(rbenv.installed(name), ret) with patch.dict(rbenv.__opts__, {"test": False}): name = "2.4.1" comt = "Rbenv failed to install" ret = { "name": name, "changes": {}, "comment": comt, "result": False } self.assertDictEqual(rbenv.installed(name), ret) comt = "Requested ruby exists" ret = { "name": name, "comment": comt, "default": False, "changes": {}, "result": True, } self.assertDictEqual(rbenv.installed(name), ret) name = "2.3.4" comt = "Requested ruby exists" ret = { "name": name, "comment": comt, "default": True, "changes": {}, "result": True, } self.assertDictEqual(rbenv.installed(name), ret) name = "1.9.3-p551" comt = "Successfully installed ruby" ret = { "name": name, "comment": comt, "default": False, "changes": { name: "Installed" }, "result": True, } self.assertDictEqual(rbenv.installed(name), ret) comt = "Failed to install ruby" ret = { "name": name, "comment": comt, "changes": {}, "result": False } self.assertDictEqual(rbenv.installed(name), ret)