def test_download_public_file(test_blob):
    storage_make_public.make_blob_public(test_blob.bucket.name, test_blob.name)
    with tempfile.NamedTemporaryFile() as dest_file:
        storage_download_public_file.download_public_file(
            test_blob.bucket.name, test_blob.name, dest_file.name)

        assert dest_file.read() == b"Hello, is it me you're looking for?"
示例#2
0
def upload_dir(source, destination):
    arr = os.listdir(source)
    for item in arr:
        if (os.path.isfile(os.path.join(source, item))):
            storage_upload_file.upload_blob(constants.bucket_name,
                                            os.path.join(source, item),
                                            destination + item, 'image/webp')
            storage_make_public.make_blob_public(constants.bucket_name,
                                                 destination + item)
示例#3
0
def observation_ok(observation_key, observation, images, scales):

    i = 0
    for image in images:
        extension = image.filename[image.filename.rindex('.'):]
        filename = image.filename

        if '.jpg' != extension:
            image.save(filename.replace(extension, '.jpg'))
            storage_upload_file.upload_blob(constants.bucket_name, filename.replace(extension, '.jpg'),
                                            observation['photoPaths'][i].replace(extension, '.jpg'), 'image/jpeg')
            storage_make_public.make_blob_public(constants.bucket_name, observation['photoPaths'][i].replace(extension,
                                                                                                             '.jpg'))
        else:
            storage_make_public.make_blob_public(constants.bucket_name, observation['photoPaths'][i])

        size = min(image.width, image.height)
        image = utils.crop_square(image, size, size, scales[i])
        if size > 512:
            image = image.resize((512, 512), Image.ANTIALIAS)
        image.save(filename.replace(extension, '.webp'))
        storage_upload_file.upload_blob(constants.bucket_name, filename.replace(extension, '.webp'),
                                        observation['photoPaths'][i].replace(extension, '.webp'), 'image/webp')
        storage_make_public.make_blob_public(constants.bucket_name, observation['photoPaths'][i].replace(extension,
                                                                                                         '.webp'))
        i += 1
        image.close()

    observation['status'] = 'public'
    i = 0
    for path in observation['photoPaths']:
        extension = path[path.rindex('.'):]
        observation['photoPaths'][i] = observation['photoPaths'][i].replace(extension, '.webp')
        i += 1
    ref_public_by_date.child(observation_key).update(observation)
    ref_public_by_plant.child(observation['plant']).child('list').child(observation_key).update(observation)

    user = observation['id'][:observation['id'].index('_')]
    ref_private.child(user).child('by date').child('list').child(observation['id']).update(
        observation)
    ref_private.child(user).child('by plant').child(observation['plant']).child('list').child(
        observation['id']).update(observation)
    root.destroy()
示例#4
0
def test_make_blob_public(test_public_blob):
    storage_make_public.make_blob_public(
        test_public_blob.bucket.name, test_public_blob.name)

    r = requests.get(test_public_blob.public_url)
    assert r.text == "Hello, is it me you're looking for?"