From 2742ee76ccc50cd4f84e44861ef82ec5f3b5234a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= Date: Wed, 25 May 2016 17:08:16 +0100 Subject: [PATCH 10/11] unit tests for rpm.checksum() and zypper.download() lint issue fixed --- tests/unit/modules/rpm_test.py | 16 ++++++++++++++++ tests/unit/modules/zypp/zypper-download.xml | 19 +++++++++++++++++++ tests/unit/modules/zypper_test.py | 25 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 tests/unit/modules/zypp/zypper-download.xml diff --git a/tests/unit/modules/rpm_test.py b/tests/unit/modules/rpm_test.py index f180736..4042137 100644 --- a/tests/unit/modules/rpm_test.py +++ b/tests/unit/modules/rpm_test.py @@ -95,6 +95,22 @@ class RpmTestCase(TestCase): self.assertDictEqual(rpm.owner('/usr/bin/python', '/usr/bin/vim'), ret) + # 'checksum' function tests: 1 + + def test_checksum(self): + ''' + Test if checksum validate as expected + ''' + ret = { + "file1.rpm": True, + "file2.rpm": False, + "file3.rpm": False, + } + + mock = MagicMock(side_effect=[True, 0, True, 1, False, 0]) + with patch.dict(rpm.__salt__, {'file.file_exists': mock, 'cmd.retcode': mock}): + self.assertDictEqual(rpm.checksum("file1.rpm", "file2.rpm", "file3.rpm"), ret) + @patch('salt.modules.rpm.HAS_RPM', True) def test_version_cmp_rpm(self): ''' diff --git a/tests/unit/modules/zypp/zypper-download.xml b/tests/unit/modules/zypp/zypper-download.xml new file mode 100644 index 0000000..eeea0a5 --- /dev/null +++ b/tests/unit/modules/zypp/zypper-download.xml @@ -0,0 +1,19 @@ + + + Loading repository data... + Reading installed packages... + Argument resolves to no package: foo + + + + package + nmap + + x86_64 + + + + + + download: Done. + diff --git a/tests/unit/modules/zypper_test.py b/tests/unit/modules/zypper_test.py index 4e735cd..9ec2b83 100644 --- a/tests/unit/modules/zypper_test.py +++ b/tests/unit/modules/zypper_test.py @@ -354,6 +354,31 @@ class ZypperTestCase(TestCase): self.assertTrue(pkgs.get(pkg_name)) self.assertEqual(pkgs[pkg_name], pkg_version) + def test_download(self): + ''' + Test package download + :return: + ''' + download_out = { + 'stdout': get_test_data('zypper-download.xml'), + 'stderr': None, + 'retcode': 0 + } + + test_out = { + 'nmap': { + 'path': u'/var/cache/zypp/packages/SLE-12-x86_64-Pool/x86_64/nmap-6.46-1.72.x86_64.rpm', + 'repository-alias': u'SLE-12-x86_64-Pool', + 'repository-name': u'SLE-12-x86_64-Pool' + } + } + + with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=download_out)}): + with patch.dict(zypper.__salt__, {'lowpkg.checksum': MagicMock(return_value=True)}): + self.assertEqual(zypper.download("nmap"), test_out) + test_out['_error'] = "The following package(s) failed to download: foo" + self.assertEqual(zypper.download("nmap", "foo"), test_out) + def test_remove_purge(self): ''' Test package removal -- 2.8.2