~didrocks/ubuntuone-client/dont-suffer-zg-crash

« back to all changes in this revision

Viewing changes to tests/platform/test_os_helper.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-11 16:18:11 UTC
  • mfrom: (1.1.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20110211161811-lbelxu332e8r2dov
Tags: 1.5.4-0ubuntu1
* New upstream release.
  - Files still get downloaded from unsubscribed folder (LP: #682878)
  - Add subscription capabilities to shares (LP: #708335)
  - Nautilus offers Publish option within other's shares (LP: #712674)
  - Shares dir name may not be unique (LP: #715776)
  - Send a notification when new Volume is available (LP: #702055)
  - Add messaging menu entry for new Volumes (LP: #702075)
  - Aggregate notifications for completed operations (LP: #702128)
  - Send a notification for new Share offers (LP: #702138)
  - Add messaging menu entry for new Share offers (LP: #702144)
* Remove ubuntuone-client-tools as u1sync has been moved out.
* Simplify python package as we don't have multiple python packages now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# tests.platform.linux - linux platform tests
2
2
#
3
3
# Author: Guillermo Gonzalez <guillermo.gonzalez@canonical.com>
 
4
#         Manuel de la Pena <manuel@canonical.com>
4
5
#
5
6
# Copyright 2010 Canonical Ltd.
6
7
#
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/>.
18
19
 
19
 
"""Linux specific tests for the platform module."""
 
20
"""Test for the  os operations in the platform module."""
20
21
 
21
22
import errno
22
23
import os
23
24
 
24
25
from contrib.testing.testcase import BaseTwistedTestCase
25
 
from ubuntuone.platform.linux import (
 
26
from ubuntuone.platform import (
26
27
    access,
27
28
    allow_writes,
28
29
    listdir,
34
35
    rename,
35
36
    set_dir_readonly,
36
37
    set_dir_readwrite,
 
38
    set_no_rights,
37
39
    set_file_readonly,
38
40
    set_file_readwrite,
39
41
    stat_path,
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
 
54
        # in the tearDown.
 
55
        self.fd = open(self.testfile, 'w')
51
56
 
52
57
    def tearDown(self):
53
 
        self.rmtree(self.basedir)
 
58
        try:
 
59
            self.fd.close()
 
60
            self.rmtree(self.basedir)
 
61
        except Exception:
 
62
            pass
54
63
        BaseTwistedTestCase.tearDown(self)
55
64
 
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'))
60
69
 
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'))
67
76
 
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'))
74
83
 
90
99
 
91
100
    def test_path_file_exist_no(self):
92
101
        """Test that the file doesn't exist."""
 
102
        self.fd.close()
93
103
        os.remove(self.testfile)
94
104
        self.assertFalse(path_exists(self.testfile))
95
105
 
99
109
 
100
110
    def test_path_dir_exist_no(self):
101
111
        """Test that the dir doesn't exist."""
 
112
        self.fd.close()
102
113
        os.remove(self.testfile)
103
114
        self.assertFalse(path_exists(os.path.join(self.basedir, 'nodir')))
104
115
 
105
116
    def test_remove_file(self):
106
117
        """Test the remove file."""
 
118
        self.fd.close()
107
119
        remove_file(self.testfile)
108
120
        self.assertFalse(os.path.exists(self.testfile))
109
121
 
208
220
 
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)
214
226
 
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))
218
230
 
219
 
    def test_stat_symlink(self):
220
 
        """Test that it doesn't follow symlinks.
221
 
 
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.
225
 
        """
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)
230
 
 
231
231
    def test_stat_no_path(self):
232
232
        """Test that it raises proper error when no file is there."""
233
233
        try:
241
241
 
242
242
    def test_path_exists_file_no(self):
243
243
        """The file is not there."""
 
244
        self.fd.close()
244
245
        os.remove(self.testfile)
245
246
        self.assertFalse(path_exists(self.testfile))
246
247
 
250
251
 
251
252
    def test_path_exists_dir_no(self):
252
253
        """The dir is not there."""
 
254
        self.fd.close()
253
255
        self.rmtree(self.basedir)
254
256
        self.assertFalse(path_exists(self.basedir))