def test_selfupdate(self): """ Test for Composer selfupdate """ mock = MagicMock(return_value=False) with patch.object(composer, "_valid_composer", mock): self.assertRaises(CommandNotFoundError, composer.selfupdate) mock = MagicMock(return_value=True) with patch.object(composer, "_valid_composer", mock): mock = MagicMock(return_value={"retcode": 1, "stderr": "A"}) with patch.dict(composer.__salt__, {"cmd.run_all": mock}): self.assertRaises(CommandExecutionError, composer.selfupdate) mock = MagicMock(return_value=True) with patch.object(composer, "_valid_composer", mock): mock = MagicMock(return_value={"retcode": 0, "stderr": "A"}) with patch.dict(composer.__salt__, {"cmd.run_all": mock}): self.assertTrue(composer.selfupdate(quiet=True)) mock = MagicMock(return_value=True) with patch.object(composer, "_valid_composer", mock): rval = {"retcode": 0, "stderr": "A", "stdout": "B"} mock = MagicMock(return_value=rval) with patch.dict(composer.__salt__, {"cmd.run_all": mock}): self.assertEqual(composer.selfupdate(), rval)
def test_selfupdate(self): ''' Test for Composer selfupdate ''' mock = MagicMock(return_value=False) with patch.object(composer, '_valid_composer', mock): self.assertRaises(CommandNotFoundError, composer.selfupdate) mock = MagicMock(return_value=True) with patch.object(composer, '_valid_composer', mock): mock = MagicMock(return_value={'retcode': 1, 'stderr': 'A'}) with patch.dict(composer.__salt__, {'cmd.run_all': mock}): self.assertRaises(CommandExecutionError, composer.selfupdate) mock = MagicMock(return_value=True) with patch.object(composer, '_valid_composer', mock): mock = MagicMock(return_value={'retcode': 0, 'stderr': 'A'}) with patch.dict(composer.__salt__, {'cmd.run_all': mock}): self.assertTrue(composer.selfupdate(quiet=True)) mock = MagicMock(return_value=True) with patch.object(composer, '_valid_composer', mock): rval = {'retcode': 0, 'stderr': 'A', 'stdout': 'B'} mock = MagicMock(return_value=rval) with patch.dict(composer.__salt__, {'cmd.run_all': mock}): self.assertEqual(composer.selfupdate(), rval)
def test_selfupdate(self): """ Test for Composer selfupdate """ mock = MagicMock(return_value=False) with patch.object(composer, "_valid_composer", mock): self.assertRaises(CommandNotFoundError, composer.selfupdate) mock = MagicMock(return_value=True) with patch.object(composer, "_valid_composer", mock): mock = MagicMock(return_value={"retcode": 1, "stderr": "A"}) with patch.dict(composer.__salt__, {"cmd.run_all": mock}): self.assertRaises(CommandExecutionError, composer.selfupdate) mock = MagicMock(return_value=True) with patch.object(composer, "_valid_composer", mock): mock = MagicMock(return_value={"retcode": 0, "stderr": "A"}) with patch.dict(composer.__salt__, {"cmd.run_all": mock}): self.assertTrue(composer.selfupdate(quiet=True)) mock = MagicMock(return_value=True) with patch.object(composer, "_valid_composer", mock): rval = {"retcode": 0, "stderr": "A", "stdout": "B"} mock = MagicMock(return_value=rval) with patch.dict(composer.__salt__, {"cmd.run_all": mock}): self.assertEqual(composer.selfupdate(), rval)