From 38535bd820fd1525ebf43acfd3e02ea86c2ff9b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Tue, 23 Jan 2018 16:00:56 +0000
Subject: [PATCH] Allow running tests on Python 2.6 systems

---
 tests/unit/grains/core_test.py        |  12 +-
 tests/unit/modules/test_kubernetes.py |  19 ++-
 tests/unit/modules/test_yumpkg.py     | 310 ++++++++++++++++++----------------
 tests/unit/modules/zypper_test.py     | 154 ++++++++---------
 4 files changed, 253 insertions(+), 242 deletions(-)

diff --git a/tests/unit/grains/core_test.py b/tests/unit/grains/core_test.py
index c60bf373d6..d339561816 100644
--- a/tests/unit/grains/core_test.py
+++ b/tests/unit/grains/core_test.py
@@ -475,13 +475,11 @@ PATCHLEVEL = 3
 
     def _run_fqdns_test(self, reverse_resolv_mock, ret):
         with patch.object(salt.utils, 'is_windows', MagicMock(return_value=False)):
-            with patch('salt.utils.network.ip_addrs',
-            MagicMock(return_value=['1.2.3.4', '5.6.7.8'])),\
-            patch('salt.utils.network.ip_addrs6',
-            MagicMock(return_value=['fe80::a8b2:93ff:fe00:0', 'fe80::a8b2:93ff:dead:beef'])):
-                with patch.object(socket, 'gethostbyaddr', side_effect=reverse_resolv_mock):
-                    fqdns = core.fqdns()
-                    self.assertEqual(fqdns, ret)
+            with patch('salt.utils.network.ip_addrs', MagicMock(return_value=['1.2.3.4', '5.6.7.8'])):
+                with patch('salt.utils.network.ip_addrs6', MagicMock(return_value=['fe80::a8b2:93ff:fe00:0', 'fe80::a8b2:93ff:dead:beef'])):
+                    with patch.object(socket, 'gethostbyaddr', side_effect=reverse_resolv_mock):
+                        fqdns = core.fqdns()
+                        self.assertEqual(fqdns, ret)
 
 if __name__ == '__main__':
     from integration import run_tests
diff --git a/tests/unit/modules/test_kubernetes.py b/tests/unit/modules/test_kubernetes.py
index 493822a93c..7003b24663 100644
--- a/tests/unit/modules/test_kubernetes.py
+++ b/tests/unit/modules/test_kubernetes.py
@@ -5,6 +5,7 @@
 
 # Import Python Libs
 from __future__ import absolute_import
+import sys
 
 # Import Salt Testing Libs
 from salttesting import TestCase, skipIf
@@ -15,15 +16,17 @@ from salttesting.mock import (
     NO_MOCK_REASON
 )
 
-try:
-    from salt.modules import kubernetes
-except ImportError:
+if sys.version_info < (2, 7):
     kubernetes = False
-
-# Globals
-kubernetes.__salt__ = dict()
-kubernetes.__grains__ = dict()
-kubernetes.__context__ = dict()
+else:
+    try:
+        from salt.modules import kubernetes
+        # Globals
+        kubernetes.__salt__ = dict()
+        kubernetes.__grains__ = dict()
+        kubernetes.__context__ = dict()
+    except ImportError:
+        kubernetes = False
 
 
 @skipIf(NO_MOCK, NO_MOCK_REASON)
diff --git a/tests/unit/modules/test_yumpkg.py b/tests/unit/modules/test_yumpkg.py
index 574fec1bfe..ae3b29c472 100644
--- a/tests/unit/modules/test_yumpkg.py
+++ b/tests/unit/modules/test_yumpkg.py
@@ -23,168 +23,186 @@ yumpkg.__grains__ = dict()
 yumpkg.__context__ = dict()
 
 
