16
17
# You should have received a copy of the GNU General Public License along
17
18
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""Linux specific tests for the platform module."""
20
"""Test for the os operations in the platform module."""
24
25
from contrib.testing.testcase import BaseTwistedTestCase
25
from ubuntuone.platform.linux import (
26
from ubuntuone.platform import (
47
49
BaseTwistedTestCase.setUp(self)
48
50
self.basedir = self.mktemp('test_root')
49
51
self.testfile = os.path.join(self.basedir, "test_file")
50
open(self.testfile, 'w').close()
52
# although open(self.testfile, 'w').close() is possible on linux,
53
# on windows we will have issues. Lets remember the fd and close it
55
self.fd = open(self.testfile, 'w')
52
57
def tearDown(self):
53
self.rmtree(self.basedir)
60
self.rmtree(self.basedir)
54
63
BaseTwistedTestCase.tearDown(self)
56
65
def test_set_dir_readonly(self):
57
66
"""Test for set_dir_readonly."""
58
67
set_dir_readonly(self.basedir)
59
self.assertRaises(OSError, os.mkdir, os.path.join(self.basedir, 'foo'))
68
self.assertRaises(OSError, make_dir, os.path.join(self.basedir, 'foo'))
61
70
def test_set_dir_readwrite(self):
62
71
"""Test for set_dir_readwrite."""
63
72
set_dir_readonly(self.basedir)
64
self.assertRaises(OSError, os.mkdir, os.path.join(self.basedir, 'foo'))
73
self.assertRaises(OSError, make_dir, os.path.join(self.basedir, 'foo'))
65
74
set_dir_readwrite(self.basedir)
66
75
os.mkdir(os.path.join(self.basedir, 'foo'))
68
77
def test_allow_writes(self):
69
78
"""Test for allow_writes."""
70
79
set_dir_readonly(self.basedir)
71
self.assertRaises(OSError, os.mkdir, os.path.join(self.basedir, 'foo'))
80
self.assertRaises(OSError, make_dir, os.path.join(self.basedir, 'foo'))
72
81
with allow_writes(self.basedir):
73
82
os.mkdir(os.path.join(self.basedir, 'foo'))
100
110
def test_path_dir_exist_no(self):
101
111
"""Test that the dir doesn't exist."""
102
113
os.remove(self.testfile)
103
114
self.assertFalse(path_exists(os.path.join(self.basedir, 'nodir')))
105
116
def test_remove_file(self):
106
117
"""Test the remove file."""
107
119
remove_file(self.testfile)
108
120
self.assertFalse(os.path.exists(self.testfile))
209
221
def test_access_nothing(self):
210
222
"""Test access on a file with no permission at all."""
211
os.chmod(self.testfile, 0o000)
223
set_no_rights(self.testfile)
212
224
self.assertFalse(access(self.testfile))
213
os.chmod(self.testfile, 0o664)
225
set_file_readwrite(self.testfile)
215
227
def test_stat_normal(self):
216
228
"""Test on a normal file."""
217
229
self.assertEqual(os.stat(self.testfile), stat_path(self.testfile))
219
def test_stat_symlink(self):
220
"""Test that it doesn't follow symlinks.
222
We compare the inode only (enough to see if it's returning info
223
from the link or the linked), as we can not compare the full stat
224
because the st_mode will be different.
226
link = os.path.join(self.basedir, 'foo')
227
os.symlink(self.testfile, link)
228
self.assertNotEqual(os.stat(link).st_ino, stat_path(link).st_ino)
229
self.assertEqual(os.lstat(link).st_ino, stat_path(link).st_ino)
231
231
def test_stat_no_path(self):
232
232
"""Test that it raises proper error when no file is there."""