]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
a wealth of tests for the pkg_managers module 146/head
authorAlfredo Deza <alfredo.deza@inktank.com>
Thu, 12 Dec 2013 22:15:01 +0000 (17:15 -0500)
committerAlfredo Deza <alfredo.deza@inktank.com>
Thu, 12 Dec 2013 22:15:01 +0000 (17:15 -0500)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
ceph_deploy/tests/unit/util/test_pkg_managers.py

index de421b404746ac77cfd75edf6e606123542935e4..5ef702723c7d3f3b69d5fa123c1a51a1e234101b 100644 (file)
@@ -1,4 +1,3 @@
-import py.test
 from mock import patch, Mock
 from ceph_deploy.util import pkg_managers
 
@@ -6,17 +5,135 @@ from ceph_deploy.util import pkg_managers
 class TestRPM(object):
 
     def setup(self):
-        self.to_patch = 'ceph_deploy.util.pkg_managers.wrappers'
+        self.to_patch = 'ceph_deploy.util.pkg_managers.process.run'
 
-    @py.test.mark.skipif(reason='failing due to removal of pushy')
-    def test_extend_flags(self):
-        fake_check_call = Mock()
-        with patch(self.to_patch, fake_check_call):
+    def test_normal_flags(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.rpm(Mock())
+            result = fake_run.call_args_list[-1]
+        assert result[0][-1] == ['rpm', '-Uvh']
+
+    def test_extended_flags(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
             pkg_managers.rpm(
-                Mock(),
                 Mock(),
                 ['-f', 'vim'])
-            result = fake_check_call.check_call.call_args_list[-1]
+            result = fake_run.call_args_list[-1]
         assert result[0][-1] == ['rpm', '-Uvh', '-f', 'vim']
 
 
+class TestApt(object):
+
+    def setup(self):
+        self.to_patch = 'ceph_deploy.util.pkg_managers.process.run'
+
+    def test_install_single_package(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.apt(Mock(), 'vim')
+            result = fake_run.call_args_list[-1]
+        assert 'install' in result[0][-1]
+        assert result[0][-1][-1] == 'vim'
+
+    def test_install_multiple_packages(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.apt(Mock(), ['vim', 'zsh'])
+            result = fake_run.call_args_list[-1]
+        assert 'install' in result[0][-1]
+        assert result[0][-1][-2:] == ['vim', 'zsh']
+
+    def test_remove_single_package(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.apt_remove(Mock(), 'vim')
+            result = fake_run.call_args_list[-1]
+        assert 'remove' in result[0][-1]
+        assert result[0][-1][-1] == 'vim'
+
+    def test_remove_multiple_packages(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.apt_remove(Mock(), ['vim', 'zsh'])
+            result = fake_run.call_args_list[-1]
+        assert 'remove' in result[0][-1]
+        assert result[0][-1][-2:] == ['vim', 'zsh']
+
+
+class TestYum(object):
+
+    def setup(self):
+        self.to_patch = 'ceph_deploy.util.pkg_managers.process.run'
+
+    def test_install_single_package(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.yum(Mock(), 'vim')
+            result = fake_run.call_args_list[-1]
+        assert 'install' in result[0][-1]
+        assert result[0][-1][-1] == 'vim'
+
+    def test_install_multiple_packages(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.yum(Mock(), ['vim', 'zsh'])
+            result = fake_run.call_args_list[-1]
+        assert 'install' in result[0][-1]
+        assert result[0][-1][-2:] == ['vim', 'zsh']
+
+    def test_remove_single_package(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.yum_remove(Mock(), 'vim')
+            result = fake_run.call_args_list[-1]
+        assert 'remove' in result[0][-1]
+        assert result[0][-1][-1] == 'vim'
+
+    def test_remove_multiple_packages(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.yum_remove(Mock(), ['vim', 'zsh'])
+            result = fake_run.call_args_list[-1]
+        assert 'remove' in result[0][-1]
+        assert result[0][-1][-2:] == ['vim', 'zsh']
+
+
+class TestZypper(object):
+
+    def setup(self):
+        self.to_patch = 'ceph_deploy.util.pkg_managers.process.run'
+
+    def test_install_single_package(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.zypper(Mock(), 'vim')
+            result = fake_run.call_args_list[-1]
+        assert 'install' in result[0][-1]
+        assert result[0][-1][-1] == 'vim'
+
+    def test_install_multiple_packages(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.zypper(Mock(), ['vim', 'zsh'])
+            result = fake_run.call_args_list[-1]
+        assert 'install' in result[0][-1]
+        assert result[0][-1][-2:] == ['vim', 'zsh']
+
+    def test_remove_single_package(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.zypper_remove(Mock(), 'vim')
+            result = fake_run.call_args_list[-1]
+        assert 'remove' in result[0][-1]
+        assert result[0][-1][-1] == 'vim'
+
+    def test_remove_multiple_packages(self):
+        fake_run = Mock()
+        with patch(self.to_patch, fake_run):
+            pkg_managers.zypper_remove(Mock(), ['vim', 'zsh'])
+            result = fake_run.call_args_list[-1]
+        assert 'remove' in result[0][-1]
+        assert result[0][-1][-2:] == ['vim', 'zsh']
+