+RPM_OUT = [
+    'python-urlgrabber_|-(none)_|-3.10_|-8.el7_|-noarch_|-(none)_|-1487838471',
+    'alsa-lib_|-(none)_|-1.1.1_|-1.el7_|-x86_64_|-(none)_|-1487838475',
+    'gnupg2_|-(none)_|-2.0.22_|-4.el7_|-x86_64_|-(none)_|-1487838477',
+    'rpm-python_|-(none)_|-4.11.3_|-21.el7_|-x86_64_|-(none)_|-1487838477',
+    'pygpgme_|-(none)_|-0.3_|-9.el7_|-x86_64_|-(none)_|-1487838478',
+    'yum_|-(none)_|-3.4.3_|-150.el7.centos_|-noarch_|-(none)_|-1487838479',
+    'lzo_|-(none)_|-2.06_|-8.el7_|-x86_64_|-(none)_|-1487838479',
+    'qrencode-libs_|-(none)_|-3.4.1_|-3.el7_|-x86_64_|-(none)_|-1487838480',
+    'ustr_|-(none)_|-1.0.4_|-16.el7_|-x86_64_|-(none)_|-1487838480',
+    'shadow-utils_|-2_|-4.1.5.1_|-24.el7_|-x86_64_|-(none)_|-1487838481',
+    'util-linux_|-(none)_|-2.23.2_|-33.el7_|-x86_64_|-(none)_|-1487838484',
+    'openssh_|-(none)_|-6.6.1p1_|-33.el7_3_|-x86_64_|-(none)_|-1487838485',
+    'virt-what_|-(none)_|-1.13_|-8.el7_|-x86_64_|-(none)_|-1487838486',
+]
+
+def _add_data(data, key, value):
+    data.setdefault(key, []).append(value)
+
+
 @skipIf(NO_MOCK, NO_MOCK_REASON)
 class YumTestCase(TestCase):
     '''
     Test cases for salt.modules.yumpkg
     '''
 
+    @patch.dict(yumpkg.__grains__, {'osarch': 'x86_64', 'os': 'RedHat'})
+    @patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(RPM_OUT))})
+    @patch.dict(yumpkg.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'python-urlgrabber': '0.0.1'} , 'repository'))})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list})
+    @patch.dict(yumpkg.__salt__, {'config.get': MagicMock()})
+    @patch.dict(yumpkg.__salt__, {'lowpkg.version_cmp': MagicMock(return_value=-1)})
+    def test_install_pkg(self):
+        '''
+        Test package installation.
+
+        :return:
+        '''
+        pkgs = yumpkg.install(name='python-urlgrabber')
+        self.assertEqual(pkgs, {})
+
+    @patch.dict(yumpkg.__grains__, {'osarch': 'x86_64', 'os': 'RedHat'})
+    @patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(RPM_OUT))})
+    @patch.dict(yumpkg.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'python-urlgrabber': '0.0.1'} , 'repository'))})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list})
+    @patch.dict(yumpkg.__salt__, {'config.get': MagicMock()})
+    @patch.dict(yumpkg.__salt__, {'lowpkg.version_cmp': MagicMock(return_value=-1)})
+    def test_install_pkg_with_diff_attr(self):
+        '''
+        Test package installation with diff_attr.
+
+        :return:
+        '''
+        pkgs = yumpkg.install(name='python-urlgrabber', diff_attr=['version', 'epoch', 'release', 'arch'])
+        self.assertEqual(pkgs, {})
+
+    @patch.dict(yumpkg.__grains__, {'osarch': 'x86_64'})
+    @patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(RPM_OUT))})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.stringify': MagicMock()})
     def test_list_pkgs(self):
         '''
         Test packages listing.
 
         :return:
         '''
