예제 #1
0
    def test_prepare_initial_synced_fixture(self):
        # """Test that fixture set up code worked."""
        # Fixtures are initialized to 9 top-level files and 7 folders, all 12:00:00
        self.assert_test_folder_equal(get_test_folder("local"),
                                      _SyncTestBase.local_fixture_unmodified)

        # setUp() should have created a copy of /local in /remote
        self.assert_test_folder_equal(get_test_folder("remote"),
                                      _SyncTestBase.local_fixture_unmodified)

        # Metadata files are created on local target only
        self.assertTrue(is_test_file("local/" + DirMetadata.META_FILE_NAME))
        self.assertTrue(not is_test_file("remote/" +
                                         DirMetadata.META_FILE_NAME))

        # Local meta data file contains peer sync info
        meta = get_metadata("local")
        remote_path = os.path.join(PYFTPSYNC_TEST_FOLDER, "remote")
        assert "peer_sync" in meta
        meta = meta["peer_sync"]
        assert remote_path in meta
        meta = meta[remote_path]
        assert "file1.txt" in meta
        assert "folder7" in meta
        # Subfolders also contain peer_sync info
        meta = get_metadata("local/folder7")
        assert "file7_1.txt" in meta["peer_sync"][remote_path]
예제 #2
0
    def test_delete_unmatched(self):
        opts = {
            "verbose": self.verbose,
            "resolve": "local",
            "delete": True,
            "delete_unmatched": True,
            "force": True,
            "match": "*1.txt",
        }

        stats = self.do_run_suite(UploadSynchronizer, opts)
        self._dump_de_facto_results(stats)

        # We expect 7 conflicts, and leave them unresolved (i.e. skip them all)

        # self.assertEqual(stats["files_written"], 3)
        # self.assertEqual(stats["download_files_written"], 0)
        # self.assertEqual(stats["upload_files_written"], 3)
        # self.assertEqual(stats["files_deleted"], 1)
        # self.assertEqual(stats["dirs_deleted"], 2)
        # self.assertEqual(stats["conflict_files"], 7)
        # self.assertEqual(stats["conflict_files_skipped"], 7)

        self.assert_test_folder_equal(get_test_folder("local"),
                                      _SyncTestBase.local_fixture_modified)

        # We expect that remote only contains files that match '*1.txt'
        expect_remote = {
            "file1.txt": {
                "content": "local1",
                "date": "2014-01-01 12:00:00"
            },
            "folder1/file1_1.txt": {
                "content": "local1_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder2/file2_1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder5/file5_1.txt": {
                "content": "local5_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder6/file6_1.txt": {
                "content": "local6_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder7/file7_1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "new_file1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
        }
        self.assert_test_folder_equal(get_test_folder("remote"), expect_remote)
예제 #3
0
    def test_dry_run(self):
        opts = {"verbose": self.verbose, "resolve": "local", "dry_run": True}

        stats = self.do_run_suite(BiDirSynchronizer, opts)

        # DRY-RUN: We expect no changes
        self.assertEqual(stats["bytes_written"], 0)

        self.assert_test_folder_equal(get_test_folder("local"),
                                      _SyncTestBase.local_fixture_modified)
        self.assert_test_folder_equal(get_test_folder("remote"),
                                      _SyncTestBase.remote_fixture_modified)
예제 #4
0
    def test_mirror(self):
        opts = {
            "verbose": self.verbose,
            "resolve": "local",
            "delete": True,
            "force": True,
        }

        self.do_run_suite(UploadSynchronizer, opts)

        # We expect that local is mirrored 1:1 to remote
        self.assert_test_folder_equal(get_test_folder("local"),
                                      _SyncTestBase.local_fixture_modified)
        self.assert_test_folder_equal(get_test_folder("remote"),
                                      _SyncTestBase.local_fixture_modified)
예제 #5
0
    def test_prepare_modified_fixture(self):
        # """Test that fixture set up code worked."""
        #
        self._prepare_modified_fixture()

        self.assert_test_folder_equal(get_test_folder("local"),
                                      _SyncTestBase.local_fixture_modified)

        self.assert_test_folder_equal(get_test_folder("remote"),
                                      _SyncTestBase.remote_fixture_modified)

        # Metadata files are created on local target only
        self.assertTrue(is_test_file("local/" + DirMetadata.META_FILE_NAME))
        self.assertTrue(not is_test_file("remote/" +
                                         DirMetadata.META_FILE_NAME))
예제 #6
0
    def test_default(self):
        opts = {
            "verbose": self.verbose
        }  # default options, i.e. 'skip' conflicts
        # Default options: expect 4 unresolved conflicts
        stats = self.do_run_suite(UploadSynchronizer, opts)
        self._dump_de_facto_results(stats)

        # We expect 7 conflicts, and leave them unresolved (i.e. skip them all)

        self.assertEqual(stats["files_written"], 3)
        self.assertEqual(stats["download_files_written"], 0)
        self.assertEqual(stats["upload_files_written"], 3)
        self.assertEqual(stats["files_deleted"], 0)
        self.assertEqual(stats["dirs_deleted"], 0)
        self.assertEqual(stats["conflict_files"], 7)
        self.assertEqual(stats["conflict_files_skipped"], 7)

        # We expect that local remains unmodified
        self.assert_test_folder_equal(get_test_folder("local"),
                                      _SyncTestBase.local_fixture_modified)

        expect_remote = {
            "file1.txt": {
                "content": "local1",
                "date": "2014-01-01 12:00:00"
            },
            "file2.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file3.txt": {
                "content": "local3",
                "date": "2014-01-01 12:00:00"
            },
            "file4.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file6.txt": {
                "content": "remote 13:00:05",
                "date": "2014-01-01 13:00:05"
            },
            "file7.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file8.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "folder1/file1_1.txt": {
                "content": "local1_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder2/file2_1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder3/file3_1.txt": {
                "content": "local3_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder4/file4_1.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder5/file5_1.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "new_file1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file2.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file3.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file4.txt": {
                "content": "remote 13:00 with other content",
                "date": "2014-01-01 13:00:00",
            },
            "new_file5.txt": {
                "content": "remote 13:00:05",
                "date": "2014-01-01 13:00:05",
            },
            "new_file6.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
        }
        self.assert_test_folder_equal(get_test_folder("remote"), expect_remote)
예제 #7
0
    def test_no_metadata(self):
        """Synchronize with absent .pyftpsync-meta.json."""

        # Reset setUp fixture and re-create without using a synchronizer
        self._prepare_synced_fixture_without_meta()

        opts = {"verbose": self.verbose}

        self.do_run_suite(BiDirSynchronizer, opts)
        #         self._dump_de_facto_results(stats)

        # NOTE:
        # Since we don't have meta data, the synchronizer treats missing files on
        # either side as 'new'.
        # Also modifications on both sides are not recognized as conflict. Instead the
        # newer file wins. (Only exception is new_file4.txt` which has identical time
        # but different size)
        # => So we basically get a union of both targets.

        # self.assertEqual(stats["files_written"], 18)
        # self.assertEqual(stats["download_files_written"], 9)
        # self.assertEqual(stats["upload_files_written"], 9)
        # self.assertEqual(stats["files_deleted"], 0)
        # self.assertEqual(stats["dirs_deleted"], 0)
        # self.assertEqual(stats["conflict_files"], 1)

        expect_local = {
            "file1.txt": {
                "content": "local1",
                "date": "2014-01-01 12:00:00"
            },
            "file2.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file3.txt": {
                "content": "local3",
                "date": "2014-01-01 12:00:00"
            },
            "file4.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file5.txt": {
                "content": "local5",
                "date": "2014-01-01 12:00:00"
            },
            "file6.txt": {
                "content": "remote 13:00:05",
                "date": "2014-01-01 13:00:05"
            },
            "file7.txt": {
                "content": "local 13:00:05",
                "date": "2014-01-01 13:00:05"
            },
            "file8.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file9.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "folder1/file1_1.txt": {
                "content": "local1_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder2/file2_1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder3/file3_1.txt": {
                "content": "local3_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder4/file4_1.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder5/file5_1.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder6/file6_1.txt": {
                "content": "local6_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder7/file7_1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "new_file1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file2.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file3.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file4.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file5.txt": {
                "content": "remote 13:00:05",
                "date": "2014-01-01 13:00:05",
            },
            "new_file6.txt": {
                "content": "local 13:00:05",
                "date": "2014-01-01 13:00:05",
            },
        }
        expect_remote = expect_local.copy()
        expect_remote.update({
            "new_file4.txt": {
                "content": "remote 13:00 with other content",
                "date": "2014-01-01 13:00:00",
            }
        })
        self.assert_test_folder_equal(get_test_folder("local"), expect_local)
        self.assert_test_folder_equal(get_test_folder("remote"), expect_remote)
예제 #8
0
    def test_default(self):
        opts = {
            "verbose": self.verbose
        }  # default options, i.e. 'skip' conflicts
        # Default options: expect 4 unresolved conflicts
        stats = self.do_run_suite(BiDirSynchronizer, opts)
        #         self._dump_de_facto_results(stats)

        # We expect 7 conflicts, and leave them unresolved (i.e. skip them all)

        self.assertEqual(stats["files_written"], 6)
        self.assertEqual(stats["download_files_written"], 3)
        self.assertEqual(stats["upload_files_written"], 3)
        self.assertEqual(stats["files_deleted"], 2)
        self.assertEqual(stats["dirs_deleted"], 4)
        self.assertEqual(stats["conflict_files"], 7)

        expect_local = {
            "file1.txt": {
                "content": "local1",
                "date": "2014-01-01 12:00:00"
            },
            "file2.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file4.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file6.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file7.txt": {
                "content": "local 13:00:05",
                "date": "2014-01-01 13:00:05"
            },
            "file9.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "folder1/file1_1.txt": {
                "content": "local1_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder2/file2_1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder5/file5_1.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "new_file1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file2.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file3.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file4.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file5.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file6.txt": {
                "content": "local 13:00:05",
                "date": "2014-01-01 13:00:05",
            },
        }
        expect_remote = {
            "file1.txt": {
                "content": "local1",
                "date": "2014-01-01 12:00:00"
            },
            "file2.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file4.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file6.txt": {
                "content": "remote 13:00:05",
                "date": "2014-01-01 13:00:05"
            },
            "file7.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file8.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "folder1/file1_1.txt": {
                "content": "local1_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder2/file2_1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder5/file5_1.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "new_file1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file2.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file3.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file4.txt": {
                "content": "remote 13:00 with other content",
                "date": "2014-01-01 13:00:00",
            },
            "new_file5.txt": {
                "content": "remote 13:00:05",
                "date": "2014-01-01 13:00:05",
            },
            "new_file6.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
        }
        self.assert_test_folder_equal(get_test_folder("local"), expect_local)
        self.assert_test_folder_equal(get_test_folder("remote"), expect_remote)
예제 #9
0
    def test_resolve_remote(self):

        opts = {"resolve": "remote", "verbose": self.verbose}

        stats = self.do_run_suite(BiDirSynchronizer, opts)
        # self._dump_de_facto_results(stats)

        # We resolve all conflicts by using the remote version.

        self.assertEqual(stats["files_written"], 12)
        self.assertEqual(stats["download_files_written"], 9)
        self.assertEqual(stats["upload_files_written"], 3)
        self.assertEqual(stats["files_deleted"], 3)
        self.assertEqual(stats["dirs_deleted"], 4)
        self.assertEqual(stats["conflict_files"], 7)

        expect_local = {
            "file1.txt": {
                "content": "local1",
                "date": "2014-01-01 12:00:00"
            },
            "file2.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file4.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file6.txt": {
                "content": "remote 13:00:05",
                "date": "2014-01-01 13:00:05"
            },
            "file7.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "file8.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "folder1/file1_1.txt": {
                "content": "local1_1",
                "date": "2014-01-01 12:00:00",
            },
            "folder2/file2_1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "folder5/file5_1.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00",
            },
            "new_file1.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file2.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file3.txt": {
                "content": "local 13:00",
                "date": "2014-01-01 13:00:00"
            },
            "new_file4.txt": {
                "content": "remote 13:00 with other content",
                "date": "2014-01-01 13:00:00",
            },
            "new_file5.txt": {
                "content": "remote 13:00:05",
                "date": "2014-01-01 13:00:05",
            },
            "new_file6.txt": {
                "content": "remote 13:00",
                "date": "2014-01-01 13:00:00"
            },
        }
        self.assert_test_folder_equal(get_test_folder("local"), expect_local)
        self.assert_test_folder_equal(get_test_folder("remote"), expect_local)