def test_info_installed(self): """ Test - Return the information of the named package(s) installed on the system. """ names = {"group": "section", "packager": "maintainer", "url": "homepage"} installed = copy.deepcopy({'wget': LOWPKG_INFO['wget']}) for name in names: if installed['wget'].get(names[name], False): installed['wget'][name] = installed['wget'].pop(names[name]) del installed['wget']['status'] assert aptpkg.info_installed('wget') == installed assert len(aptpkg.info_installed()) == 1
def test_info_installed(lowpkg_info_var): """ Test - Return the information of the named package(s) installed on the system. """ names = {"group": "section", "packager": "maintainer", "url": "homepage"} installed = copy.deepcopy({"wget": lowpkg_info_var["wget"]}) for name in names: if installed["wget"].get(names[name], False): installed["wget"][name] = installed["wget"].pop(names[name]) mock = MagicMock(return_value=lowpkg_info_var) with patch.dict(aptpkg.__salt__, {"lowpkg.info": mock}): del installed["wget"]["status"] assert aptpkg.info_installed("wget") == installed assert len(aptpkg.info_installed()) == 1
def test_info_installed_attr(self): ''' Test info_installed 'attr'. This doesn't test 'attr' behaviour per se, since the underlying function is in dpkg. The test should simply not raise exceptions for invalid parameter. :return: ''' ret = aptpkg.info_installed('emacs', attr='foo,bar') assert isinstance(ret, dict) assert 'wget' in ret assert isinstance(ret['wget'], dict) wget_pkg = ret['wget'] expected_pkg = { 'url': 'http://www.gnu.org/software/wget/', 'packager': 'Ubuntu Developers <*****@*****.**>', 'name': 'wget', 'install_date': '2016-08-30T22:20:15Z', 'description': 'retrieves files from the web', 'version': '1.15-1ubuntu1.14.04.2', 'architecture': 'amd64', 'group': 'web', 'source': 'wget' } for k in wget_pkg: assert k in expected_pkg assert wget_pkg[k] == expected_pkg[k]
def test_info_installed_all_versions(self): ''' Test info_installed 'all_versions'. Since Debian won't return same name packages with the different names, this should just return different structure, backward compatible with the RPM equivalents. :return: ''' print() ret = aptpkg.info_installed('emacs', all_versions=True) assert isinstance(ret, dict) assert 'wget' in ret assert isinstance(ret['wget'], list) pkgs = ret['wget'] assert len(pkgs) == 1 assert isinstance(pkgs[0], dict) wget_pkg = pkgs[0] expected_pkg = {'url': 'http://www.gnu.org/software/wget/', 'packager': 'Ubuntu Developers <*****@*****.**>', 'name': 'wget', 'install_date': '2016-08-30T22:20:15Z', 'description': 'retrieves files from the web', 'version': '1.15-1ubuntu1.14.04.2', 'architecture': 'amd64', 'group': 'web', 'source': 'wget'} for k in wget_pkg: assert k in expected_pkg assert wget_pkg[k] == expected_pkg[k]
def test_info_installed(self): ''' Test - Return the information of the named package(s) installed on the system. ''' names = { 'group': 'section', 'packager': 'maintainer', 'url': 'homepage' } installed = copy.deepcopy({'wget': LOWPKG_INFO['wget']}) for name in names: if installed['wget'].get(names[name], False): installed['wget'][name] = installed['wget'].pop(names[name]) del installed['wget']['status'] assert aptpkg.info_installed('wget') == installed assert len(aptpkg.info_installed()) == 1
def test_info_installed(self): ''' Test - Return the information of the named package(s) installed on the system. ''' names = { 'group': 'section', 'packager': 'maintainer', 'url': 'homepage' } installed = copy.deepcopy({'wget': LOWPKG_INFO['wget']}) for name in names: if installed['wget'].get(names[name], False): installed['wget'][name] = installed['wget'].pop(names[name]) mock = MagicMock(return_value=LOWPKG_INFO) with patch.dict(aptpkg.__salt__, {'lowpkg.info': mock}): del installed['wget']['status'] self.assertEqual(aptpkg.info_installed('wget'), installed) self.assertEqual(len(aptpkg.info_installed()), 1)
def test_info_installed_attr_without_status(self): ''' Test info_installed 'attr' for inclusion of 'status' attribute. Since info_installed should only return installed packages, we need to call __salt__['lowpkg.info'] with the 'status' attribute even if the user is not asking for it in 'attr'. Otherwise info_installed would not be able to check if the package is installed and would return everything. :return: ''' with patch('salt.modules.aptpkg.__salt__', {'lowpkg.info': MagicMock(return_value=LOWPKG_INFO)}) as wget_lowpkg: ret = aptpkg.info_installed('wget', attr='version') calls = wget_lowpkg['lowpkg.info'].call_args_list.pop() self.assertIn('status', calls.kwargs['attr']) self.assertIn('version', calls.kwargs['attr'])
def test_info_installed(self): ''' Test - Return the information of the named package(s) installed on the system. ''' names = { 'group': 'section', 'packager': 'maintainer', 'url': 'homepage' } installed = copy.deepcopy(LOWPKG_INFO) for name in names: if installed['wget'].get(names[name], False): installed['wget'][name] = installed['wget'].pop(names[name]) mock = MagicMock(return_value=LOWPKG_INFO) with patch.dict(aptpkg.__salt__, {'lowpkg.info': mock}): self.assertEqual(aptpkg.info_installed('wget'), installed)