Пример #1
0
def test_blob_content_type(storage):
    if storage.provider_name() == 'dropbox':
        pytest.xfail('Dropbox ignores content type')
    if storage.provider_name() == 'rapidshare':
        pytest.xfail('Rapidshare ignores content type')
    if storage.provider_name() == 'googledrive':
        pytest.xfail('Google drive handles content type quite strangely')
    if storage.provider_name() == 'cloudme':
        pytest.xfail('CloudMe handles content type quite strangely')
    if storage.provider_name() == 'onedrive':
        pytest.xfail('OneDrive ignores content type')

    temp_root_path = miscutils.generate_test_path()
    try:
        logger.info('Will use test folder: %s', temp_root_path)

        # some providers are sensitive to filename suffix, so we do not specify any here:
        c_path = temp_root_path.add('uploaded_blob')
        data = b'some content...'
        content_type = 'text/plain; charset=Latin-1'
        upload_request = CUploadRequest(c_path, MemoryByteSource(data))
        upload_request.content_type(content_type)
        storage.upload(upload_request)

        c_file = storage.get_file(c_path)
        assert c_file.is_blob()
        assert c_file.content_type == content_type

        # Update file content, check content-type is updated also:
        data = b'some\x05binary\xFFcontent...'
        content_type = 'application/octet-stream'
        upload_request = CUploadRequest(c_path, MemoryByteSource(data))
        upload_request.content_type(content_type)
        storage.upload(upload_request)

        c_file = storage.get_file(c_path)
        assert c_file.content_type == content_type
    finally:
        storage.delete(temp_root_path)
Пример #2
0
def test_blob_content_type(storage):
    if storage.provider_name() == 'dropbox':
        pytest.xfail('Dropbox ignores content type')
    if storage.provider_name() == 'rapidshare':
        pytest.xfail('Rapidshare ignores content type')
    if storage.provider_name() == 'googledrive':
        pytest.xfail('Google drive handles content type quite strangely')
    if storage.provider_name() == 'cloudme':
        pytest.xfail('CloudMe handles content type quite strangely')
    if storage.provider_name() == 'onedrive':
        pytest.xfail('OneDrive ignores content type')

    temp_root_path = miscutils.generate_test_path()
    try:
        logger.info('Will use test folder: %s', temp_root_path)

        # some providers are sensitive to filename suffix, so we do not specify any here:
        c_path = temp_root_path.add('uploaded_blob')
        data = b'some content...'
        content_type = 'text/plain; charset=Latin-1'
        upload_request = CUploadRequest(c_path, MemoryByteSource(data))
        upload_request.content_type(content_type)
        storage.upload(upload_request)

        c_file = storage.get_file(c_path)
        assert c_file.is_blob()
        assert c_file.content_type == content_type

        # Update file content, check content-type is updated also:
        data = b'some\x05binary\xFFcontent...'
        content_type = 'application/octet-stream'
        upload_request = CUploadRequest(c_path, MemoryByteSource(data))
        upload_request.content_type(content_type)
        storage.upload(upload_request)

        c_file = storage.get_file(c_path)
        assert c_file.content_type == content_type
    finally:
        storage.delete(temp_root_path)