-        def _add_data(data, key, value):
-            data.setdefault(key, []).append(value)
-
-        rpm_out = [
-            'python-urlgrabber_|-(none)_|-3.10_|-8.el7_|-noarch_|-(none)_|-1487838471',
-            'alsa-lib_|-(none)_|-1.1.1_|-1.el7_|-x86_64_|-(none)_|-1487838475',
-            'gnupg2_|-(none)_|-2.0.22_|-4.el7_|-x86_64_|-(none)_|-1487838477',
-            'rpm-python_|-(none)_|-4.11.3_|-21.el7_|-x86_64_|-(none)_|-1487838477',
-            'pygpgme_|-(none)_|-0.3_|-9.el7_|-x86_64_|-(none)_|-1487838478',
-            'yum_|-(none)_|-3.4.3_|-150.el7.centos_|-noarch_|-(none)_|-1487838479',
-            'lzo_|-(none)_|-2.06_|-8.el7_|-x86_64_|-(none)_|-1487838479',
-            'qrencode-libs_|-(none)_|-3.4.1_|-3.el7_|-x86_64_|-(none)_|-1487838480',
-            'ustr_|-(none)_|-1.0.4_|-16.el7_|-x86_64_|-(none)_|-1487838480',
-            'shadow-utils_|-2_|-4.1.5.1_|-24.el7_|-x86_64_|-(none)_|-1487838481',
-            'util-linux_|-(none)_|-2.23.2_|-33.el7_|-x86_64_|-(none)_|-1487838484',
-            'openssh_|-(none)_|-6.6.1p1_|-33.el7_3_|-x86_64_|-(none)_|-1487838485',
-            'virt-what_|-(none)_|-1.13_|-8.el7_|-x86_64_|-(none)_|-1487838486',
-        ]
-        with patch.dict(yumpkg.__grains__, {'osarch': 'x86_64'}), \
-             patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(rpm_out))}), \
-             patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data}), \
-             patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list}), \
-             patch.dict(yumpkg.__salt__, {'pkg_resource.stringify': MagicMock()}):
-            pkgs = yumpkg.list_pkgs(versions_as_list=True)
-            for pkg_name, pkg_version in {
-                'python-urlgrabber': '3.10-8.el7',
-                'alsa-lib': '1.1.1-1.el7',
-                'gnupg2': '2.0.22-4.el7',
-                'rpm-python': '4.11.3-21.el7',
-                'pygpgme': '0.3-9.el7',
-                'yum': '3.4.3-150.el7.centos',
-                'lzo': '2.06-8.el7',
-                'qrencode-libs': '3.4.1-3.el7',
-                'ustr': '1.0.4-16.el7',
-                'shadow-utils': '2:4.1.5.1-24.el7',
-                'util-linux': '2.23.2-33.el7',
-                'openssh': '6.6.1p1-33.el7_3',
-                'virt-what': '1.13-8.el7'}.items():
-                self.assertTrue(pkgs.get(pkg_name))
-                self.assertEqual(pkgs[pkg_name], [pkg_version])
+        pkgs = yumpkg.list_pkgs(versions_as_list=True)
+        for pkg_name, pkg_version in {
+            'python-urlgrabber': '3.10-8.el7',
+            'alsa-lib': '1.1.1-1.el7',
+            'gnupg2': '2.0.22-4.el7',
+            'rpm-python': '4.11.3-21.el7',
+            'pygpgme': '0.3-9.el7',
+            'yum': '3.4.3-150.el7.centos',
+            'lzo': '2.06-8.el7',
+            'qrencode-libs': '3.4.1-3.el7',
+            'ustr': '1.0.4-16.el7',
+            'shadow-utils': '2:4.1.5.1-24.el7',
+            'util-linux': '2.23.2-33.el7',
+            'openssh': '6.6.1p1-33.el7_3',
+            'virt-what': '1.13-8.el7'}.items():
+            self.assertTrue(pkgs.get(pkg_name))
+            self.assertEqual(pkgs[pkg_name], [pkg_version])
 
+    @patch.dict(yumpkg.__grains__, {'osarch': 'x86_64'})
+    @patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(RPM_OUT))})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list})
+    @patch.dict(yumpkg.__salt__, {'pkg_resource.stringify': MagicMock()})
     def test_list_pkgs_with_attr(self):
         '''
         Test packages listing with the attr parameter
 
         :return:
         '''
