1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-28 11:42:03 +03:00

pyxattr: Factor out helper functions.

This commit is contained in:
Jelmer Vernooij
2010-01-21 17:17:02 +13:00
parent 17d6f56646
commit 9ddeac17f5

View File

@ -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)