def test_relink(self, islink, symlink, unlink, readlink, walk): def read_link(path): if os.path.basename(path) == 'l-invalid': raise OSError() return path.upper() readlink.side_effect = read_link def is_link(path): return os.path.basename(path)[0] == 'l' islink.side_effect = is_link paths = { 'D0/L2': Item(1, '1', 'D0/L2', 'new-path-1', []), 'D1/L3': Item(2, '2', 'D1/L3', 'new-path-2', []), 'D2/L6': Item(3, '3', 'D2/L6', 'new-path-3', []), 'D3/L7': Item(4, '4', 'D3', 'new-path-4', ['L7']), } walk.return_value = [ ('d0', ['d1', 'd2'], ['f1', 'l2']), ('d1', [], ['l3', 'f4']), ('d2', [], ['f5', 'l6', 'l7', 'l-invalid']), ('d3', [], ['l7']), ] # test batch = Batch() batch.paths = paths batch._relink() # validation self.assertEqual( unlink.call_args_list, [ call('d0/l2'), call('d1/l3'), call('d2/l6'), call('d3/l7') ]) self.assertEqual( symlink.call_args_list, [ call('new-path-1', 'd0/l2'), call('new-path-2', 'd1/l3'), call('new-path-3', 'd2/l6'), call('new-path-4/L7', 'd3/l7') ])
def test_migrate(self): plan = Mock() items = [ Item(plan, '1', 'path-1', 'new-path-1', []), Item(plan, '2', 'path-2', 'new-path-2', []), Item(plan, '3', 'path-3', 'new-path-3', []), ] # test batch = Batch() batch.items = items batch._migrate() # validate for i in items: expected_call = call(i.unit_id, i.storage_path, i.new_path) self.assertTrue(expected_call in plan.migrate.call_args_list)
def test_migrate(self): plan = Mock() items = [ Item(plan, '1', 'path-1', 'new-path-1', []), Item(plan, '2', 'path-2', 'new-path-2', []), Item(plan, '3', 'path-3', 'new-path-3', []), ] # test batch = Batch() batch.items = items batch._migrate() # validate self.assertEqual( plan.migrate.call_args_list, [ call(i.unit_id, i.storage_path, i.new_path) for i in items ])
def test_migrate(self, unit_migrate): items = [ Item(Mock(), '1', 'path-1', 'new-path-1'), Item(Mock(), '2', 'path-2', 'new-path-2'), Item(Mock(), '3', 'path-3', 'new-path-3'), ] _dict = Mock() _dict.itervalues.return_value = iter(items) # test batch = Batch() batch.items = _dict batch._migrate() # validate self.assertEqual( unit_migrate.call_args_list, [ call(i.plan, i.unit_id, i.storage_path, i.new_path) for i in items ])
def test_relink(self, islink, symlink, unlink, readlink, walk): def read_link(path): return path.upper() readlink.side_effect = read_link def is_link(path): return os.path.basename(path)[0] == 'l' islink.side_effect = is_link items = { 'D0/L2': Item(1, '1', 'd0/l2', 'new-path-1'), 'D1/L3': Item(2, '2', 'd1/l3', 'new-path-2'), 'D2/L6': Item(3, '3', 'd2/l6', 'new-path-3'), } walk.return_value = [ ('d0', ['d1', 'd2'], ['f1', 'l2']), ('d1', [], ['l3', 'f4']), ('d2', [], ['f5', 'l6', 'l7']) ] # test batch = Batch() batch.items = items batch._relink() # validation self.assertEqual( unlink.call_args_list, [ call(items[k].storage_path) for k in sorted(items) ]) self.assertEqual( symlink.call_args_list, [ call(items[k].new_path, k.lower()) for k in sorted(items) ])
def test_relink(self, symlink, unlink, readlink, walk): links = { '/pub/zoo/cat/lion/f1': '/content/a/f1', '/pub/zoo/cat/tiger/f2': '/content/b/f2', '/pub/zoo/zebra/f3': '/content/c/f3', '/pub/zoo/bear/f4': '/content/d/f4', '/pub/zoo/wolf/f5': '/content/e/f5', '/pub/zoo/wolf/.f5': '/content/e/.f5', '/pub/zoo/wolf/f6': '/content/e/f6', '/pub/unknown/f0': '/content/unknown/f0', } def read_link(path): try: return links[path] except KeyError: raise OSError() readlink.side_effect = read_link items = [ Item(1, '1', '/content/a/f1', '/content/new/a/f1', []), Item(2, '2', '/content/b/f2', '/content/new/b/f2', []), Item(3, '3', '/content/c/f3', '/content/new/c/f3', []), Item(4, '4', '/content/d/f4', '/content/new/d/f4', []), Item(5, '5', '/content/e', '/content/new/e', ['f5', '.f5', 'f6']), ] paths = {} for i in items: paths[i.storage_path] = i for f in i.files: paths[os.path.join(i.storage_path, f)] = i walk.return_value = [ ('/pub', ['zoo', 'other'], []), ('/pub/zoo', ['cat'], []), ('/pub/zoo/cat', ['lion', 'tiger'], []), ('/pub/zoo/cat/lion', [], ['f1']), ('/pub/zoo/cat/tiger', [], ['f2']), ('/pub/zoo/zebra', [], ['f3']), ('/pub/zoo/bear', [], ['f4']), ('/pub/zoo/wolf', [], ['.f5', 'f5', 'f6']), ('/pub/unknown', [], ['f0', 'f1']), ] # test batch = Batch() batch.paths = paths batch._relink() # validation expected_unlink_calls = [ call('/pub/zoo/cat/lion/f1'), call('/pub/zoo/cat/tiger/f2'), call('/pub/zoo/zebra/f3'), call('/pub/zoo/bear/f4'), call('/pub/zoo/wolf/.f5'), call('/pub/zoo/wolf/f5'), call('/pub/zoo/wolf/f6'), ] expected_link_calls = [ call('/content/new/a/f1', '/pub/zoo/cat/lion/f1'), call('/content/new/b/f2', '/pub/zoo/cat/tiger/f2'), call('/content/new/c/f3', '/pub/zoo/zebra/f3'), call('/content/new/d/f4', '/pub/zoo/bear/f4'), call('/content/new/e/.f5', '/pub/zoo/wolf/.f5'), call('/content/new/e/f5', '/pub/zoo/wolf/f5'), call('/content/new/e/f6', '/pub/zoo/wolf/f6'), ] for link_call, unlink_call in zip(expected_link_calls, expected_unlink_calls): self.assertTrue(link_call in symlink.call_args_list) self.assertTrue(unlink_call in unlink.call_args_list)