def test_check_image_quality(self): user = users_factories.UserFactory() offer = factories.ThingOfferFactory() image_as_bytes = (IMAGES_DIR / "mouette_small.jpg").read_bytes() with pytest.raises(models.ApiErrors) as error: api.create_mediation(user, offer, "credits", image_as_bytes) assert error.value.errors["thumb"] == ["L'image doit faire 400 * 400 px minimum"] assert models.Mediation.query.count() == 0
def test_crop_params(self, mocked_store_public_object): user = users_factories.UserFactory() offer = factories.ThingOfferFactory() image_as_bytes = (IMAGES_DIR / "mouette_full_size.jpg").read_bytes() crop_params = (0.8, 0.8, 1) mediation = api.create_mediation(user, offer, "credits", image_as_bytes, crop_params) assert mediation.thumbCount == 1 resized_as_bytes = mocked_store_public_object.call_args[1]["blob"] resized = PIL.Image.open(io.BytesIO(resized_as_bytes)) assert resized.size == (357, 357)
def test_create_mediation_basics(self, mocked_add_offer_id): user = users_factories.UserFactory() offer = factories.ThingOfferFactory() image_as_bytes = (IMAGES_DIR / "mouette_full_size.jpg").read_bytes() mediation = api.create_mediation(user, offer, "credits", image_as_bytes) assert mediation.author == user assert mediation.offer == offer assert mediation.credit == "credits" assert mediation.thumbCount == 1 mocked_add_offer_id.assert_called_once_with(client=app.redis_client, offer_id=offer.id)
def create_thumbnail(form: CreateThumbnailBodyModel) -> CreateThumbnailResponseModel: offer = get_offer_by_id(form.offer_id) check_user_has_access_to_offerer(current_user, offer.venue.managingOffererId) image_as_bytes = form.get_image_as_bytes(request) thumbnail = offers_api.create_mediation( user=current_user, offer=offer, credit=form.credit, image_as_bytes=image_as_bytes, crop_params=form.crop_params, ) return CreateThumbnailResponseModel(id=thumbnail.id)
def create_mediation( form: CreateMediationBodyModel) -> MediationResponseIdModel: ensure_current_user_has_rights(RightsType.editor, form.offerer_id) offer = get_offer_by_id(form.offer_id) image_as_bytes = form.get_image_as_bytes(request) mediation = offers_api.create_mediation( user=current_user, offer=offer, credit=form.credit, image_as_bytes=image_as_bytes, crop_params=form.crop_params, ) return MediationResponseIdModel.from_orm(mediation)
def create_mediation( form: CreateMediationBodyModel) -> MediationResponseIdModel: check_user_has_access_to_offerer(current_user, form.offerer_id) offer = get_offer_by_id(form.offer_id) image_as_bytes = form.get_image_as_bytes(request) mediation = offers_api.create_mediation( user=current_user, offer=offer, credit=form.credit, image_as_bytes=image_as_bytes, crop_params=form.crop_params, ) return MediationResponseIdModel.from_orm(mediation)