示例#1
0
async def add_files(authorized_transport, bucket):
    blob_names = []
    for info in ALL_FILES:
        to_upload = get_contents_for_upload(info)
        blob_name = get_blob_name(info)

        blob_names.append(blob_name)
        if u"metadata" in info:
            upload = resumable_requests.MultipartUpload(utils.MULTIPART_UPLOAD)
            metadata = copy.deepcopy(info[u"metadata"])
            metadata[u"name"] = blob_name
            response = await upload.transmit(
                authorized_transport, to_upload, metadata, info[u"content_type"]
            )
        else:
            upload_url = utils.SIMPLE_UPLOAD_TEMPLATE.format(blob_name=blob_name)
            upload = resumable_requests.SimpleUpload(upload_url)
            response = await upload.transmit(
                authorized_transport, to_upload, info[u"content_type"]
            )

        assert response.status == http_client.OK

    yield

    # Clean-up the blobs we created.
    for blob_name in blob_names:
        await delete_blob(authorized_transport, blob_name)
示例#2
0
async def simple_file(authorized_transport, bucket):
    blob_name = u"basic-file.txt"
    upload_url = utils.SIMPLE_UPLOAD_TEMPLATE.format(blob_name=blob_name)
    upload = resumable_requests.SimpleUpload(upload_url)
    data = b"Simple contents"
    response = await upload.transmit(authorized_transport, data, PLAIN_TEXT)
    assert response.status == http_client.OK

    yield blob_name, data

    await delete_blob(authorized_transport, blob_name)
示例#3
0
async def secret_file(authorized_transport, bucket):
    blob_name = u"super-seekrit.txt"
    data = b"Please do not tell anyone my encrypted seekrit."

    upload_url = utils.SIMPLE_UPLOAD_TEMPLATE.format(blob_name=blob_name)
    headers = utils.get_encryption_headers()
    upload = resumable_requests.SimpleUpload(upload_url, headers=headers)
    response = await upload.transmit(authorized_transport, data, PLAIN_TEXT)
    assert response.status == http_client.OK

    yield blob_name, data, headers

    await delete_blob(authorized_transport, blob_name)
示例#4
0
async def test_simple_upload(authorized_transport, bucket, cleanup):
    with open(ICO_FILE, u"rb") as file_obj:
        actual_contents = file_obj.read()

    blob_name = os.path.basename(ICO_FILE)
    # Make sure to clean up the uploaded blob when we are done.

    await cleanup(blob_name, authorized_transport)
    await check_does_not_exist(authorized_transport, blob_name)

    # Create the actual upload object.
    upload_url = utils.SIMPLE_UPLOAD_TEMPLATE.format(blob_name=blob_name)
    upload = resumable_requests.SimpleUpload(upload_url)
    # Transmit the resource.
    response = await upload.transmit(authorized_transport, actual_contents,
                                     ICO_CONTENT_TYPE)
    await check_response(response, blob_name, actual_contents=actual_contents)
    # Download the content to make sure it's "working as expected".
    await check_content(blob_name, actual_contents, authorized_transport)
    # Make sure the upload is tombstoned.
    await check_tombstoned(upload, authorized_transport, actual_contents,
                           ICO_CONTENT_TYPE)
示例#5
0
async def test_simple_upload_with_headers(authorized_transport, bucket,
                                          cleanup):
    blob_name = u"some-stuff.bin"
    # Make sure to clean up the uploaded blob when we are done.
    await cleanup(blob_name, authorized_transport)
    await check_does_not_exist(authorized_transport, blob_name)

    # Create the actual upload object.
    upload_url = utils.SIMPLE_UPLOAD_TEMPLATE.format(blob_name=blob_name)
    headers = utils.get_encryption_headers()
    upload = resumable_requests.SimpleUpload(upload_url, headers=headers)
    # Transmit the resource.
    data = b"Binary contents\x00\x01\x02."
    response = await upload.transmit(authorized_transport, data,
                                     BYTES_CONTENT_TYPE)
    await check_response(response,
                         blob_name,
                         actual_contents=data,
                         content_type=BYTES_CONTENT_TYPE)
    # Download the content to make sure it's "working as expected".
    await check_content(blob_name, data, authorized_transport, headers=headers)
    # Make sure the upload is tombstoned.
    await check_tombstoned(upload, authorized_transport, data,
                           BYTES_CONTENT_TYPE)