Пример #3
0
def test_file_with_special_chars(storage):
    temp_root_path = miscutils.generate_test_path()
    try:
        safe_name = _filter_name_for_provider(storage.provider_name(), "hum...\u00a0',;.:\u00a0!*%&~#{[|`_ç^@ £€")
        folder_path = temp_root_path.add(safe_name)

        storage.create_folder(folder_path)
        fback = storage.get_file(folder_path)
        assert fback.path == folder_path
        assert fback.is_folder()
        assert not fback.is_blob()

        # Folder must appear in test root folder list:
        root_test_content = storage.list_folder(temp_root_path)
        assert folder_path in root_test_content
        assert root_test_content[folder_path].path == folder_path
        assert root_test_content[folder_path].is_folder()
        assert not root_test_content[folder_path].is_blob()

        # Generate a random blob name (ensure it does not start nor end with a space)
        nameb = list()
        nameb.append('b')
        for i in range(0,30):
            nameb.append(_generate_random_blob_name_char(storage.provider_name()))
        nameb.append('e')
        blob_path = None
        last_blob_path = None
        for i in range(0,10):
            last_blob_path = blob_path
            # slightly change blob name, so that we get similar but different names:
            index = int(random.random() * (len(nameb) - 2)) + 1
            nameb[index] = _generate_random_blob_name_char(storage.provider_name())
            blob_name = ''.join(nameb)
            blob_path = folder_path.add(blob_name)
            logger.info("Will upload file to path: %r", blob_path)

            content_file = b'This is cont€nt of test file: ' + blob_name.encode('UTF-8')
            upload_request = CUploadRequest(blob_path, MemoryByteSource(content_file))
            upload_request.content_type('text/plain; charset=UTF-8')
            storage.upload(upload_request)
            bback = storage.get_file(blob_path)
            if bback is None:
                logger.error('Test failed with blob_path=%r', blob_path)
                logger.error('            last_blob_path=%r', last_blob_path)
            assert bback is not None
            assert bback.path == blob_path
            assert bback.is_blob()
            assert not bback.is_folder()

            # Download and check content:
            mbs = MemoryByteSink()
            download_request = CDownloadRequest(blob_path, mbs)
            # It has been seen once a 404 error below with google drive:
            # This may be caused by different servers that are not yet informed of file creation ?
            storage.download(download_request)
            mbs.get_bytes() == content_file

            # blob must appear in folder list:
            folder_content = storage.list_folder(folder_path)
            assert blob_path in folder_content
            assert folder_content[blob_path].path == blob_path
            assert folder_content[blob_path].is_blob()
            assert not folder_content[blob_path].is_folder()

    finally:
        storage.delete(temp_root_path)
Пример #4
0
def test_file_with_special_chars(storage):
    temp_root_path = miscutils.generate_test_path()
    try:
        safe_name = _filter_name_for_provider(
            storage.provider_name(),
            "hum...\u00a0',;.:\u00a0!*%&~#{[|`_ç^@ £€")
        folder_path = temp_root_path.add(safe_name)

        storage.create_folder(folder_path)
        fback = storage.get_file(folder_path)
        assert fback.path == folder_path
        assert fback.is_folder()
        assert not fback.is_blob()

        # Folder must appear in test root folder list:
        root_test_content = storage.list_folder(temp_root_path)
        assert folder_path in root_test_content
        assert root_test_content[folder_path].path == folder_path
        assert root_test_content[folder_path].is_folder()
        assert not root_test_content[folder_path].is_blob()

        # Generate a random blob name (ensure it does not start nor end with a space)
        nameb = list()
        nameb.append('b')
        for i in range(0, 30):
            nameb.append(
                _generate_random_blob_name_char(storage.provider_name()))
        nameb.append('e')
        blob_path = None
        last_blob_path = None
        for i in range(0, 10):
            last_blob_path = blob_path
            # slightly change blob name, so that we get similar but different names:
            index = int(random.random() * (len(nameb) - 2)) + 1
            nameb[index] = _generate_random_blob_name_char(
                storage.provider_name())
            blob_name = ''.join(nameb)
            blob_path = folder_path.add(blob_name)
            logger.info("Will upload file to path: %r", blob_path)

            content_file = b'This is cont€nt of test file: ' + blob_name.encode(
                'UTF-8')
            upload_request = CUploadRequest(blob_path,
                                            MemoryByteSource(content_file))
            upload_request.content_type('text/plain; charset=UTF-8')
            storage.upload(upload_request)
            bback = storage.get_file(blob_path)
            if bback is None:
                logger.error('Test failed with blob_path=%r', blob_path)
                logger.error('            last_blob_path=%r', last_blob_path)
            assert bback is not None
            assert bback.path == blob_path
            assert bback.is_blob()
            assert not bback.is_folder()

            # Download and check content:
            mbs = MemoryByteSink()
            download_request = CDownloadRequest(blob_path, mbs)
            # It has been seen once a 404 error below with google drive:
            # This may be caused by different servers that are not yet informed of file creation ?
            storage.download(download_request)
            mbs.get_bytes() == content_file

            # blob must appear in folder list:
            folder_content = storage.list_folder(folder_path)
            assert blob_path in folder_content
            assert folder_content[blob_path].path == blob_path
            assert folder_content[blob_path].is_blob()
            assert not folder_content[blob_path].is_folder()

    finally:
        storage.delete(temp_root_path)