예제 #1
0
    def test_issue_24(self):
        if not self.use_ftp_target:
            raise SkipTest("Only FTP targets.")

#         empty_folder()
        empty_folder(os.path.join(PYFTPSYNC_TEST_FOLDER, "local"))
        empty_folder(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote"))

        local_target = make_target(self.local_url)
        remote_target = make_target(self.remote_url)

        SIZE = 1000 * 1000
        write_test_file("local/large1.txt", size=SIZE)
        write_test_file("remote/large2.txt", size=SIZE)

        opts = {
            "verbose": 5,
            "match": "large*.txt",
        }
        synchronizer = DownloadSynchronizer(local_target, remote_target, opts)

        assert is_test_file("local/large1.txt")
        assert is_test_file("remote/large2.txt")
        assert not is_test_file("remote/large1.txt")
        assert not is_test_file("local/large2.txt")

        synchronizer.run()

        # Expect that large2 was downloaded
        assert not is_test_file("remote/large1.txt")
        assert get_test_file_size("local/large2.txt") == SIZE
예제 #2
0
    def test_issue_24(self):
        if not self.use_ftp_target:
            raise SkipTest("Only FTP targets.")

        #         empty_folder()
        empty_folder(os.path.join(PYFTPSYNC_TEST_FOLDER, "local"))
        empty_folder(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote"))

        local_target = make_target(self.local_url)
        remote_target = make_target(self.remote_url)

        SIZE = 1000 * 1000
        write_test_file("local/large1.txt", size=SIZE)
        write_test_file("remote/large2.txt", size=SIZE)

        opts = {"verbose": 5, "match": "large*.txt"}
        synchronizer = DownloadSynchronizer(local_target, remote_target, opts)

        assert is_test_file("local/large1.txt")
        assert is_test_file("remote/large2.txt")
        assert not is_test_file("remote/large1.txt")
        assert not is_test_file("local/large2.txt")

        synchronizer.run()

        # Expect that large2 was downloaded
        assert not is_test_file("remote/large1.txt")
        assert get_test_file_size("local/large2.txt") == SIZE
예제 #3
0
    def test_issue_20(self):

        opts = {"verbose": 5}

        local_target = make_target(self.local_url)
        remote_target = make_target(self.remote_url)

        ftp_downloader = DownloadSynchronizer(local_target, remote_target, opts)
        ftp_uploader = UploadSynchronizer(local_target, remote_target, opts)

        write_test_file("local/large1.txt", size=10 * 1000)
        write_test_file("remote/large2.txt", size=10 * 1000)
        ftp_downloader.run()
        ftp_uploader.run()
예제 #4
0
    def _transfer_files(self, count, size):
        temp1_path = os.path.join(PYFTPSYNC_TEST_FOLDER, "local")
        empty_folder(temp1_path)  # remove standard test files

        local = FsTarget(temp1_path)
        remote = self.remote

        for i in range(count):
            write_test_file("local/file_{}.txt".format(i), size=size)

        # Upload all of temp/local to remote

        opts = {"force": False, "delete": False, "verbose": 3}
        s = UploadSynchronizer(local, remote, opts)
        s.run()
        stats = s.get_stats()
        #        pprint(stats)

        self.assertEqual(stats["files_written"], count)
        self.assertEqual(stats["bytes_written"], count * size)
        #        pprint(stats)
        print(
            "Upload {} x {} bytes took {}: {}".format(
                count, size, stats["upload_write_time"], stats["upload_rate_str"]
            ),
            file=sys.stderr,
        )

        # Download all of 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["files_written"], count)
        self.assertEqual(stats["bytes_written"], count * size)

        #        pprint(stats)
        print(
            "Download {} x {} bytes took {}: {}".format(
                count, size, stats["download_write_time"], stats["download_rate_str"]
            ),
            file=sys.stderr,
        )
예제 #5
0
    def _transfer_files(self, count, size):
        temp1_path = os.path.join(PYFTPSYNC_TEST_FOLDER, "local")
        empty_folder(temp1_path)  # remove standard test files

        local = FsTarget(temp1_path)
        remote = self.remote

        for i in range(count):
            write_test_file("local/file_{}.txt".format(i), size=size)

        # Upload all of temp/local to remote

        opts = {"force": False, "delete": False, "verbose": 3}
        s = UploadSynchronizer(local, remote, opts)
        s.run()
        stats = s.get_stats()
        #        pprint(stats)

        self.assertEqual(stats["files_written"], count)
        self.assertEqual(stats["bytes_written"], count * size)
        #        pprint(stats)
        print(
            "Upload {} x {} bytes took {}: {}".format(
                count, size, stats["upload_write_time"],
                stats["upload_rate_str"]),
            file=sys.stderr,
        )

        # Download all of 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["files_written"], count)
        self.assertEqual(stats["bytes_written"], count * size)

        #        pprint(stats)
        print(
            "Download {} x {} bytes took {}: {}".format(
                count, size, stats["download_write_time"],
                stats["download_rate_str"]),
            file=sys.stderr,
        )
예제 #6
0
    def test_issue_21(self):
        if not self.use_ftp_target:
            raise SkipTest("Only FTP targets.")
        write_test_file("local/large.txt", size=10 * 1000)
        write_test_file("remote/large.txt", size=10 * 1000)

        out = run_script("download", "-vvv", self.local_url, self.remote_url)
        #         print(out)
        assert not ("*cmd* 'PORT" in out or "*cmd* 'EPRT" in out)
        assert "*cmd* 'PASV" in out or "*cmd* 'EPSV" in out

        out = run_script("download", self.local_url, self.remote_url, "-vvv",
                         "--ftp-active")
        #         print(out)
        assert "*cmd* 'PORT" in out or "*cmd* 'EPRT" in out
        assert not ("*cmd* 'PASV" in out or "*cmd* 'EPSV" in out)
예제 #7
0
    def test_issue_21(self):
        if not self.use_ftp_target:
            raise SkipTest("Only FTP targets.")
        write_test_file("local/large.txt", size=10 * 1000)
        write_test_file("remote/large.txt", size=10 * 1000)

        out = run_script("download", "-vvv", self.local_url, self.remote_url)
        #         print(out)
        assert not ("*cmd* 'PORT" in out or "*cmd* 'EPRT" in out)
        assert "*cmd* 'PASV" in out or "*cmd* 'EPSV" in out

        out = run_script(
            "download", self.local_url, self.remote_url, "-vvv", "--ftp-active"
        )
        #         print(out)
        assert "*cmd* 'PORT" in out or "*cmd* 'EPRT" in out
        assert not ("*cmd* 'PASV" in out or "*cmd* 'EPSV" in out)
예제 #8
0
    def test_folder_conflict(self):
        """Delete a folder on one side, but change content on other side."""

        write_test_file("local/folder1/file1_1.txt",
                        dt="2014-01-01 13:00:00",
                        content="local 13:00")
        remove_test_folder("remote/folder1")

        opts = {"verbose": self.verbose}
        stats = self._sync_test_folders(BiDirSynchronizer, opts)

        # Note: currently we do NOT detect this kind of conflicts!

        # This is what we can expect right now:
        self.assertEqual(stats["dirs_deleted"], 1)
        self.assertEqual(stats["conflict_files"], 0)

        raise SkipTest("Currently we do NOT detect this kind of conflicts.")
예제 #9
0
    def test_folder_conflict(self):
        """Delete a folder on one side, but change content on other side."""

        write_test_file(
            "local/folder1/file1_1.txt", dt="2014-01-01 13:00:00", content="local 13:00"
        )
        remove_test_folder("remote/folder1")

        opts = {"verbose": self.verbose}
        stats = self._sync_test_folders(BiDirSynchronizer, opts)

        # Note: currently we do NOT detect this kind of conflicts!

        # This is what we can expect right now:
        self.assertEqual(stats["dirs_deleted"], 1)
        self.assertEqual(stats["conflict_files"], 0)

        raise SkipTest("Currently we do NOT detect this kind of conflicts.")
예제 #10
0
    def test_folder_conflict(self):
        """Delete a folder on one side, but change content on other side."""

        write_test_file("local/folder1/file1_1.txt", dt="2014-01-01 13:00:00",
                        content="local 13:00")
        remove_test_folder("remote/folder1")

        opts = {"verbose": self.verbose}
        stats = self._sync_test_folders(BiDirSynchronizer, opts)

        # Note: currently we do NOT detect this kind of conflicts!

        # This is what we can expect right now:
        self.assertEqual(stats["dirs_deleted"], 1)
        self.assertEqual(stats["conflict_files"], 0)

        raise SkipTest("Currently we do NOT detect this kind of conflicts.")

        self.assertEqual(stats["files_written"], 0)
        self.assertEqual(stats["download_files_written"], 0)
        self.assertEqual(stats["upload_files_written"], 0)
        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': 'local2', 'date': '2014-01-01 12:00:00'},
            'file3.txt': {'content': 'local3', 'date': '2014-01-01 12:00:00'},
            'file4.txt': {'content': 'local4', 'date': '2014-01-01 12:00:00'},
            'file5.txt': {'content': 'local5', 'date': '2014-01-01 12:00:00'},
            'file6.txt': {'content': 'local6', 'date': '2014-01-01 12:00:00'},
            'file7.txt': {'content': 'local7', 'date': '2014-01-01 12:00:00'},
            'file8.txt': {'content': 'local8', 'date': '2014-01-01 12:00:00'},
            'file9.txt': {'content': 'local9', 'date': '2014-01-01 12:00:00'},
            'folder2/file2_1.txt': {'content': 'local2_1', 'date': '2014-01-01 12:00:00'},
            'folder3/file3_1.txt': {'content': 'local3_1', 'date': '2014-01-01 12:00:00'},
            'folder4/file4_1.txt': {'content': 'local4_1', 'date': '2014-01-01 12: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': 'local7_1', 'date': '2014-01-01 12:00:00'},
            }
        self.assert_test_folder_equal(get_test_folder("local"), expect_local)
        self.assert_test_folder_equal(get_test_folder("remote"), expect_local)
예제 #11
0
파일: test_1x.py 프로젝트: mar10/pyftpsync
def prepare_fixtures_1():
    """Create two test folders and some files.

    """
    print("Prepare_fixtures", PYFTPSYNC_TEST_FOLDER)
    # print("PYFTPSYNC_TEST_FOLDER", os.environ.get("PYFTPSYNC_TEST_FOLDER"))
    # print("PYFTPSYNC_TEST_FTP_URL", os.environ.get("PYFTPSYNC_TEST_FTP_URL"))

    assert os.path.isdir(PYFTPSYNC_TEST_FOLDER)
    # Reset all
    empty_folder(PYFTPSYNC_TEST_FOLDER)
    # Add some files to ../local/
    dt = datetime.datetime(2014, 1, 1, 12, 0, 0)
    write_test_file("local/file1.txt", content="111", dt=dt)
    write_test_file("local/file2.txt", content="222", dt=dt)
    write_test_file("local/file3.txt", content="333", dt=dt)
    write_test_file("local/folder1/file1_1.txt", content="1.111", dt=dt)
    write_test_file("local/folder2/file2_1.txt", content="2.111", dt=dt)
    write_test_file("local/big_file.txt", size=1024 * 16, dt=dt)
    # Create empty ../remote/
    os.mkdir(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote"))
예제 #12
0
def prepare_fixtures_1():
    """Create two test folders and some files.

    """
    print("Prepare_fixtures", PYFTPSYNC_TEST_FOLDER)
    # print("PYFTPSYNC_TEST_FOLDER", os.environ.get("PYFTPSYNC_TEST_FOLDER"))
    # print("PYFTPSYNC_TEST_FTP_URL", os.environ.get("PYFTPSYNC_TEST_FTP_URL"))

    assert os.path.isdir(PYFTPSYNC_TEST_FOLDER)
    # Reset all
    empty_folder(PYFTPSYNC_TEST_FOLDER)
    # Add some files to ../local/
    dt = datetime.datetime(2014, 1, 1, 12, 0, 0)
    write_test_file("local/file1.txt", content="111", dt=dt)
    write_test_file("local/file2.txt", content="222", dt=dt)
    write_test_file("local/file3.txt", content="333", dt=dt)
    write_test_file("local/folder1/file1_1.txt", content="1.111", dt=dt)
    write_test_file("local/folder2/file2_1.txt", content="2.111", dt=dt)
    write_test_file("local/big_file.txt", size=1024 * 16, dt=dt)
    # Create empty ../remote/
    os.mkdir(os.path.join(PYFTPSYNC_TEST_FOLDER, "remote"))