Example #1
0
    def test_no_error_is_raised_if_the_thumb_is_heavier_than_100_ko(self):
        # given
        with open(MODULE_PATH / '..' / 'files/mouette_full_size.jpg',
                  'rb') as f:
            thumb = f.read()

        try:
            # when
            check_thumb_quality(thumb)
        except:
            # then
            assert False, 'Images heavier than 100 ko should be accepted'
Example #2
0
    def test_an_error_is_raised_if_the_thumb_is_too_light(self):
        # given
        with open(MODULE_PATH / '..' / 'files/mouette_thumbnail.jpg',
                  'rb') as f:
            thumb = f.read()

        # when
        with pytest.raises(ApiErrors) as e:
            check_thumb_quality(thumb)

        # then
        assert e.value.errors['thumb'] == ["L'image doit faire 100 ko minimum"]
Example #3
0
def create_mediation():
    check_thumb_in_request(files=request.files, form=request.form)
    offerer_id = dehumanize(request.form['offererId'])
    offer_id = dehumanize(request.form['offerId'])
    credit = request.form.get('credit')
    ensure_current_user_has_rights(RightsType.editor, offerer_id)
    mediation = create_new_mediation(offer_id, offerer_id, current_user,
                                     credit)
    thumb = read_thumb(files=request.files, form=request.form)
    check_thumb_quality(thumb)
    PcObject.save(mediation)
    save_thumb(mediation, thumb, 0, crop=_get_crop(request.form))
    return jsonify(as_dict(mediation)), 201
Example #4
0
    def test_an_error_is_raised_if_the_thumb_height_is_less_than_400_px(self):
        # given
        with open(MODULE_PATH / '..' / 'files/mouette_landscape.jpg',
                  'rb') as f:
            thumb = f.read()

        # when
        with pytest.raises(ApiErrors) as e:
            check_thumb_quality(thumb)

        # then
        assert e.value.errors['thumb'] == [
            "L'image doit faire 400 * 400 px minimum"
        ]