~rye/ubuntuone-client/unique-check-is-unique

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_fsm.py

  • Committer: Tarmac
  • Author(s): facundo at com
  • Date: 2010-09-09 13:05:46 UTC
  • mfrom: (676.2.8 move-limbo)
  • Revision ID: tarmac-20100909130546-11g5qu3beajtesgh
Move operations live in limbo until confirmed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    FileSystemManager,
37
37
    InconsistencyError,
38
38
    METADATA_VERSION,
 
39
    TrashFileShelf,
39
40
)
40
41
from ubuntuone.syncdaemon.event_queue import EventQueue
41
42
from ubuntuone.syncdaemon import logger
 
43
from ubuntuone.syncdaemon.interfaces import IMarker
 
44
from ubuntuone.syncdaemon.marker import MDMarker
42
45
from ubuntuone.syncdaemon.volume_manager import Share, allow_writes
43
46
 
44
47
TESTS_DIR = os.path.join(os.getcwd(), "tmp")
2122
2125
        self.assertTrue(os.path.exists(tdir1))
2123
2126
        self.assertTrue(self.fsm.get_by_mdid(mdid1))
2124
2127
 
 
2128
    def test_movelimbo(self):
 
2129
        """Test that a node is sent to and removed from the move limbo."""
 
2130
        testfile = os.path.join(self.share_path, "path")
 
2131
        open(testfile, "w").close()
 
2132
        self.fsm.create(testfile, "share")
 
2133
        self.fsm.set_node_id(testfile, "uuid")
 
2134
        self.assertEqual(self.fsm.move_limbo, {})
 
2135
        self.assertEqual(list(self.fsm.get_iter_move_limbo()), [])
 
2136
 
 
2137
        # move to limbo
 
2138
        self.fsm.add_to_move_limbo("share", "uuid", "old_parent",
 
2139
                                   "new_parent", "new_name")
 
2140
        d = {("share", "uuid"): ("old_parent", "new_parent", "new_name")}
 
2141
        self.assertEqual(self.fsm.move_limbo, d)
 
2142
        r = [("share", "uuid", "old_parent", "new_parent", "new_name")]
 
2143
        self.assertEqual(list(self.fsm.get_iter_move_limbo()), r)
 
2144
 
 
2145
        # remove from limbo
 
2146
        self.fsm.remove_from_move_limbo("share", "uuid")
 
2147
        self.assertEqual(self.fsm.move_limbo, {})
 
2148
        self.assertEqual(list(self.fsm.get_iter_move_limbo()), [])
 
2149
 
2125
2150
    def test_trash_normal(self):
2126
2151
        """Test that a node is sent to and removed from trash."""
2127
2152
        testfile = os.path.join(self.share_path, "path")
3233
3258
        self.assertTrue(mdid4 in dirty_mdids)
3234
3259
 
3235
3260
 
 
3261
class TrashFileShelfTests(unittest.TestCase):
 
3262
    """Test the customized file shelf."""
 
3263
 
 
3264
    def setUp(self):
 
3265
        """Set up."""
 
3266
        try:
 
3267
            os.mkdir(TESTS_DIR)
 
3268
        except OSError:
 
3269
            # already there, remove it to clean and create again
 
3270
            shutil.rmtree(TESTS_DIR)
 
3271
            os.mkdir(TESTS_DIR)
 
3272
 
 
3273
        self.tfs = TrashFileShelf(os.path.join(TESTS_DIR, "trash"))
 
3274
 
 
3275
    def tearDown(self):
 
3276
        """Tear down."""
 
3277
        shutil.rmtree(TESTS_DIR)
 
3278
 
 
3279
    def test_one_value(self):
 
3280
        """Test the file shelf with one value."""
 
3281
        self.tfs[("foo", "bar")] = 'value'
 
3282
 
 
3283
        self.assertEqual(self.tfs[("foo", "bar")], 'value')
 
3284
        self.assertEqual(list(self.tfs.keys()), [("foo", "bar")])
 
3285
 
 
3286
    def test_two_values(self):
 
3287
        """Test the file shelf with two values."""
 
3288
        self.tfs[("foo", "bar")] = 'value1'
 
3289
        self.tfs[("xyz", "hfb")] = 'value2'
 
3290
 
 
3291
        self.assertEqual(self.tfs[("foo", "bar")], 'value1')
 
3292
        self.assertEqual(self.tfs[("xyz", "hfb")], 'value2')
 
3293
        self.assertEqual(sorted(self.tfs.keys()),
 
3294
                         [("foo", "bar"), ("xyz", "hfb")])
 
3295
 
 
3296
    def test_node_id_None(self):
 
3297
        """node_id can be None."""
 
3298
        self.tfs[("foo", None)] = 'value'
 
3299
        self.assertEqual(self.tfs[("foo", None)], 'value')
 
3300
        self.assertEqual(list(self.tfs.keys()), [("foo", None)])
 
3301
 
 
3302
    def test_node_id_marker(self):
 
3303
        """node_id can be a marker."""
 
3304
        marker = MDMarker("bar")
 
3305
        self.tfs[("foo", marker)] = 'value'
 
3306
        self.assertEqual(self.tfs[("foo", marker)], 'value')
 
3307
        self.assertEqual(list(self.tfs.keys()), [("foo", marker)])
 
3308
        node_id = list(self.tfs.keys())[0][1]
 
3309
        self.assertTrue(IMarker.providedBy(node_id))
 
3310
 
 
3311
    def test_share_id_marker(self):
 
3312
        """share_id can be a marker."""
 
3313
        marker = MDMarker("bar")
 
3314
        self.tfs[(marker, "foo")] = 'value'
 
3315
        self.assertEqual(self.tfs[(marker, "foo")], 'value')
 
3316
        self.assertEqual(list(self.tfs.keys()), [(marker, "foo")])
 
3317
        share_id = list(self.tfs.keys())[0][0]
 
3318
        self.assertTrue(IMarker.providedBy(share_id))
 
3319
 
 
3320
 
3236
3321
def test_suite():
3237
3322
    # pylint: disable-msg=C0111
3238
3323
    return unittest.TestLoader().loadTestsFromName(__name__)