Example #1
0
    def test_non_existent_source_file(self):
        dst = os.path.join(self.tempdir, "a_different_filename.txt")

        self.assertFalse(os.path.exists(dst))

        sync = libgsync.sync.Sync(sys.argv[1], dst)
        sync("file_not_found.txt")

        self.assertFalse(os.path.exists(dst))
Example #2
0
    def test_non_existent_source_file(self):
        dst = os.path.join(self.tempdir, "a_different_filename.txt")

        self.assertFalse(os.path.exists(dst))

        sync = libgsync.sync.Sync(sys.argv[1], dst)
        sync("file_not_found.txt")

        self.assertFalse(os.path.exists(dst))
Example #3
0
    def test_local_files(self):
        src = sys.argv[1]
        dst = os.path.join(self.tempdir, "open_for_read.txt")

        self.assertFalse(os.path.exists(dst))

        sync = libgsync.sync.Sync(src, self.tempdir)
        sync("open_for_read.txt")

        self.assertTrue(os.path.exists(dst))
        self.assertEqual(sha256sum(os.path.join(src, "open_for_read.txt")),
                         sha256sum(dst))
Example #4
0
    def test_local_files(self):
        src = sys.argv[1]
        dst = os.path.join(self.tempdir, "open_for_read.txt")

        self.assertFalse(os.path.exists(dst))

        sync = libgsync.sync.Sync(src, self.tempdir)
        sync("open_for_read.txt")

        self.assertTrue(os.path.exists(dst))
        self.assertEqual(
            sha256sum(os.path.join(src, "open_for_read.txt")),
            sha256sum(dst)
        )
Example #5
0
    def test_local_files_with_different_mimetypes(self):
        src = sys.argv[1]
        dst = os.path.join(self.tempdir, "open_for_read.txt")

        # Copy a binary file to ensure it isn't ascii.
        shutil.copyfile("/bin/true", dst)
        self.assertTrue(os.path.exists(dst))

        sync = libgsync.sync.Sync(src, self.tempdir)
        sync("open_for_read.txt")

        self.assertTrue(os.path.exists(dst))
        self.assertEqual(
            sha256sum(os.path.join(src, "open_for_read.txt")),
            sha256sum(os.path.join(self.tempdir, "open_for_read.txt")))
Example #6
0
    def test_local_files_force_dest_file(self):
        src = sys.argv[1]
        dst = os.path.join(self.tempdir, "a_different_filename.txt")

        libgsync.options.GsyncOptions.force_dest_file = True

        self.assertFalse(os.path.exists(dst))

        sync = libgsync.sync.Sync(src, dst)
        sync("open_for_read.txt")

        self.assertTrue(os.path.exists(dst))

        self.assertEqual(sha256sum(os.path.join(src, "open_for_read.txt")),
                         sha256sum(dst))
Example #7
0
    def test_local_files_with_different_mimetypes(self):
        src = sys.argv[1]
        dst = os.path.join(self.tempdir, "open_for_read.txt")

        # Copy a binary file to ensure it isn't ascii.
        shutil.copyfile("/bin/true", dst)
        self.assertTrue(os.path.exists(dst))

        sync = libgsync.sync.Sync(src, self.tempdir)
        sync("open_for_read.txt")

        self.assertTrue(os.path.exists(dst))
        self.assertEqual(
            sha256sum(os.path.join(src, "open_for_read.txt")),
            sha256sum(os.path.join(self.tempdir, "open_for_read.txt"))
        )
Example #8
0
    def test_local_files_force_dest_file(self):
        src = sys.argv[1]
        dst = os.path.join(self.tempdir, "a_different_filename.txt")

        libgsync.options.GsyncOptions.force_dest_file = True

        self.assertFalse(os.path.exists(dst))

        sync = libgsync.sync.Sync(src, dst)
        sync("open_for_read.txt")

        self.assertTrue(os.path.exists(dst))

        self.assertEqual(
            sha256sum(os.path.join(src, "open_for_read.txt")),
            sha256sum(dst)
        )
Example #9
0
    def test_local_files_with_different_sizes(self):
        src = sys.argv[1]
        dst = os.path.join(self.tempdir, "open_for_read.txt")

        # Copy a binary file to ensure it isn't ascii.
        shutil.copyfile(os.path.join(src, "open_for_read.txt"), dst)

        # Alter the destination file size.
        with open(dst, "a") as f:
            f.write("Some extra text\n")

        sync = libgsync.sync.Sync(src, self.tempdir)
        sync("open_for_read.txt")

        self.assertTrue(os.path.exists(dst))
        self.assertEqual(
            sha256sum(os.path.join(src, "open_for_read.txt")),
            sha256sum(os.path.join(self.tempdir, "open_for_read.txt")))
Example #10
0
    def test_local_files_with_different_sizes(self):
        src = sys.argv[1]
        dst = os.path.join(self.tempdir, "open_for_read.txt")

        # Copy a binary file to ensure it isn't ascii.
        shutil.copyfile(os.path.join(src, "open_for_read.txt"), dst)

        # Alter the destination file size.
        with open(dst, "a") as f:
            f.write("Some extra text\n")

        sync = libgsync.sync.Sync(src, self.tempdir)
        sync("open_for_read.txt")

        self.assertTrue(os.path.exists(dst))
        self.assertEqual(
            sha256sum(os.path.join(src, "open_for_read.txt")),
            sha256sum(os.path.join(self.tempdir, "open_for_read.txt"))
        )