-        def _add_data(data, key, value):
-            data.setdefault(key, []).append(value)
-
-        rpm_out = [
-            'python-urlgrabber_|-(none)_|-3.10_|-8.el7_|-noarch_|-(none)_|-1487838471',
-            'alsa-lib_|-(none)_|-1.1.1_|-1.el7_|-x86_64_|-(none)_|-1487838475',
-            'gnupg2_|-(none)_|-2.0.22_|-4.el7_|-x86_64_|-(none)_|-1487838477',
-            'rpm-python_|-(none)_|-4.11.3_|-21.el7_|-x86_64_|-(none)_|-1487838477',
-            'pygpgme_|-(none)_|-0.3_|-9.el7_|-x86_64_|-(none)_|-1487838478',
-            'yum_|-(none)_|-3.4.3_|-150.el7.centos_|-noarch_|-(none)_|-1487838479',
-            'lzo_|-(none)_|-2.06_|-8.el7_|-x86_64_|-(none)_|-1487838479',
-            'qrencode-libs_|-(none)_|-3.4.1_|-3.el7_|-x86_64_|-(none)_|-1487838480',
-            'ustr_|-(none)_|-1.0.4_|-16.el7_|-x86_64_|-(none)_|-1487838480',
-            'shadow-utils_|-2_|-4.1.5.1_|-24.el7_|-x86_64_|-(none)_|-1487838481',
-            'util-linux_|-(none)_|-2.23.2_|-33.el7_|-x86_64_|-(none)_|-1487838484',
-            'openssh_|-(none)_|-6.6.1p1_|-33.el7_3_|-x86_64_|-(none)_|-1487838485',
-            'virt-what_|-(none)_|-1.13_|-8.el7_|-x86_64_|-(none)_|-1487838486',
-        ]
-        with patch.dict(yumpkg.__grains__, {'osarch': 'x86_64'}), \
-             patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(rpm_out))}), \
-             patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data}), \
-             patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list}), \
-             patch.dict(yumpkg.__salt__, {'pkg_resource.stringify': MagicMock()}):
-            pkgs = yumpkg.list_pkgs(attr=['epoch', 'release', 'arch', 'install_date_time_t'])
-            for pkg_name, pkg_attr in {
-                'python-urlgrabber': {
-                    'version': '3.10',
-                    'release': '8.el7',
-                    'arch': 'noarch',
-                    'install_date_time_t': 1487838471,
-                },
-                'alsa-lib': {
-                    'version': '1.1.1',
-                    'release': '1.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838475,
-                },
-                'gnupg2': {
-                    'version': '2.0.22',
-                    'release': '4.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838477,
-                },
-                'rpm-python': {
-                    'version': '4.11.3',
-                    'release': '21.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838477,
-                },
-                'pygpgme': {
-                    'version': '0.3',
-                    'release': '9.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838478,
-                },
-                'yum': {
-                    'version': '3.4.3',
-                    'release': '150.el7.centos',
-                    'arch': 'noarch',
-                    'install_date_time_t': 1487838479,
-                },
-                'lzo': {
-                    'version': '2.06',
-                    'release': '8.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838479,
-                },
-                'qrencode-libs': {
-                    'version': '3.4.1',
-                    'release': '3.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838480,
-                },
-                'ustr': {
-                    'version': '1.0.4',
-                    'release': '16.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838480,
-                },
-                'shadow-utils': {
-                    'epoch': '2',
-                    'version': '4.1.5.1',
-                    'release': '24.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838481,
-                },
-                'util-linux': {
-                    'version': '2.23.2',
-                    'release': '33.el7',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838484,
-                },
-                'openssh': {
-                    'version': '6.6.1p1',
-                    'release': '33.el7_3',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1487838485,
-                },
-                'virt-what': {
-                    'version': '1.13',
-                    'release': '8.el7',
-                    'install_date_time_t': 1487838486,
-                    'arch': 'x86_64',
-                }}.items():
-                self.assertTrue(pkgs.get(pkg_name))
-                self.assertEqual(pkgs[pkg_name], [pkg_attr])
+        pkgs = yumpkg.list_pkgs(attr=['epoch', 'release', 'arch', 'install_date_time_t'])
+        for pkg_name, pkg_attr in {
+            'python-urlgrabber': {
+                'version': '3.10',
+                'release': '8.el7',
+                'arch': 'noarch',
+                'install_date_time_t': 1487838471,
+            },
+            'alsa-lib': {
+                'version': '1.1.1',
+                'release': '1.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838475,
+            },
+            'gnupg2': {
+                'version': '2.0.22',
+                'release': '4.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838477,
+            },
+            'rpm-python': {
+                'version': '4.11.3',
+                'release': '21.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838477,
+            },
+            'pygpgme': {
+                'version': '0.3',
+                'release': '9.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838478,
+            },
+            'yum': {
+                'version': '3.4.3',
+                'release': '150.el7.centos',
+                'arch': 'noarch',
+                'install_date_time_t': 1487838479,
+            },
+            'lzo': {
+                'version': '2.06',
+                'release': '8.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838479,
+            },
+            'qrencode-libs': {
+                'version': '3.4.1',
+                'release': '3.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838480,
+            },
+            'ustr': {
+                'version': '1.0.4',
+                'release': '16.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838480,
+            },
+            'shadow-utils': {
+                'epoch': '2',
+                'version': '4.1.5.1',
+                'release': '24.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838481,
+            },
+            'util-linux': {
+                'version': '2.23.2',
+                'release': '33.el7',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838484,
+            },
+            'openssh': {
+                'version': '6.6.1p1',
+                'release': '33.el7_3',
+                'arch': 'x86_64',
+                'install_date_time_t': 1487838485,
+            },
+            'virt-what': {
+                'version': '1.13',
+                'release': '8.el7',
+                'install_date_time_t': 1487838486,
+                'arch': 'x86_64',
+            }}.items():
+            self.assertTrue(pkgs.get(pkg_name))
+            self.assertEqual(pkgs[pkg_name], [pkg_attr])
diff --git a/tests/unit/modules/zypper_test.py b/tests/unit/modules/zypper_test.py
index be09d16f47..c82dedec29 100644
--- a/tests/unit/modules/zypper_test.py
+++ b/tests/unit/modules/zypper_test.py
@@ -46,6 +46,10 @@ def get_test_data(filename):
     return open(os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'zypp'), filename)).read()
 
 
