~ubuntu-branches/ubuntu/lucid/ubuntuone-client/lucid-updates

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_fsm.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2009-10-16 13:35:00 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091016133500-t2zacp5ozfj1hpug
Tags: 1.0.2-0ubuntu1
* New upstream release.
  - Avoid conflicts due to bouncing FS events (LP: #449605)
  - Don't try to authorize if connect on start is never (LP: #451154)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    METADATA_VERSION,
37
37
)
38
38
from ubuntuone.syncdaemon.volume_manager import Share, allow_writes
 
39
from ubuntuone.syncdaemon.event_queue import EventQueue
39
40
 
40
41
TESTS_DIR = os.path.join(os.getcwd(), "tmp")
41
42
 
62
63
        self.partials_dir = os.path.join(TESTS_DIR, "partials")
63
64
        self.fsm = FileSystemManager(self.fsmdir, self.partials_dir,
64
65
                                     FakeVolumeManager(self.root_dir))
 
66
        self.eq = EventQueue(self.fsm)
 
67
        self.fsm.register_eq(self.eq)
65
68
        self.share = self.create_share('share', 'share_name',
66
69
                                            self.fsm, self.shares_dir)
67
70
        self.share_path = self.share.path
68
71
 
69
72
    def tearDown(self):
70
73
        """ Clean up the tests. """
 
74
        self.eq.shutdown()
71
75
        self.rmtree(TESTS_DIR)
72
76
 
73
77
    @staticmethod
2090
2094
                os.chmod(os.path.join(dirpath, dir), 0777)
2091
2095
            for file in files:
2092
2096
                os.chmod(os.path.join(dirpath, file), 0666)
2093
 
        shutil.rmtree(TESTS_DIR)
 
2097
        FSMTestCase.tearDown(self)
2094
2098
 
2095
2099
    def test_file_ro_share_fail(self):
2096
2100
        """ Test that manual creation of a file, fails on a ro-share. """
2241
2245
        FSMTestCase.setUp(self)
2242
2246
        # create a ro share
2243
2247
        self.share_ro = self.create_share('share_ro', 'share_ro_name',
2244
 
                                       self.fsm, self.shares_dir, access_level='View')
 
2248
                                          self.fsm, self.shares_dir,
 
2249
                                          access_level='View')
2245
2250
        self.share_ro_path = self.share_ro.path
2246
2251
 
2247
2252
    def test_write_in_ro_share(self):
2248
2253
        """test the EnableShareWrite context manager in a ro share"""
2249
2254
        path = os.path.join(self.share_ro_path, 'foo', 'a_file_in_a_ro_share')
2250
2255
        data = 'yes I can write!'
2251
 
        can_write_parent = os.access(os.path.dirname(self.share_ro_path), os.W_OK)
 
2256
        can_write_parent = os.access(os.path.dirname(self.share_ro_path),
 
2257
                                     os.W_OK)
2252
2258
        with EnableShareWrite(self.share_ro, path):
2253
2259
            with open(path, 'w') as f:
2254
2260
                f.write(data)
2255
2261
        self.assertEquals(data, open(path, 'r').read())
2256
2262
        self.assertFalse(os.access(self.share_ro_path, os.W_OK))
2257
2263
        # check that the parent permissions are ok
2258
 
        self.assertEquals(can_write_parent, os.access(os.path.dirname(self.share_ro_path), os.W_OK))
 
2264
        self.assertEquals(can_write_parent,
 
2265
                          os.access(os.path.dirname(self.share_ro_path),
 
2266
                                    os.W_OK))
2259
2267
        # fail to write directly in the share
2260
2268
        self.assertRaises(IOError, open, path, 'w')
2261
2269
 
2291
2299
        os.makedirs(self.root_dir)
2292
2300
        self.data_dir = os.path.join(TESTS_DIR, "data")
2293
2301
        self.partials_dir = os.path.join(TESTS_DIR, "partials")
2294
 
        self.main = FakeMain(self.root_dir, self.shares_dir, self.data_dir, self.partials_dir)
 
2302
        self.main = FakeMain(self.root_dir, self.shares_dir,
 
2303
                             self.data_dir, self.partials_dir)
2295
2304
        self.fsm = self.main.fs
2296
2305
        self.share = self.create_share('share', 'share_name',
2297
2306
                                           self.fsm, self.shares_dir)
2300
2309
    def tearDown(self):
2301
2310
        """ Clean up the tests. """
2302
2311
        self.main.shutdown()
2303
 
        FSMTestCase.tearDown(self)
 
2312
        self.rmtree(TESTS_DIR)
2304
2313
 
2305
2314
 
2306
2315
    @staticmethod