Пример #1
0
 def check(self):
     from pcs_api.bytes_io import (MemoryByteSource, MemoryByteSink,
                                   StdoutProgressListener)
     from pcs_api.models import (CPath, CUploadRequest, CDownloadRequest)
     msg = "Cloud storage user_id = " + repr(self.storage.get_user_id())
     self.ctx.logger.info(msg)
     msg = "Cloud storage quota = " + repr(self.storage.get_quota())
     self.ctx.logger.info(msg)
     self.ctx.logger.info("Cloud storage is  ready")
     fpath = CPath('/test_dir')
     self.storage.create_folder(fpath)
     bpath = fpath.add("test.txt")
     file_contents_uploaded = b"Test file contents"
     upload_request = CUploadRequest(
         bpath, MemoryByteSource(file_contents_uploaded)).content_type(
             'text/plain')
     upload_request.progress_listener(StdoutProgressListener())
     self.storage.upload(upload_request)
     file_contents_downloaded = MemoryByteSink()
     download_request = CDownloadRequest(bpath, file_contents_downloaded)
     download_request.progress_listener(StdoutProgressListener())
     self.storage.download(download_request)
     self.storage.delete(fpath)
     if file_contents_uploaded != file_contents_downloaded.get_bytes():
         raise RemotePCSError
Пример #2
0
def test_cpath():
    p = CPath("/foo//bar€/")
    assert p.path_name() == "/foo/bar€"
    assert p.url_encoded() == "/foo/bar%E2%82%AC"
    assert p.base_name() == "bar€"
    assert p.parent() == CPath("/foo")
    assert p.add("a,file...") == CPath("/foo/bar€/a,file...")
    assert p.add("/a,file...") == CPath("/foo/bar€/a,file...")
    assert p.add("a,file.../") == CPath("/foo/bar€/a,file...")
    assert p.add("/several//folders/he re/") == CPath("/foo/bar€/several/folders/he re")
    assert p.is_root() is False
    assert p.parent().is_root() is False
    root = p.parent().parent()
    assert root.is_root() is True
    assert root.parent().is_root() is True
    assert root == CPath("/")
    assert root == CPath("")
    assert root.base_name() == ""
    assert root.split() == []
    assert CPath("").split() == []
    assert CPath("/a").split() == ["a"]
    assert CPath('/alpha/"beta').split() == ["alpha", '"beta']
Пример #3
0
def test_cpath():
    p = CPath('/foo//bar€/')
    assert p.path_name() == '/foo/bar€'
    assert p.url_encoded() == '/foo/bar%E2%82%AC'
    assert p.base_name() == 'bar€'
    assert p.parent() == CPath('/foo')
    assert p.add('a,file...') == CPath('/foo/bar€/a,file...')
    assert p.add('/a,file...') == CPath('/foo/bar€/a,file...')
    assert p.add('a,file.../') == CPath('/foo/bar€/a,file...')
    assert p.add('/several//folders/he re/') == CPath('/foo/bar€/several/folders/he re')
    assert p.is_root() is False
    assert p.parent().is_root() is False
    root = p.parent().parent()
    assert root.is_root() is True
    assert root.parent().is_root() is True
    assert root == CPath('/')
    assert root == CPath('')
    assert root.base_name() == ''
    assert root.split() == []
    assert CPath('').split() == []
    assert CPath('/a').split() == ['a']
    assert CPath('/alpha/"beta').split() == ['alpha', '"beta']
Пример #4
0
        print("  ", f)
    # Add folders to list :
    folders_to_process += folders

# Create a folder and upload a test file :
root_folder_content = storage.list_root_folder()
# root_folder_content is a dict
# keys are files paths, values are CFolder or CBlob providing details (length, content-type...)
print('root folder content :', root_folder_content)

# Create a new folder :
fpath = CPath('/pcs_api_new_folder')
storage.create_folder(fpath)

# Upload a local file in this folder :
bpath = fpath.add('pcs_api_new_file')
file_content = b'this is file content...'
upload_request = CUploadRequest(bpath, MemoryByteSource(file_content)).content_type('text/plain')
storage.upload(upload_request)

# Download back the file :
mbs = MemoryByteSink()
download_request = CDownloadRequest(bpath, mbs)
storage.download(download_request)
assert mbs.get_bytes() == file_content

# delete remote folder :
storage.delete(fpath)

# Example : we'll download a range of largest blob :
if largest_blob:
Пример #5
0
        print("  ", f)
    # Add folders to list :
    folders_to_process += folders

# Create a folder and upload a test file :
root_folder_content = storage.list_root_folder()
# root_folder_content is a dict
# keys are files paths, values are CFolder or CBlob providing details (length, content-type...)
print('root folder content :', root_folder_content)

# Create a new folder :
fpath = CPath('/pcs_api_new_folder')
storage.create_folder(fpath)

# Upload a local file in this folder :
bpath = fpath.add('pcs_api_new_file')
file_content = b'this is file content...'
upload_request = CUploadRequest(
    bpath, MemoryByteSource(file_content)).content_type('text/plain')
storage.upload(upload_request)

# Download back the file :
mbs = MemoryByteSink()
download_request = CDownloadRequest(bpath, mbs)
storage.download(download_request)
assert mbs.get_bytes() == file_content

# delete remote folder :
storage.delete(fpath)

# Example : we'll download a range of largest blob :