def test_b2_to_local(self): file_a1 = File( "a.txt", [FileVersion("id_a_100", 100, "upload")]) # only in source file_a2 = File( "c.txt", [FileVersion("id_c_200", 200, "upload")]) # mod time matches file_a3 = File( "d.txt", [FileVersion("id_d_100", 100, "upload")]) # newer in dest file_a4 = File( "e.txt", [FileVersion("id_e_300", 300, "upload")]) # newer in source file_b1 = File( "b.txt", [FileVersion("/dir/b.txt", 200, "upload")]) # only in dest file_b2 = File( "c.txt", [FileVersion("/dir/c.txt", 200, "upload")]) # mod time matches file_b3 = File( "d.txt", [FileVersion("/dir/d.txt", 200, "upload")]) # newer in dest file_b4 = File( "e.txt", [FileVersion("/dir/e.txt", 200, "upload")]) # newer in source folder_a = FakeFolder('b2', [file_a1, file_a2, file_a3, file_a4]) folder_b = FakeFolder('local', [file_b1, file_b2, file_b3, file_b4]) actions = list(make_folder_sync_actions(folder_a, folder_b, 1)) self.assertEqual([ "b2_download(a.txt, id_a_100)", "local_delete(/dir/b.txt)", "b2_download(e.txt, id_e_300)" ], list(map(str, actions)))
def b2_file(name, *args): """ Makes a File object for a b2 file, with one FileVersion for each modification time given in *args. Positive modification times are uploads, and negative modification times are hides. It's a hack, but it works. b2_file('a.txt', 300, -200, 100) Is the same as: File( 'a.txt', [ FileVersion('id_a_300', 'a.txt', 300, 'upload'), FileVersion('id_a_200', 'a.txt', 200, 'hide'), FileVersion('id_a_100', 'a.txt', 100, 'upload') ] ) """ versions = [ FileVersion('id_%s_%d' % (name[0], abs(mod_time)), 'folder/' + name, abs(mod_time), 'upload' if 0 < mod_time else 'hide', 10) for mod_time in args ] # yapf disable return File(name, versions)
def local_file(name, *args): """ Makes a File object for a b2 file, with one FileVersion for each modification time given in *args. """ versions = [FileVersion('/dir/%s' % (name,), name, mod_time, 'upload', 10) for mod_time in args] return File(name, versions)
def test_two(self): file_a1 = File("a.txt", [FileVersion("a", "a", 100, "upload", 10)]) file_a2 = File("b.txt", [FileVersion("b", "b", 100, "upload", 10)]) file_a3 = File("d.txt", [FileVersion("c", "c", 100, "upload", 10)]) file_a4 = File("f.txt", [FileVersion("f", "f", 100, "upload", 10)]) file_b1 = File("b.txt", [FileVersion("b", "b", 200, "upload", 10)]) file_b2 = File("e.txt", [FileVersion("e", "e", 200, "upload", 10)]) folder_a = FakeFolder('b2', [file_a1, file_a2, file_a3, file_a4]) folder_b = FakeFolder('b2', [file_b1, file_b2]) self.assertEqual([(file_a1, None), (file_a2, file_b1), (file_a3, None), (None, file_b2), (file_a4, None)], list(zip_folders(folder_a, folder_b)))
def test_one_empty(self): file_a1 = File("a.txt", [FileVersion("a", "a", 100, "upload", 10)]) folder_a = FakeFolder('b2', [file_a1]) folder_b = FakeFolder('b2', []) self.assertEqual([(file_a1, None)], list(zip_folders(folder_a, folder_b)))