+def _add_data(data, key, value):
+    data.setdefault(key, []).append(value)
+
+
 # Import Salt Libs
 from salt.modules import zypper
 
@@ -56,6 +60,16 @@ zypper.__context__ = dict()
 zypper.rpm = None
 
 
+RPM_OUT = [
+    'protobuf-java_|-2.6.1_|-3.1.develHead_|-noarch_|-_|-1499257756',
+    'yast2-ftp-server_|-3.1.8_|-8.1_|-x86_64_|-_|-1499257798',
+    'jose4j_|-0.4.4_|-2.1.develHead_|-noarch_|-_|-1499257756',
+    'apache-commons-cli_|-1.2_|-1.233_|-noarch_|-_|-1498636510',
+    'jakarta-commons-discovery_|-0.4_|-129.686_|-noarch_|-_|-1498636511',
+    'susemanager-build-keys-web_|-12.0_|-5.1.develHead_|-noarch_|-_|-1498636510',
+]
+
+
 @skipIf(NO_MOCK, NO_MOCK_REASON)
 class ZypperTestCase(TestCase):
 
@@ -431,99 +445,77 @@ Repository 'DUMMY' not found by its alias, number, or URI.
                 self.assertFalse(zypper.upgrade_available(pkg_name))
             self.assertTrue(zypper.upgrade_available('vim'))
 
+    @patch.dict(zypper.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(RPM_OUT))})
+    @patch.dict(zypper.__salt__, {'pkg_resource.add_pkg': _add_data})
+    @patch.dict(zypper.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list})
+    @patch.dict(zypper.__salt__, {'pkg_resource.stringify': MagicMock()})
     def test_list_pkgs(self):
         '''
         Test packages listing.
 
         :return:
         '''
-        def _add_data(data, key, value):
-            data.setdefault(key, []).append(value)
-
-        rpm_out = [
-            'protobuf-java_|-2.6.1_|-3.1.develHead_|-noarch_|-_|-1499257756',
-            'yast2-ftp-server_|-3.1.8_|-8.1_|-x86_64_|-_|-1499257798',
-            'jose4j_|-0.4.4_|-2.1.develHead_|-noarch_|-_|-1499257756',
-            'apache-commons-cli_|-1.2_|-1.233_|-noarch_|-_|-1498636510',
-            'jakarta-commons-discovery_|-0.4_|-129.686_|-noarch_|-_|-1498636511',
-            'susemanager-build-keys-web_|-12.0_|-5.1.develHead_|-noarch_|-_|-1498636510',
-        ]
-        with patch.dict(zypper.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(rpm_out))}), \
-             patch.dict(zypper.__salt__, {'pkg_resource.add_pkg': _add_data}), \
-             patch.dict(zypper.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list}), \
-             patch.dict(zypper.__salt__, {'pkg_resource.stringify': MagicMock()}):
-            pkgs = zypper.list_pkgs(versions_as_list=True)
-            for pkg_name, pkg_version in {
-                'jakarta-commons-discovery': '0.4-129.686',
-                'yast2-ftp-server': '3.1.8-8.1',
-                'protobuf-java': '2.6.1-3.1.develHead',
-                'susemanager-build-keys-web': '12.0-5.1.develHead',
-                'apache-commons-cli': '1.2-1.233',
-                'jose4j': '0.4.4-2.1.develHead'}.items():
-                self.assertTrue(pkgs.get(pkg_name))
-                self.assertEqual(pkgs[pkg_name], [pkg_version])
-
+        pkgs = zypper.list_pkgs(versions_as_list=True)
+        for pkg_name, pkg_version in {
+            'jakarta-commons-discovery': '0.4-129.686',
+            'yast2-ftp-server': '3.1.8-8.1',
+            'protobuf-java': '2.6.1-3.1.develHead',
+            'susemanager-build-keys-web': '12.0-5.1.develHead',
+            'apache-commons-cli': '1.2-1.233',
+            'jose4j': '0.4.4-2.1.develHead'}.items():
+            self.assertTrue(pkgs.get(pkg_name))
+            self.assertEqual(pkgs[pkg_name], [pkg_version])
+
+    @patch.dict(zypper.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(RPM_OUT))})
+    @patch.dict(zypper.__salt__, {'pkg_resource.add_pkg': _add_data})
+    @patch.dict(zypper.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list})
+    @patch.dict(zypper.__salt__, {'pkg_resource.stringify': MagicMock()})
     def test_list_pkgs_with_attr(self):
         '''
         Test packages listing with the attr parameter
 
         :return:
         '''
