summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-16 09:35:31 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-16 09:35:31 -0400
commitad0798f9e7fe105fa1314daf0213d8d3d50bd2e1 (patch)
treea9284654c50ed3403b7c2556e2526363ad2ecba7 /testsuite
parent4efd4785d9e919ed3abf57377487475dc89de5c5 (diff)
downloadbcfg2-ad0798f9e7fe105fa1314daf0213d8d3d50bd2e1.tar.gz
bcfg2-ad0798f9e7fe105fa1314daf0213d8d3d50bd2e1.tar.bz2
bcfg2-ad0798f9e7fe105fa1314daf0213d8d3d50bd2e1.zip
use common test libs for POSIX tests
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py9
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py9
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py9
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py9
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py9
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py9
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py9
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py56
8 files changed, 42 insertions, 77 deletions
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py
index 7d64c5a2e..ba25c9bea 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py
@@ -5,19 +5,14 @@ import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Client.Tools.POSIX.Device import *
from Test__init import get_posix_object
-
-def call(*args, **kwargs):
- """ the Mock call object is a fairly recent addition, but it's
- very very useful, so we create our own function to create Mock
- calls """
- return (args, kwargs)
+from .....common import *
def get_device_object(posix=None):
if posix is None:
posix = get_posix_object()
return POSIXDevice(posix.logger, posix.setup, posix.config)
-class TestPOSIXDevice(unittest.TestCase):
+class TestPOSIXDevice(Bcfg2TestCase):
def test_fully_specified(self):
ptool = get_device_object()
orig_entry = lxml.etree.Element("Path", name="/test", type="device",
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py
index 021ed8113..41e1a3f00 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py
@@ -6,19 +6,14 @@ import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Client.Tools.POSIX.Directory import *
from Test__init import get_posix_object
-
-def call(*args, **kwargs):
- """ the Mock call object is a fairly recent addition, but it's
- very very useful, so we create our own function to create Mock
- calls """
- return (args, kwargs)
+from .....common import *
def get_directory_object(posix=None):
if posix is None:
posix = get_posix_object()
return POSIXDirectory(posix.logger, posix.setup, posix.config)
-class TestPOSIXDirectory(unittest.TestCase):
+class TestPOSIXDirectory(Bcfg2TestCase):
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool.verify")
@patch("Bcfg2.Client.Tools.POSIX.Directory.POSIXDirectory._exists")
def test_verify(self, mock_exists, mock_verify):
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py
index e663973c7..2f1b0c920 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py
@@ -5,19 +5,14 @@ import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Client.Tools.POSIX.Hardlink import *
from Test__init import get_posix_object
-
-def call(*args, **kwargs):
- """ the Mock call object is a fairly recent addition, but it's
- very very useful, so we create our own function to create Mock
- calls """
- return (args, kwargs)
+from .....common import *
def get_hardlink_object(posix=None):
if posix is None:
posix = get_posix_object()
return POSIXHardlink(posix.logger, posix.setup, posix.config)
-class TestPOSIXHardlink(unittest.TestCase):
+class TestPOSIXHardlink(Bcfg2TestCase):
@patch("os.path.samefile")
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool.verify")
def test_verify(self, mock_verify, mock_samefile):
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py
index 38f3b6ee3..9ac23921c 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py
@@ -5,19 +5,14 @@ import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Client.Tools.POSIX.Nonexistent import *
from Test__init import get_config, get_posix_object
-
-def call(*args, **kwargs):
- """ the Mock call object is a fairly recent addition, but it's
- very very useful, so we create our own function to create Mock
- calls """
- return (args, kwargs)
+from .....common import *
def get_nonexistent_object(posix=None):
if posix is None:
posix = get_posix_object()
return POSIXNonexistent(posix.logger, posix.setup, posix.config)
-class TestPOSIXNonexistent(unittest.TestCase):
+class TestPOSIXNonexistent(Bcfg2TestCase):
@patch("os.path.lexists")
def test_verify(self, mock_lexists):
entry = lxml.etree.Element("Path", name="/test", type="nonexistent")
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py
index 94b74dd13..f1746e34a 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py
@@ -4,18 +4,13 @@ import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Client.Tools.POSIX.Permissions import *
from Test__init import get_posix_object
-
-def call(*args, **kwargs):
- """ the Mock call object is a fairly recent addition, but it's
- very very useful, so we create our own function to create Mock
- calls """
- return (args, kwargs)
+from .....common import *
def get_permissions_object(posix=None):
if posix is None:
posix = get_posix_object()
return POSIXPermissions(posix.logger, posix.setup, posix.config)
-class TestPOSIXPermissions(unittest.TestCase):
+class TestPOSIXPermissions(Bcfg2TestCase):
# nothing to test!
pass
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py
index a3ed9f68d..d9a2717dd 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py
@@ -5,19 +5,14 @@ import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Client.Tools.POSIX.Symlink import *
from Test__init import get_posix_object
-
-def call(*args, **kwargs):
- """ the Mock call object is a fairly recent addition, but it's
- very very useful, so we create our own function to create Mock
- calls """
- return (args, kwargs)
+from .....common import *
def get_symlink_object(posix=None):
if posix is None:
posix = get_posix_object()
return POSIXSymlink(posix.logger, posix.setup, posix.config)
-class TestPOSIXSymlink(unittest.TestCase):
+class TestPOSIXSymlink(Bcfg2TestCase):
@patch("os.readlink")
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool.verify")
def test_verify(self, mock_verify, mock_readlink):
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py
index 952bb02dd..e55ab4410 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py
@@ -4,12 +4,7 @@ import lxml.etree
from mock import Mock, MagicMock, patch
import Bcfg2.Client.Tools
import Bcfg2.Client.Tools.POSIX
-
-def call(*args, **kwargs):
- """ the Mock call object is a fairly recent addition, but it's
- very very useful, so we create our own function to create Mock
- calls """
- return (args, kwargs)
+from .....common import *
def get_config(entries):
config = lxml.etree.Element("Configuration")
@@ -33,7 +28,7 @@ def get_posix_object(logger=None, setup=None, config=None):
return Bcfg2.Client.Tools.POSIX.POSIX(logger, setup, config)
-class TestPOSIX(unittest.TestCase):
+class TestPOSIX(Bcfg2TestCase):
def test__init(self):
entries = [lxml.etree.Element("Path", name="test", type="file")]
p = get_posix_object(config=get_config(entries))
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
index 6226eb802..7bc26e03d 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py
@@ -7,6 +7,7 @@ from mock import Mock, MagicMock, patch
import Bcfg2.Client.Tools
from Bcfg2.Client.Tools.POSIX.base import *
from Test__init import get_posix_object
+from .....common import *
try:
import selinux
@@ -20,28 +21,27 @@ try:
except ImportError:
has_acls = False
-def call(*args, **kwargs):
- """ the Mock call object is a fairly recent addition, but it's
- very very useful, so we create our own function to create Mock
- calls """
- return (args, kwargs)
-
def get_posixtool_object(posix=None):
if posix is None:
posix = get_posix_object()
return POSIXTool(posix.logger, posix.setup, posix.config)
-class TestPOSIXTool(unittest.TestCase):
+class TestPOSIXTool(Bcfg2TestCase):
+ test_obj = POSIXTool
+
+ def get_obj(self, posix=None):
+ return get_posixtool_object(posix)
+
def test_fully_specified(self):
# fully_specified should do no checking on the abstract
# POSIXTool object
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
self.assertTrue(ptool.fully_specified(Mock()))
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool._verify_metadata")
def test_verify(self, mock_verify):
entry = lxml.etree.Element("Path", name="/test", type="file")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
with patch('os.stat') as mock_stat, patch('os.walk') as mock_walk:
mock_stat.return_value = MagicMock()
@@ -71,7 +71,7 @@ class TestPOSIXTool(unittest.TestCase):
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool._set_perms")
def test_install(self, mock_set_perms):
entry = lxml.etree.Element("Path", name="/test", type="file")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
mock_set_perms.return_value = True
self.assertTrue(ptool.install(entry))
@@ -115,7 +115,7 @@ class TestPOSIXTool(unittest.TestCase):
@patch("shutil.rmtree")
def test_exists(self, mock_rmtree, mock_unlink):
entry = lxml.etree.Element("Path", name="/etc/foo", type="file")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
with patch('os.lstat') as mock_lstat, \
patch("os.path.isdir") as mock_isdir:
mock_lstat.side_effect = OSError
@@ -172,7 +172,7 @@ class TestPOSIXTool(unittest.TestCase):
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool._set_secontext")
def test_set_perms(self, mock_set_secontext, mock_set_acls, mock_norm_gid,
mock_norm_uid, mock_utime, mock_chmod, mock_chown):
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
def reset():
mock_set_secontext.reset_mock()
@@ -290,7 +290,7 @@ class TestPOSIXTool(unittest.TestCase):
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool._list_entry_acls")
def test_set_acls(self, mock_list_entry_acls, mock_norm_gid, mock_norm_uid):
entry = lxml.etree.Element("Path", name="/etc/foo", type="file")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
# disable acls for the initial test
Bcfg2.Client.Tools.POSIX.base.has_acls = False
@@ -430,7 +430,7 @@ class TestPOSIXTool(unittest.TestCase):
@unittest.skipUnless(has_selinux, "SELinux not found, skipping")
def test_set_secontext(self):
entry = lxml.etree.Element("Path", name="/etc/foo", type="file")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
# disable selinux for the initial test
Bcfg2.Client.Tools.POSIX.base.has_selinux = False
@@ -468,7 +468,7 @@ class TestPOSIXTool(unittest.TestCase):
@patch("grp.getgrnam")
def test_norm_gid(self, mock_getgrnam):
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
self.assertEqual(5, ptool._norm_gid("5"))
self.assertFalse(mock_getgrnam.called)
@@ -481,7 +481,7 @@ class TestPOSIXTool(unittest.TestCase):
def test_norm_entry_gid(self, mock_norm_gid):
entry = lxml.etree.Element("Path", name="/test", type="file",
group="group", owner="user")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
mock_norm_gid.return_value = 10
self.assertEqual(10, ptool._norm_entry_gid(entry))
mock_norm_gid.assert_called_with(entry.get("group"))
@@ -493,7 +493,7 @@ class TestPOSIXTool(unittest.TestCase):
@patch("pwd.getpwnam")
def test_norm_uid(self, mock_getpwnam):
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
self.assertEqual(5, ptool._norm_uid("5"))
self.assertFalse(mock_getpwnam.called)
@@ -507,7 +507,7 @@ class TestPOSIXTool(unittest.TestCase):
def test_norm_entry_uid(self, mock_norm_uid):
entry = lxml.etree.Element("Path", name="/test", type="file",
group="group", owner="user")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
mock_norm_uid.return_value = 10
self.assertEqual(10, ptool._norm_entry_uid(entry))
mock_norm_uid.assert_called_with(entry.get("owner"))
@@ -518,12 +518,12 @@ class TestPOSIXTool(unittest.TestCase):
mock_norm_uid.assert_called_with(entry.get("owner"))
def test_norm_acl_perms(self):
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
# there's basically no reasonably way to test the Permset
# object parsing feature without writing our own Mock object
# that re-implements Permset.test(). silly pylibacl won't let
# us create standalone Entry or Permset objects.
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
self.assertEqual(5, ptool._norm_acl_perms("5"))
self.assertEqual(0, ptool._norm_acl_perms("55"))
self.assertEqual(5, ptool._norm_acl_perms("rx"))
@@ -537,7 +537,7 @@ class TestPOSIXTool(unittest.TestCase):
def test__gather_data(self):
path = '/test'
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
# have to use context manager version of patch here because
# os.stat must be unpatched when we instantiate the object to
@@ -579,7 +579,7 @@ class TestPOSIXTool(unittest.TestCase):
def test__gather_data_selinux(self):
context = 'system_u:object_r:root_t:s0'
path = '/test'
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
with patch("selinux.getfilecon") as mock_getfilecon, \
patch('os.stat') as mock_stat:
mock_getfilecon.return_value = [len(context) + 1, context]
@@ -598,7 +598,7 @@ class TestPOSIXTool(unittest.TestCase):
("access", posix1e.ACL_GROUP, "testgroup"): "rx"}
mock_list_file_acls.return_value = acls
path = '/test'
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
with patch('os.stat') as mock_stat:
mock_stat.return_value = MagicMock()
# disable selinux for this call and test it separately
@@ -621,7 +621,7 @@ class TestPOSIXTool(unittest.TestCase):
# can start fresh every time
orig_entry = copy.deepcopy(entry)
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
def reset():
mock_gather_data.reset_mock()
@@ -781,7 +781,7 @@ class TestPOSIXTool(unittest.TestCase):
user="user", perms="rwx")
lxml.etree.SubElement(entry, "ACL", scope="group", type="access",
group="group", perms="5")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
self.assertItemsEqual(ptool._list_entry_acls(entry),
{("default", posix1e.ACL_USER, "user"): 7,
("access", posix1e.ACL_GROUP, "group"): 5})
@@ -791,7 +791,7 @@ class TestPOSIXTool(unittest.TestCase):
@patch("grp.getgrgid")
def test_list_file_acls(self, mock_getgrgid, mock_getpwuid):
path = '/test'
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
with patch("posix1e.ACL") as mock_ACL, \
patch("os.path.isdir") as mock_isdir:
# build a set of file ACLs to return from posix1e.ACL(file=...)
@@ -876,7 +876,7 @@ class TestPOSIXTool(unittest.TestCase):
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool._list_entry_acls")
def test_verify_acls(self, mock_list_entry_acls, mock_list_file_acls):
entry = lxml.etree.Element("Path", name="/test", type="file")
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
# we can't test to make sure that errors get properly sorted
# into (missing, extra, wrong) without refactoring the
# _verify_acls code, and I don't feel like doing that, so eff
@@ -934,7 +934,7 @@ class TestPOSIXTool(unittest.TestCase):
mock_set_perms.reset_mock()
mock_makedirs.reset_mock()
- ptool = get_posixtool_object()
+ ptool = self.get_obj()
mock_set_perms.return_value = True
def path_exists_rv(path):
if path == "/test":