コード例 #1
0
    def test_upload(self, tmpfile: Path, remote_tmpdir: DriveFolder):
        local_file = tmpfile(size_bytes=1024)

        # No chunksize specified
        remote_file = remote_tmpdir.new_file(str(local_file.parent))
        remote_file.upload(str(local_file))
        assert md5_file(local_file) == remote_file.md5sum

        # Chunksize = None
        remote_file = remote_tmpdir.new_file(str(local_file.parent))
        remote_file.upload(str(local_file), chunksize=None)
        assert md5_file(local_file) == remote_file.md5sum
コード例 #2
0
 def test_upload_resume_with_stored_uri(self, tmpfile: Path,
                                        remote_tmpdir: DriveFolder):
     chunksize = chunksize_min
     local_file = tmpfile(size_bytes=chunksize * 2)
     remote_file = remote_tmpdir.new_file(local_file.name)
     progress = ProgressExtractor(abort_at=0.0)
     with pytest.raises(AbortTransfer):
         remote_file.upload(str(local_file),
                            chunksize=chunksize,
                            progress_handler=progress.update_status)
     remote_file = remote_tmpdir.new_file(local_file.name)
     remote_file.upload(str(local_file),
                        chunksize=chunksize,
                        resumable_uri=progress.status.resumable_uri)
コード例 #3
0
    def test_upload_remote_file_does_not_match(self, tmpfile: Path,
                                               remote_tmpdir: DriveFolder):
        chunksize = chunksize_min
        local_file_orig = tmpfile(size_bytes=chunksize * 3)
        local_file_same_size = tmpfile(size_bytes=chunksize * 3)
        local_file_different_size = tmpfile(size_bytes=None)
        shutil.copy(str(local_file_orig), str(local_file_different_size))
        with local_file_different_size.open('ba') as fh:
            fh.write(os.urandom(chunksize))

        ## Test size mismatch
        remote_file = remote_tmpdir.new_file(local_file_orig.name)
        progress = ProgressExtractor(abort_at=0.0)
        with pytest.raises(AbortTransfer):
            remote_file.upload(str(local_file_orig),
                               chunksize=chunksize,
                               progress_handler=progress.update_status)
        assert progress.status.resumable_progress == chunksize

        with pytest.raises(HttpError):
            remote_file.upload(str(local_file_different_size),
                               chunksize=chunksize)

        ## Test checksum mismatch on intermediate chunk
        remote_file = remote_tmpdir.new_file(local_file_orig.name)
        progress = ProgressExtractor(abort_at=0.0)
        with pytest.raises(AbortTransfer):
            remote_file.upload(str(local_file_orig),
                               chunksize=chunksize,
                               progress_handler=progress.update_status)
        assert progress.status.resumable_progress == chunksize

        with pytest.raises(CheckSumError):
            remote_file.upload(str(local_file_same_size), chunksize=chunksize)
        assert remote_file.resumable_uri == None

        ## Test checksum mismatch on last chunk
        remote_file = remote_tmpdir.new_file(local_file_orig.name)
        progress = ProgressExtractor(abort_at=0.6)
        with pytest.raises(AbortTransfer):
            remote_file.upload(str(local_file_orig),
                               chunksize=chunksize,
                               progress_handler=progress.update_status)
        assert progress.status.resumable_progress == 2 * chunksize

        with pytest.raises(CheckSumError):
            remote_file.upload(str(local_file_same_size), chunksize=chunksize)
        assert remote_file.resumable_uri == None
コード例 #4
0
 def test_rename_only_target_dir_no_basename(self,
                                             remote_tmpdir: DriveFolder):
     remote_file = remote_tmpdir.new_file("filename")
     remote_file.upload_empty()
     remote_tmpdir.create_path("1/2/3")
     remote_file.rename("1/2/3")
     assert remote_tmpdir.child_from_path("1/2/3/filename") == remote_file
コード例 #5
0
 def test_new_file(self, tmpfile: Path, remote_tmpdir: DriveFolder):
     new_file = remote_tmpdir.new_file(random_string())
     assert isinstance(new_file, (DriveFile))
     assert new_file.isfolder() == False
     assert new_file.id == None
     with pytest.raises(FileNotFoundError):
         new_file.download(tmpfile)
コード例 #6
0
 def test_upload_chunksize_too_small(self, tmpfile: Path,
                                     remote_tmpdir: DriveFolder):
     chunksize = 1
     local_file = tmpfile(size_bytes=chunksize * 2)
     remote_file = remote_tmpdir.new_file(local_file.name)
     with pytest.raises(HttpError):
         remote_file.upload(str(local_file), chunksize=chunksize)
コード例 #7
0
 def test_upload_chunksize_bigger_than_filesize(self, tmpfile: Path,
                                                remote_tmpdir: DriveFolder):
     chunksize = 100
     local_file = tmpfile(size_bytes=int(chunksize / 2))
     remote_file = remote_tmpdir.new_file(local_file.name)
     remote_file.upload(str(local_file), chunksize=chunksize)
     assert md5_file(local_file) == remote_file.md5sum
