2152
2182
self.assertEqual(list(self.fsm.get_iter_trash()),
2153
2183
[("share", "uuid", "parent")])
2155
def test_local_changed_empty_dir(self):
2156
"""Test the recursive changed feature for a node."""
2157
local_dir = os.path.join(self.root_dir, "foo")
2159
mdid = self.fsm.create(local_dir, "", is_dir=True)
2160
self.fsm.set_node_id(local_dir, "uuid")
2162
# local_hash differs from server_hash for local_dir
2163
self.fsm.set_by_mdid(mdid, local_hash=98765)
2165
assert len(os.listdir(local_dir)) == 0 # local_dir is empty
2166
self.assertTrue(self.fsm.local_changed(path=local_dir))
2168
def test_local_changed_non_empty_dir(self):
2169
"""Test the recursive changed feature for a non empty dir."""
2170
local_dir = os.path.join(self.root_dir, "foo")
2172
self.fsm.create(local_dir, "", is_dir=True)
2173
self.fsm.set_node_id(local_dir, "uuid")
2175
sub_dir = os.path.join(local_dir, "bar")
2177
mdid_subdir = self.fsm.create(sub_dir, "", is_dir=True)
2178
self.fsm.set_node_id(sub_dir, "uuid_subdir")
2180
assert len(os.listdir(local_dir)) > 0 # local_dir is not empty
2181
self.assertFalse(self.fsm.local_changed(path=local_dir))
2183
# local_hash differs from server_hash for sub_dir
2184
self.fsm.set_by_mdid(mdid_subdir, local_hash=98765)
2186
self.assertTrue(self.fsm.local_changed(path=local_dir))
2185
def test_trash_with_node_in_none(self):
2186
"""Test that in trash is saved the marker if node_id is None."""
2187
testfile = os.path.join(self.share_path, "path")
2188
open(testfile, "w").close()
2189
mdid = self.fsm.create(testfile, "share")
2191
# delete to trash and check the marker
2192
self.fsm.delete_to_trash(mdid, "parent")
2193
marker = MDMarker(mdid)
2194
self.assertEqual(self.fsm.trash,
2195
{("share", marker): (mdid, "parent", testfile)})
2197
def test_dereference_ok_limbos_none(self):
2198
"""Limbos' markers ok dereferencing is fine if no marker at all."""
2199
self.fsm.dereference_ok_limbos('nothing', "foo")
2201
def test_dereference_err_limbos_none(self):
2202
"""Limbos' markers err dereferencing is fine if no marker at all."""
2203
self.fsm.dereference_err_limbos('nothing')
2205
def test_dereference_ok_trash_node(self):
2206
"""Dereference possible marker in trash, node."""
2208
testfile = os.path.join(self.share_path, "path")
2209
mdid = self.fsm.create(testfile, "share")
2210
self.fsm.set_node_id(testfile, "mrkr")
2211
self.fsm.delete_to_trash(mdid, "parent")
2213
# dereference and test
2214
self.fsm.dereference_ok_limbos("mrkr", "final")
2215
self.assertFalse(self.fsm.node_in_trash("share", "mrkr"))
2216
self.assertTrue(self.fsm.node_in_trash("share", "final"))
2217
self.assertTrue(self.handler.check_debug("dereference ok trash",
2220
def test_dereference_ok_trash_parent(self):
2221
"""Dereference possible marker in trash, parent."""
2223
testfile = os.path.join(self.share_path, "path")
2224
mdid = self.fsm.create(testfile, "share")
2225
self.fsm.set_node_id(testfile, "node")
2226
self.fsm.delete_to_trash(mdid, "mrkr")
2228
# dereference and test
2229
self.fsm.dereference_ok_limbos("mrkr", "final")
2230
self.assertEqual(self.fsm.trash[("share", "node")][1], "final")
2231
self.assertTrue(self.handler.check_debug("dereference ok trash",
2232
"marker", "parent"))
2234
def test_dereference_ok_trash_parent_node(self):
2235
"""An unlinked node can be a parent of other."""
2237
testfile = os.path.join(self.share_path, "path1")
2238
mdid = self.fsm.create(testfile, "share")
2239
self.fsm.set_node_id(testfile, "mrkr")
2240
self.fsm.delete_to_trash(mdid, "parent")
2243
testfile = os.path.join(self.share_path, "path2")
2244
mdid = self.fsm.create(testfile, "share")
2245
self.fsm.set_node_id(testfile, "node")
2246
self.fsm.delete_to_trash(mdid, "mrkr")
2248
# dereference and test
2249
self.fsm.dereference_ok_limbos("mrkr", "final")
2250
self.assertFalse(self.fsm.node_in_trash("share", "mrkr"))
2251
self.assertTrue(self.fsm.node_in_trash("share", "final"))
2252
self.assertEqual(self.fsm.trash[("share", "node")][1], "final")
2254
def test_dereference_err_trash_node(self):
2255
"""Dereference with error possible marker in trash, node."""
2257
testfile = os.path.join(self.share_path, "path")
2258
mdid = self.fsm.create(testfile, "share")
2259
self.fsm.set_node_id(testfile, "mrkr")
2260
self.fsm.delete_to_trash(mdid, "parent")
2262
# dereference and test
2263
self.fsm.dereference_err_limbos("mrkr")
2264
self.assertFalse(self.fsm.node_in_trash("share", "mrkr"))
2265
self.assertTrue(self.handler.check_debug("dereference err trash", "marker"))
2267
def test_dereference_err_trash_parent(self):
2268
"""Dereference with error possible marker in trash, parent."""
2270
testfile = os.path.join(self.share_path, "path")
2271
mdid = self.fsm.create(testfile, "share")
2272
self.fsm.set_node_id(testfile, "node")
2273
self.fsm.delete_to_trash(mdid, "mrkr")
2275
# dereference and test
2276
self.fsm.dereference_err_limbos("mrkr")
2277
self.assertFalse(self.fsm.node_in_trash("share", "node"))
2278
self.assertTrue(self.handler.check_debug("dereference err trash", "marker"))
2280
def test_dereference_err_trash_parent_node(self):
2281
"""An unlinked node can be a parent of other, both with failure."""
2283
testfile = os.path.join(self.share_path, "path1")
2284
mdid = self.fsm.create(testfile, "share")
2285
self.fsm.set_node_id(testfile, "mrkr")
2286
self.fsm.delete_to_trash(mdid, "parent")
2289
testfile = os.path.join(self.share_path, "path2")
2290
mdid = self.fsm.create(testfile, "share")
2291
self.fsm.set_node_id(testfile, "node")
2292
self.fsm.delete_to_trash(mdid, "mrkr")
2294
# dereference and test
2295
self.fsm.dereference_err_limbos("mrkr")
2296
self.assertFalse(self.fsm.node_in_trash("share", "mrkr"))
2297
self.assertFalse(self.fsm.node_in_trash("share", "node"))
2299
def test_dereference_ok_movelimbo_node(self):
2300
"""Dereference possible marker in move limbo, node."""
2302
self.fsm.add_to_move_limbo("sh", "mrkr", "oldparent", "newparent", "x")
2304
# dereference and test
2305
self.fsm.dereference_ok_limbos("mrkr", "final")
2306
self.assertFalse(("sh", "mrkr") in self.fsm.move_limbo)
2307
self.assertTrue(("sh", "final") in self.fsm.move_limbo)
2308
self.assertTrue(self.handler.check_debug("dereference ok move limbo",
2311
def test_dereference_ok_movelimbo_oldparent(self):
2312
"""Dereference possible marker in move limbo, oldparent."""
2314
self.fsm.add_to_move_limbo("sh", "node", "mrkr", "newparent", "x")
2316
# dereference and test
2317
self.fsm.dereference_ok_limbos("mrkr", "final")
2318
self.assertEqual(self.fsm.move_limbo[("sh", "node")],
2319
("final", "newparent", "x"))
2320
self.assertTrue(self.handler.check_debug("dereference ok move limbo",
2321
"marker", "old_parent"))
2323
def test_dereference_ok_movelimbo_newparent(self):
2324
"""Dereference possible marker in move limbo, newparent."""
2326
self.fsm.add_to_move_limbo("sh", "node", "oldparent", "mrkr", "x")
2328
# dereference and test
2329
self.fsm.dereference_ok_limbos("mrkr", "final")
2330
self.assertEqual(self.fsm.move_limbo[("sh", "node")],
2331
("oldparent", "final", "x"))
2332
self.assertTrue(self.handler.check_debug("dereference ok move limbo",
2333
"marker", "new_parent"))
2335
def test_dereference_ok_movelimbo_bothparents(self):
2336
"""Dereference possible marker in move limbo, both parents."""
2338
self.fsm.add_to_move_limbo("sh", "node", "mrkr", "mrkr", "x")
2340
# dereference and test
2341
self.fsm.dereference_ok_limbos("mrkr", "final")
2342
self.assertEqual(self.fsm.move_limbo[("sh", "node")],
2343
("final", "final", "x"))
2345
def test_dereference_err_movelimbo_node(self):
2346
"""Dereference with error possible marker in move limbo, node."""
2348
self.fsm.add_to_move_limbo("sh", "mrkr", "oldparent", "newparent", "x")
2350
# dereference and test
2351
self.fsm.dereference_err_limbos("mrkr")
2352
self.assertFalse(("sh", "mrkr") in self.fsm.move_limbo)
2353
self.assertTrue(self.handler.check_debug("dereference err move limbo",
2356
def test_dereference_err_movelimbo_oldparent(self):
2357
"""Dereference with error possible marker in move limbo, oldparent."""
2359
self.fsm.add_to_move_limbo("sh", "node", "mrkr", "newparent", "x")
2361
# dereference and test
2362
self.fsm.dereference_err_limbos("mrkr")
2363
self.assertFalse(("sh", "node") in self.fsm.move_limbo)
2364
self.assertTrue(self.handler.check_debug("dereference err move limbo",
2367
def test_dereference_err_movelimbo_newparent(self):
2368
"""Dereference with error possible marker in move limbo, newparent."""
2370
self.fsm.add_to_move_limbo("sh", "node", "oldparent", "mrkr", "x")
2372
# dereference and test
2373
self.fsm.dereference_err_limbos("mrkr")
2374
self.assertFalse(("sh", "node") in self.fsm.move_limbo)
2375
self.assertTrue(self.handler.check_debug("dereference err move limbo",
2378
def test_dereference_err_movelimbo_bothparents(self):
2379
"""Dereference with error possible marker in move limbo, both."""
2381
self.fsm.add_to_move_limbo("sh", "node", "mrkr", "mrkr", "x")
2383
# dereference and test
2384
self.fsm.dereference_err_limbos("mrkr")
2385
self.assertFalse(("sh", "node") in self.fsm.move_limbo)
2189
2388
class SyntheticInfoTests(FSMTestCase):
3233
3432
self.assertTrue(mdid4 in dirty_mdids)
3435
class TrashFileShelfTests(unittest.TestCase):
3436
"""Test the customized file shelf."""
3443
# already there, remove it to clean and create again
3444
shutil.rmtree(TESTS_DIR)
3447
self.tfs = TrashFileShelf(os.path.join(TESTS_DIR, "trash"))
3451
shutil.rmtree(TESTS_DIR)
3453
def test_one_value(self):
3454
"""Test the file shelf with one value."""
3455
self.tfs[("foo", "bar")] = 'value'
3457
self.assertEqual(self.tfs[("foo", "bar")], 'value')
3458
self.assertEqual(list(self.tfs.keys()), [("foo", "bar")])
3460
def test_two_values(self):
3461
"""Test the file shelf with two values."""
3462
self.tfs[("foo", "bar")] = 'value1'
3463
self.tfs[("xyz", "hfb")] = 'value2'
3465
self.assertEqual(self.tfs[("foo", "bar")], 'value1')
3466
self.assertEqual(self.tfs[("xyz", "hfb")], 'value2')
3467
self.assertEqual(sorted(self.tfs.keys()),
3468
[("foo", "bar"), ("xyz", "hfb")])
3470
def test_node_id_None(self):
3471
"""node_id can be None."""
3472
self.tfs[("foo", None)] = 'value'
3473
self.assertEqual(self.tfs[("foo", None)], 'value')
3474
self.assertEqual(list(self.tfs.keys()), [("foo", None)])
3476
def test_node_id_marker(self):
3477
"""node_id can be a marker."""
3478
marker = MDMarker("bar")
3479
self.tfs[("foo", marker)] = 'value'
3480
self.assertEqual(self.tfs[("foo", marker)], 'value')
3481
self.assertEqual(list(self.tfs.keys()), [("foo", marker)])
3482
node_id = list(self.tfs.keys())[0][1]
3483
self.assertTrue(IMarker.providedBy(node_id))
3485
def test_share_id_marker(self):
3486
"""share_id can be a marker."""
3487
marker = MDMarker("bar")
3488
self.tfs[(marker, "foo")] = 'value'
3489
self.assertEqual(self.tfs[(marker, "foo")], 'value')
3490
self.assertEqual(list(self.tfs.keys()), [(marker, "foo")])
3491
share_id = list(self.tfs.keys())[0][0]
3492
self.assertTrue(IMarker.providedBy(share_id))
3236
3495
def test_suite():
3237
3496
# pylint: disable-msg=C0111
3238
3497
return unittest.TestLoader().loadTestsFromName(__name__)