]> git.k1024.org Git - pylibacl.git/blob - test/test_acls.py
Allow use of a diferent path for temporary files
[pylibacl.git] / test / test_acls.py
1 #
2 #
3
4 import unittest
5 import os
6 import tempfile
7
8 import posix1e
9
10 TEST_DIR=os.environ.get("TESTDIR", ".")
11
12 class aclTest(unittest.TestCase):
13     """Unittests for ACLs"""
14
15     def setUp(self):
16         """set up function"""
17         self.rmfiles = []
18         self.rmdirs = []
19
20     def tearDown(self):
21         """tear down function"""
22         for fname in self.rmfiles:
23             os.unlink(fname)
24         for dname in self.rmdirs:
25             os.rmdir(dname)
26
27     def _getfile(self):
28         """create a temp file"""
29         fh, fname = tempfile.mkstemp(".test", "xattr-", TEST_DIR)
30         self.rmfiles.append(fname)
31         return fh, fname
32
33     def _getdir(self):
34         """create a temp dir"""
35         dname = tempfile.mkdtemp(".test", "xattr-", TEST_DIR)
36         self.rmdirs.append(dname)
37         return dname
38
39     def _getsymlink(self):
40         """create a symlink"""
41         fh, fname = self._getfile()
42         os.close(fh)
43         os.unlink(fname)
44         os.symlink(fname + ".non-existent", fname)
45         return fname
46
47     def testFromFile(self):
48         """Test loading ACLs from a file"""
49         _, fname = self._getfile()
50         acl1 = posix1e.ACL(file=fname)
51         self.failUnless(acl1.valid(), "ACL is not valid")
52
53     def testFromDir(self):
54         """Test loading ACLs from a directory"""
55         dname = self._getdir()
56         acl1 = posix1e.ACL(file=dname)
57         acl2 = posix1e.ACL(filedef=dname)
58         self.failUnless(acl1.valid(), "ACL is not valid")
59         # default ACLs might or might not be valid; missing ones are
60         # not valid, so we don't test acl2 for validity
61
62     def testFromFd(self):
63         """Test loading ACLs from a file descriptor"""
64         fd, _ = self._getfile()
65         acl1 = posix1e.ACL(fd=fd)
66         self.failUnless(acl1.valid(), "ACL is not valid")
67
68     if posix1e.HAS_ACL_FROM_MODE:
69         def testFromMode(self):
70             """Test loading ACLs from an octal mode"""
71             acl1 = posix1e.ACL(mode=0644)
72             self.failUnless(acl1.valid(), "ACL is not valid")
73     else:
74         def testFromMode(self):
75             """Test loading ACLs from an octal mode (SKIPPED)"""
76
77     def testFromEmpty(self):
78         """Test creating an empty ACL"""
79         acl1 = posix1e.ACL()
80
81
82 if __name__ == "__main__":
83     unittest.main()