def test_download_fs_fs(self): # Download files from local to remote (which is empty) local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) remote = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) opts = {"force": False, "delete": False, "verbose": self.verbose} s = DownloadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 0) self.assertEqual(stats["local_files"], 0) self.assertEqual(stats["remote_dirs"], 2) # currently files are not counted, when inside a *new* folder: self.assertEqual(stats["remote_files"], 4) self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["bytes_written"], 16403) # Again: nothing to do s = DownloadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) self.assertEqual(stats["local_files"], 6) self.assertEqual(stats["remote_dirs"], 2) self.assertEqual(stats["remote_files"], 6) self.assertEqual(stats["files_written"], 0) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["bytes_written"], 0) # file times are preserved self.assertEqual(get_test_file_date("local/file1.txt"), STAMP_20140101_120000) self.assertEqual(get_test_file_date("remote/file1.txt"), STAMP_20140101_120000)
def test_sync_fs_fs(self): local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) remote = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) opts = {"dry_run": False, "verbose": self.verbose} # , "resolve": "ask"} s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) # currently files are not counted, when inside a *new* folder: self.assertEqual(stats["local_files"], 4) self.assertEqual(stats["remote_dirs"], 0) self.assertEqual(stats["remote_files"], 0) self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["bytes_written"], 16403) # file times are preserved self.assertEqual(get_test_file_date("local/file1.txt"), STAMP_20140101_120000) self.assertEqual(get_test_file_date("remote/file1.txt"), STAMP_20140101_120000) # Again: nothing to do s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) self.assertEqual(stats["local_files"], 6) self.assertEqual(stats["remote_dirs"], 2) self.assertEqual(stats["remote_files"], 6) self.assertEqual(stats["files_created"], 0) self.assertEqual(stats["files_deleted"], 0) self.assertEqual(stats["files_written"], 0) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["bytes_written"], 0) # Modify remote and/or remote touch_test_file("local/file1.txt") touch_test_file("remote/file2.txt") # file3.txt will cause a conflict: touch_test_file("local/file3.txt") dt = datetime.datetime.utcnow() - datetime.timedelta(seconds=10) touch_test_file("remote/file3.txt", dt=dt) s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["entries_seen"], 18) self.assertEqual(stats["entries_touched"], 2) self.assertEqual(stats["files_created"], 0) self.assertEqual(stats["files_deleted"], 0) self.assertEqual(stats["files_written"], 2) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["download_files_written"], 1) self.assertEqual(stats["upload_files_written"], 1) self.assertEqual(stats["conflict_files"], 1) self.assertEqual(stats["bytes_written"], 6)
def test_sync_fs_fs(self): local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) remote = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) opts = { "dry_run": False, "verbose": self.verbose } # , "resolve": "ask"} s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) # currently files are not counted, when inside a *new* folder: self.assertEqual(stats["local_files"], 4) self.assertEqual(stats["remote_dirs"], 0) self.assertEqual(stats["remote_files"], 0) self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["bytes_written"], 16403) # file times are preserved self.assertEqual(get_test_file_date("local/file1.txt"), STAMP_20140101_120000) self.assertEqual(get_test_file_date("remote/file1.txt"), STAMP_20140101_120000) # Again: nothing to do s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) self.assertEqual(stats["local_files"], 6) self.assertEqual(stats["remote_dirs"], 2) self.assertEqual(stats["remote_files"], 6) self.assertEqual(stats["files_created"], 0) self.assertEqual(stats["files_deleted"], 0) self.assertEqual(stats["files_written"], 0) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["bytes_written"], 0) # Modify remote and/or remote touch_test_file("local/file1.txt") touch_test_file("remote/file2.txt") # file3.txt will cause a conflict: touch_test_file("local/file3.txt") dt = datetime.datetime.utcnow() - datetime.timedelta(seconds=10) touch_test_file("remote/file3.txt", dt=dt) s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["entries_seen"], 18) self.assertEqual(stats["entries_touched"], 2) self.assertEqual(stats["files_created"], 0) self.assertEqual(stats["files_deleted"], 0) self.assertEqual(stats["files_written"], 2) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["download_files_written"], 1) self.assertEqual(stats["upload_files_written"], 1) self.assertEqual(stats["conflict_files"], 1) self.assertEqual(stats["bytes_written"], 6)
def test_sync_fs_ftp(self): local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) remote = self.remote # Upload all of temp/local to remote opts = {"force": False, "delete": True, "verbose": 3} s = UploadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) # currently files are not counted, when inside a *new* folder: self.assertEqual(stats["local_files"], 4) self.assertEqual(stats["remote_dirs"], 0) self.assertEqual(stats["remote_files"], 0) self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["bytes_written"], 16403) # Change one file and upload again touch_test_file("local/file1.txt") opts = {"force": False, "delete": True, "verbose": 3} s = UploadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) # assert False self.assertEqual(stats["entries_seen"], 18) # ??? self.assertEqual(stats["entries_touched"], 1) self.assertEqual(stats["files_created"], 0) self.assertEqual(stats["files_deleted"], 0) self.assertEqual(stats["files_written"], 1) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["download_files_written"], 0) self.assertEqual(stats["upload_files_written"], 1) self.assertEqual(stats["conflict_files"], 0) self.assertEqual(stats["bytes_written"], 3) # Download all from remote to temp/remote local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) opts = {"force": False, "delete": True, "verbose": 3} s = DownloadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["entries_seen"], 8) self.assertEqual(stats["entries_touched"], 8) # self.assertEqual(stats["files_created"], 6) self.assertEqual(stats["files_deleted"], 0) self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["download_files_written"], 6) self.assertEqual(stats["upload_files_written"], 0) self.assertEqual(stats["conflict_files"], 0) self.assertEqual(stats["bytes_written"], 16403) # Original file times are preserved, even when retrieved from FTP self.assertNotEqual(get_test_file_date("local/file1.txt"), STAMP_20140101_120000) self.assertEqual(get_test_file_date("local/file1.txt"), get_test_file_date("local//file1.txt")) self.assertEqual(get_test_file_date("local/file2.txt"), STAMP_20140101_120000) self.assertEqual(get_test_file_date("remote//file2.txt"), STAMP_20140101_120000) # Synchronize temp/local <=> remote : nothing to do local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) opts = {"verbose": 3} s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() pprint(stats) self.assertEqual(stats["entries_touched"], 0) self.assertEqual(stats["conflict_files"], 0) self.assertEqual(stats["bytes_written"], 0) # Synchronize temp/remote <=> remote : nothing to do local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) opts = {"verbose": 3} s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() pprint(stats) self.assertEqual(stats["entries_touched"], 0) self.assertEqual(stats["conflict_files"], 0) self.assertEqual(stats["bytes_written"], 0)
def test_sync_fs_ftp(self): local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) remote = self.remote # Upload all of temp/local to remote opts = {"force": False, "delete": True, "verbose": 3} s = UploadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["local_dirs"], 2) # currently files are not counted, when inside a *new* folder: self.assertEqual(stats["local_files"], 4) self.assertEqual(stats["remote_dirs"], 0) self.assertEqual(stats["remote_files"], 0) self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["bytes_written"], 16403) # Change one file and upload again touch_test_file("local/file1.txt") opts = {"force": False, "delete": True, "verbose": 3} s = UploadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) # assert False self.assertEqual(stats["entries_seen"], 18) # ??? self.assertEqual(stats["entries_touched"], 1) self.assertEqual(stats["files_created"], 0) self.assertEqual(stats["files_deleted"], 0) self.assertEqual(stats["files_written"], 1) self.assertEqual(stats["dirs_created"], 0) self.assertEqual(stats["download_files_written"], 0) self.assertEqual(stats["upload_files_written"], 1) self.assertEqual(stats["conflict_files"], 0) self.assertEqual(stats["bytes_written"], 3) # Download all from remote to temp/remote local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) opts = {"force": False, "delete": True, "verbose": 3} s = DownloadSynchronizer(local, remote, opts) s.run() stats = s.get_stats() # pprint(stats) self.assertEqual(stats["entries_seen"], 8) self.assertEqual(stats["entries_touched"], 8) # self.assertEqual(stats["files_created"], 6) self.assertEqual(stats["files_deleted"], 0) self.assertEqual(stats["files_written"], 6) self.assertEqual(stats["dirs_created"], 2) self.assertEqual(stats["download_files_written"], 6) self.assertEqual(stats["upload_files_written"], 0) self.assertEqual(stats["conflict_files"], 0) self.assertEqual(stats["bytes_written"], 16403) # Original file times are preserved, even when retrieved from FTP self.assertNotEqual( get_test_file_date("local/file1.txt"), STAMP_20140101_120000 ) self.assertEqual( get_test_file_date("local/file1.txt"), get_test_file_date("local//file1.txt"), ) self.assertEqual(get_test_file_date("local/file2.txt"), STAMP_20140101_120000) self.assertEqual(get_test_file_date("remote//file2.txt"), STAMP_20140101_120000) # Synchronize temp/local <=> remote : nothing to do local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "local")) opts = {"verbose": 3} s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() pprint(stats) self.assertEqual(stats["entries_touched"], 0) self.assertEqual(stats["conflict_files"], 0) self.assertEqual(stats["bytes_written"], 0) # Synchronize temp/remote <=> remote : nothing to do local = FsTarget(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")) opts = {"verbose": 3} s = BiDirSynchronizer(local, remote, opts) s.run() stats = s.get_stats() pprint(stats) self.assertEqual(stats["entries_touched"], 0) self.assertEqual(stats["conflict_files"], 0) self.assertEqual(stats["bytes_written"], 0)