def test__find_chocolatey_context(choco_path): """ Test _find_chocolatey when it exists in __context__ """ with patch.dict(chocolatey.__context__, {"chocolatey._path": choco_path}): result = chocolatey._find_chocolatey() expected = choco_path assert result == expected
def test__find_chocolatey_context(self): ''' Test _find_chocolatey when it exists in __context__ ''' with patch.dict(chocolatey.__context__, {'chocolatey._path': self.choco_path}): result = chocolatey._find_chocolatey() expected = self.choco_path self.assertEqual(result, expected)
def setUp(self): """ Ensure that Chocolatey is installed """ self._chocolatey_bin = choco._find_chocolatey() if "ERROR" in self._chocolatey_bin: # self.fail("Chocolatey is not installed") self.run_function("chocolatey.bootstrap") super(ChocolateyModuleTest, self).setUp()
def test__find_chocolatey_systemdrive(mock_false, choco_path_sd): """ Test _find_chocolatey when found on SystemDrive (older versions) """ with patch.dict(chocolatey.__salt__, {"cmd.which": mock_false}), patch( "os.path.isfile", MagicMock(side_effect=[False, True])): result = chocolatey._find_chocolatey() expected = choco_path_sd # Does it return the correct path assert result == expected # Does it populate __context__ assert chocolatey.__context__["chocolatey._path"] == expected
def test__find_chocolatey_which(choco_path): """ Test _find_chocolatey when found with `cmd.which` """ mock_which = MagicMock(return_value=choco_path) with patch.dict(chocolatey.__salt__, {"cmd.which": mock_which}): result = chocolatey._find_chocolatey() expected = choco_path # Does it return the correct path assert result == expected # Does it populate __context__ assert chocolatey.__context__["chocolatey._path"] == expected
def test__find_chocolatey_programdata(mock_false, mock_true, choco_path_pd): """ Test _find_chocolatey when found in ProgramData """ with patch.dict(chocolatey.__salt__, {"cmd.which": mock_false}), patch("os.path.isfile", mock_true): result = chocolatey._find_chocolatey() expected = choco_path_pd # Does it return the correct path assert result == expected # Does it populate __context__ assert chocolatey.__context__["chocolatey._path"] == expected
def test__find_chocolatey_systemdrive(self): ''' Test _find_chocolatey when found on SystemDrive (older versions) ''' with patch.dict(chocolatey.__salt__, {'cmd.which': self.mock_false}),\ patch('os.path.isfile', MagicMock(side_effect=[False, True])): result = chocolatey._find_chocolatey() expected = self.choco_path_sd # Does it return the correct path self.assertEqual(result, expected) # Does it populate __context__ self.assertEqual(chocolatey.__context__['chocolatey._path'], expected)
def test__find_chocolatey_programdata(self): ''' Test _find_chocolatey when found in ProgramData ''' with patch.dict(chocolatey.__salt__, {'cmd.which': self.mock_false}),\ patch('os.path.isfile', self.mock_true): result = chocolatey._find_chocolatey() expected = self.choco_path_pd # Does it return the correct path self.assertEqual(result, expected) # Does it populate __context__ self.assertEqual(chocolatey.__context__['chocolatey._path'], expected)
def test__find_chocolatey_which(self): ''' Test _find_chocolatey when found with `cmd.which` ''' mock_which = MagicMock(return_value=self.choco_path) with patch.dict(chocolatey.__salt__, {'cmd.which': mock_which}): result = chocolatey._find_chocolatey() expected = self.choco_path # Does it return the correct path self.assertEqual(result, expected) # Does it populate __context__ self.assertEqual(chocolatey.__context__['chocolatey._path'], expected)
def test__find_chocolatey_programdata(self): """ Test _find_chocolatey when found in ProgramData """ with patch.dict(chocolatey.__salt__, {"cmd.which": self.mock_false}), patch( "os.path.isfile", self.mock_true): result = chocolatey._find_chocolatey() expected = self.choco_path_pd # Does it return the correct path self.assertEqual(result, expected) # Does it populate __context__ self.assertEqual(chocolatey.__context__["chocolatey._path"], expected)