diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2010-01-21 17:17:02 +1300 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2010-01-21 17:17:02 +1300 |
commit | 9ddeac17f58273730be605a1f08097a15a3204d1 (patch) | |
tree | 1dfab9939d476b111a2f3403f2010f4e54ad7ef2 /source4 | |
parent | 17d6f56646b79ba1acecab6eb661cb6205c9b408 (diff) | |
download | samba-9ddeac17f58273730be605a1f08097a15a3204d1.tar.gz samba-9ddeac17f58273730be605a1f08097a15a3204d1.tar.bz2 samba-9ddeac17f58273730be605a1f08097a15a3204d1.zip |
pyxattr: Factor out helper functions.
Diffstat (limited to 'source4')
-rw-r--r-- | source4/scripting/python/samba/tests/xattr.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/source4/scripting/python/samba/tests/xattr.py b/source4/scripting/python/samba/tests/xattr.py index 7854f84c8a..9bfe52c67e 100644 --- a/source4/scripting/python/samba/tests/xattr.py +++ b/source4/scripting/python/samba/tests/xattr.py @@ -20,20 +20,26 @@ import samba.xattr_native, samba.xattr_tdb from samba.dcerpc import xattr from samba.ndr import ndr_pack -from testtools import TestCase, TestSkipped +from testtools.testcase import TestCase, TestSkipped import random import os class XattrTests(TestCase): + def _tmpfilename(self): + random.seed() + path = os.environ['SELFTEST_PREFIX'] + return os.path.join(path, "pytests"+str(int(100000*random.random()))) + + def _eadbpath(self): + return os.path.join(os.environ['SELFTEST_PREFIX'], "eadb.tdb") + def test_set_xattr_native(self): if not samba.xattr_native.is_xattr_supported(): raise TestSkipped() - random.seed() - path = os.environ['SELFTEST_PREFIX'] - tempf = os.path.join(path,"pytests"+str(int(100000*random.random()))) ntacl = xattr.NTACL() ntacl.version = 1 + tempf = self._tmpfilename() open(tempf, 'w').write("empty") try: samba.xattr_native.wrap_setxattr(tempf, "user.unittests", @@ -45,9 +51,7 @@ class XattrTests(TestCase): def test_set_and_get_native(self): if not samba.xattr_native.is_xattr_supported(): raise TestSkipped() - random.seed() - path = os.environ['SELFTEST_PREFIX'] - tempf = os.path.join(path,"pytests"+str(int(100000*random.random()))) + tempf = self._tmpfilename() reftxt = "this is a test" open(tempf, 'w').write("empty") try: @@ -59,45 +63,41 @@ class XattrTests(TestCase): os.unlink(tempf) def test_set_xattr_tdb(self): - path = os.environ['SELFTEST_PREFIX'] - random.seed() - tempf = os.path.join(path, "pytests"+str(int(100000*random.random()))) + tempf = self._tmpfilename() + eadb_path = self._eadbpath() ntacl = xattr.NTACL() ntacl.version = 1 open(tempf, 'w').write("empty") try: - samba.xattr_tdb.wrap_setxattr(os.path.join(path, "eadb.tdb"), + samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests", ndr_pack(ntacl)) finally: os.unlink(tempf) - os.unlink(os.path.join(path, "eadb.tdb")) + os.unlink(eadb_path) def test_set_tdb_not_open(self): - path = os.environ['SELFTEST_PREFIX'] - random.seed() - tempf = os.path.join(path, "pytests"+str(int(100000*random.random()))) + tempf = self._tmpfilename() ntacl = xattr.NTACL() ntacl.version = 1 open(tempf, 'w').write("empty") try: self.assertRaises(IOError, samba.xattr_tdb.wrap_setxattr, - os.path.join(path, "nonexistent","eadb.tdb"), tempf, + os.path.join("nonexistent", "eadb.tdb"), tempf, "user.unittests", ndr_pack(ntacl)) finally: os.unlink(tempf) def test_set_and_get_tdb(self): - path = os.environ['SELFTEST_PREFIX'] - random.seed() - tempf = os.path.join(path, "pytests"+str(int(100000*random.random()))) + tempf = self._tmpfilename() + eadb_path = self._eadbpath() reftxt = "this is a test" open(tempf, 'w').write("empty") try: - samba.xattr_tdb.wrap_setxattr(os.path.join(path, "eadb.tdb"), - tempf, "user.unittests", reftxt) - text = samba.xattr_tdb.wrap_getxattr( - os.path.join(path, "eadb.tdb"), tempf, "user.unittests") + samba.xattr_tdb.wrap_setxattr(eadb_path, tempf, "user.unittests", + reftxt) + text = samba.xattr_tdb.wrap_getxattr(eadb_path, tempf, + "user.unittests") self.assertEquals(text, reftxt) finally: os.unlink(tempf) - os.unlink(os.path.join(path, "eadb.tdb")) + os.unlink(eadb_path) |