예제 #1
0
 def test_ovh_gcp_backends_call(self, mock_gcp_store_public_object,
                                mock_ovh_store_public_object):
     store_public_object("bucket", "object_id", b"mouette", "image/jpeg")
     mock_ovh_store_public_object.assert_called_once_with(
         "bucket", "object_id", b"mouette", "image/jpeg", None)
     mock_gcp_store_public_object.assert_called_once_with(
         "bucket", "object_id", b"mouette", "image/jpeg", None)
def create_thumb(
    model_with_thumb: Model,
    image_as_bytes: bytes,
    image_index: int,
    crop_params: tuple = None,
) -> None:
    image_as_bytes = standardize_image(image_as_bytes, crop_params)

    object_storage.store_public_object(
        bucket=settings.BASE_BUCKET_NAME,
        object_id=model_with_thumb.get_thumb_storage_id(image_index),
        blob=image_as_bytes,
        content_type="image/jpeg",
    )
예제 #3
0
def save_venue_banner(user: User, venue: Venue, content: bytes, content_type: str, file_name: str) -> None:
    bucket_name = settings.BASE_BUCKET_NAME
    object_id = f"venue_{venue.id}_banner"

    object_storage.store_public_object(
        bucket=bucket_name,
        object_id=object_id,
        blob=content,
        content_type=f"image/{content_type.lower()}",
    )

    venue.bannerUrl = str(pathlib.Path(settings.OBJECT_STORAGE_URL, bucket_name, object_id))
    venue.bannerMeta = {"content_type": content_type, "file_name": file_name, "author_id": user.id}

    repository.save(venue)
예제 #4
0
def store_public_object_from_sandbox_assets(folder, model, subcategoryId):
    mimes_by_folder = {"spreadsheets": "application/CSV", "thumbs": "image/jpeg", "zips": "application/zip"}
    thumb_id = humanize(model.id)
    thumbs_folder_path = Path(pcapi.sandboxes.__path__[0]) / "thumbs"
    picture_path = str(thumbs_folder_path / "mediations" / subcategoryId) + ".jpg"
    with open(picture_path, mode="rb") as thumb_file:
        if folder == "thumbs":
            create_thumb(model, thumb_file.read(), 0)
            model.thumbCount += 1
        else:
            store_public_object(
                folder,
                model.thumb_path_component + "/" + thumb_id,
                thumb_file.read(),
                mimes_by_folder[folder],
            )

    return model
예제 #5
0
def create_thumb(
    model_with_thumb: Model,
    image_as_bytes: bytes,
    image_index: int,
    crop_params: tuple = None,
    symlink_path: str = None,
    use_v2: bool = False,
) -> None:
    if use_v2:
        image_as_bytes = standardize_image_v2(image_as_bytes, crop_params)
    else:
        image_as_bytes = standardize_image(image_as_bytes, crop_params)

    object_storage.store_public_object(
        bucket="thumbs",
        object_id=model_with_thumb.get_thumb_storage_id(image_index),
        blob=image_as_bytes,
        content_type="image/jpeg",
        symlink_path=symlink_path,
    )
예제 #6
0
def store_public_object_from_sandbox_assets(folder, model, offer_type):
    mimes_by_folder = {
        "spreadsheets": "application/CSV",
        "thumbs": "image/jpeg",
        "zips": "application/zip"
    }
    plural_model_name = get_model_plural_name(model)
    thumb_id = humanize(model.id)
    thumb_path = f"{os.path.dirname(os.path.realpath(__file__))}/../../{folder}/{plural_model_name}/{str(offer_type)}"

    with open(thumb_path, mode="rb") as thumb_file:
        if folder == "thumbs":
            create_thumb(model, thumb_file.read(), 0, symlink_path=thumb_path)
            model.thumbCount += 1
        else:
            store_public_object(
                folder,
                plural_model_name + "/" + thumb_id,
                thumb_file.read(),
                mimes_by_folder[folder],
                symlink_path=thumb_path,
            )

    return model
예제 #7
0
 def test_local_backend_call(self, mock_local_store_public_object):
     store_public_object("bucket", "object_id", b"mouette", "image/jpeg")
     mock_local_store_public_object.assert_called_once_with(
         "bucket", "object_id", b"mouette", "image/jpeg")