コード例 #8
0
    def test_children_trashed(self, remote_tmpdir: DriveFolder):
        remote_file = remote_tmpdir.new_file(random_string())
        remote_file.upload_empty()
        remote_file.trash()

        assert remote_file not in remote_tmpdir.children()
        assert remote_file in remote_tmpdir.children(trashed=True)
コード例 #9
0
    def test_rename_flat(self, remote_tmpdir: DriveFolder):
        remote_file = remote_tmpdir.new_file(random_string())
        remote_file.upload_empty()
        new_name = random_string()

        remote_file.rename(new_name)
        assert remote_file.name == new_name
        assert remote_tmpdir.child(new_name) == remote_file
コード例 #10
0
    def test_children_onlyfiles(self, remote_tmpdir: DriveFolder):
        remote_folder = remote_tmpdir.mkdir(random_string())
        remote_file = remote_tmpdir.new_file(random_string())
        remote_file.upload_empty()

        filelist = list(remote_tmpdir.children(folders=False))
        assert remote_folder not in filelist
        assert remote_file in filelist
コード例 #11
0
    def test_child_all(self, remote_tmpdir: DriveFolder):
        foldername = random_string()
        folder = remote_tmpdir.mkdir(foldername)
        assert folder == remote_tmpdir.child(foldername)

        filename = random_string()
        file_ = remote_tmpdir.new_file(filename)
        file_.upload_empty()
        assert file_ == remote_tmpdir.child(filename)
コード例 #12
0
 def test_upload_invalid_resumable_uri(self, tmpfile: Path,
                                       remote_tmpdir: DriveFolder):
     chunksize = chunksize_min
     local_file = tmpfile(size_bytes=chunksize * 2)
     remote_file = remote_tmpdir.new_file(local_file.name)
     progress = ProgressExtractor(abort_at=0.0)
     with pytest.raises(AbortTransfer):
         remote_file.upload(str(local_file),
                            chunksize=chunksize,
                            progress_handler=progress.update_status)
     assert progress.status.resumable_progress == chunksize
     remote_file.resumable_uri = "https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&upload_id=invalid_id"
     with pytest.raises(HttpError):
         remote_file.upload(str(local_file))
コード例 #13
0
 def test_upload_progress_resume(self, tmpfile: Path,
                                 remote_tmpdir: DriveFolder):
     chunksize = chunksize_min
     local_file = tmpfile(size_bytes=chunksize * 5)
     remote_file = remote_tmpdir.new_file(local_file.name)
     progress = ProgressExtractor(abort_at=0.4)
     with pytest.raises(AbortTransfer):
         remote_file.upload(str(local_file),
                            chunksize=chunksize,
                            progress_handler=progress.update_status)
     assert progress.status.resumable_progress == 2 * chunksize
     progress.abort_at = 1
     remote_file.upload(str(local_file),
                        chunksize=chunksize,
                        progress_handler=progress.update_status)
     assert progress.chunks_since_last_abort == 3
コード例 #14
0
 def test_rename_target_dir_does_not_exist(self,
                                           remote_tmpdir: DriveFolder):
     remote_file = remote_tmpdir.new_file(random_string())
     remote_file.upload_empty()
     with pytest.raises(FileNotFoundError):
         remote_file.rename("a/b")
コード例 #15
0
 def test_upload_empty_file(self, tmpfile: Path,
                            remote_tmpdir: DriveFolder):
     local_file = tmpfile(size_bytes=0)
     remote_file = remote_tmpdir.new_file(str(local_file.parent))
     remote_file.upload(str(local_file))
     assert md5_file(local_file) == remote_file.md5sum
コード例 #16
0
 def test_rename_target_dir_is_a_file(self, remote_tmpdir: DriveFolder):
     remote_file = remote_tmpdir.new_file(random_string())
     remote_file.upload_empty()
     remote_tmpdir.new_file("file").upload_empty()
     with pytest.raises(NotADirectoryError):
         remote_file.rename("file/b")
コード例 #17
0
 def test_isempty(self, remote_tmp_subdir: DriveFolder):
     assert remote_tmp_subdir.isempty() == True
     remote_tmp_subdir.new_file(random_string()).upload_empty()
     assert remote_tmp_subdir.isempty() == False
コード例 #18
0
 def test_rename_subdir(self, remote_tmpdir: DriveFolder):
     remote_file = remote_tmpdir.new_file(random_string())
     remote_file.upload_empty()
     remote_tmpdir.create_path("1/2/3")
     remote_file.rename("1/2/3/b")
     assert remote_tmpdir.child_from_path("1/2/3/b") == remote_file
コード例 #19
0
 def test_mkdir_exists_file(self, remote_tmpdir: DriveFolder):
     foldername = random_string()
     remote_tmpdir.new_file(foldername).upload_empty()
     with pytest.raises(FileExistsError):
         remote_tmpdir.mkdir(foldername)
コード例 #20
0
 def test_rename_target_exists(self, remote_tmpdir: DriveFolder):
     remote_file = remote_tmpdir.new_file(random_string())
     remote_file.upload_empty()
     remote_file.parent.new_file("existing_file").upload_empty()
     remote_file.rename("existing_file")
     assert remote_tmpdir.child("existing_file") == remote_file