-        def _add_data(data, key, value):
-            data.setdefault(key, []).append(value)
-
-        rpm_out = [
-            'protobuf-java_|-2.6.1_|-3.1.develHead_|-noarch_|-_|-1499257756',
-            'yast2-ftp-server_|-3.1.8_|-8.1_|-x86_64_|-_|-1499257798',
-            'jose4j_|-0.4.4_|-2.1.develHead_|-noarch_|-_|-1499257756',
-            'apache-commons-cli_|-1.2_|-1.233_|-noarch_|-_|-1498636510',
-            'jakarta-commons-discovery_|-0.4_|-129.686_|-noarch_|-_|-1498636511',
-            'susemanager-build-keys-web_|-12.0_|-5.1.develHead_|-noarch_|-_|-1498636510',
-        ]
-        with patch.dict(zypper.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(rpm_out))}), \
-             patch.dict(zypper.__salt__, {'pkg_resource.add_pkg': _add_data}), \
-             patch.dict(zypper.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list}), \
-             patch.dict(zypper.__salt__, {'pkg_resource.stringify': MagicMock()}):
-            pkgs = zypper.list_pkgs(attr=['epoch', 'release', 'arch', 'install_date_time_t'])
-            for pkg_name, pkg_attr in {
-                'jakarta-commons-discovery': {
-                    'version': '0.4',
-                    'release': '129.686',
-                    'arch': 'noarch',
-                    'install_date_time_t': 1498636511,
-                },
-                'yast2-ftp-server': {
-                    'version': '3.1.8',
-                    'release': '8.1',
-                    'arch': 'x86_64',
-                    'install_date_time_t': 1499257798,
-                },
-                'protobuf-java': {
-                    'version': '2.6.1',
-                    'release': '3.1.develHead',
-                    'install_date_time_t': 1499257756,
-                    'arch': 'noarch',
-                },
-                'susemanager-build-keys-web': {
-                    'version': '12.0',
-                    'release': '5.1.develHead',
-                    'arch': 'noarch',
-                    'install_date_time_t': 1498636510,
-                },
-                'apache-commons-cli': {
-                    'version': '1.2',
-                    'release': '1.233',
-                    'arch': 'noarch',
-                    'install_date_time_t': 1498636510,
-                },
-                'jose4j': {
-                    'arch': 'noarch',
-                    'version': '0.4.4',
-                    'release': '2.1.develHead',
-                    'install_date_time_t': 1499257756,
-                }}.items():
-                self.assertTrue(pkgs.get(pkg_name))
-                self.assertEqual(pkgs[pkg_name], [pkg_attr])
+        pkgs = zypper.list_pkgs(attr=['epoch', 'release', 'arch', 'install_date_time_t'])
+        for pkg_name, pkg_attr in {
+            'jakarta-commons-discovery': {
+                'version': '0.4',
+                'release': '129.686',
+                'arch': 'noarch',
+                'install_date_time_t': 1498636511,
+            },
+            'yast2-ftp-server': {
+                'version': '3.1.8',
+                'release': '8.1',
+                'arch': 'x86_64',
+                'install_date_time_t': 1499257798,
+            },
+            'protobuf-java': {
+                'version': '2.6.1',
+                'release': '3.1.develHead',
+                'install_date_time_t': 1499257756,
+                'arch': 'noarch',
+            },
+            'susemanager-build-keys-web': {
+                'version': '12.0',
+                'release': '5.1.develHead',
+                'arch': 'noarch',
+                'install_date_time_t': 1498636510,
+            },
+            'apache-commons-cli': {
+                'version': '1.2',
+                'release': '1.233',
+                'arch': 'noarch',
+                'install_date_time_t': 1498636510,
+            },
+            'jose4j': {
+                'arch': 'noarch',
+                'version': '0.4.4',
+                'release': '2.1.develHead',
+                'install_date_time_t': 1499257756,
+            }}.items():
+            self.assertTrue(pkgs.get(pkg_name))
+            self.assertEqual(pkgs[pkg_name], [pkg_attr])
 
     def test_list_patches(self):
         '''
-- 
2.13.6


