def test_image_too_small(self, mock_check_image, app, offer, offerer): # given mock_check_image.side_effect = exceptions.ImageTooSmall(min_width=400, min_height=400) client = TestClient( app.test_client()).with_auth(email="*****@*****.**") data = { "offerId": humanize(offer.id), "offererId": humanize(offerer.id), "thumbUrl": "https://example.com/image.jpg", } # when with requests_mock.Mocker() as request_mock: request_mock.get( "https://example.com/image.jpg", content=b"plop", headers={"Content-Type": "image/jpeg"}, ) response = client.post("/offers/thumbnails", form=data) # then assert response.status_code == 400 assert response.json == { "errors": ["Utilisez une image plus grande (supérieure à 400px par 400px)"] }
def test_image_too_small(self, mock_check_image, app, offer, offerer): # given mock_check_image.side_effect = exceptions.ImageTooSmall(min_width=400, min_height=400) client = TestClient(app.test_client()).with_session_auth(email="*****@*****.**") thumb = (IMAGES_DIR / "mouette_small.jpg").read_bytes() data = { "offerId": humanize(offer.id), "thumb": (BytesIO(thumb), "image.jpg"), } # when response = client.post("/offers/thumbnails", form=data) # then mock_check_image.assert_called_once() assert response.status_code == 400 assert response.json == {"errors": ["Utilisez une image plus grande (supérieure à 400px par 400px)"]}
def test_image_too_small(self, mock_get_distant_image, app): # Given body = {"url": "https://example.com/icon.jpeg"} user = ProFactory() auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) mock_get_distant_image.side_effect = exceptions.ImageTooSmall( min_width=400, min_height=400) # When response = auth_request.post("/offers/thumbnail-url-validation", json=body) # Then assert response.status_code == 200 assert response.json == { "errors": ["Utilisez une image plus grande (supérieure à 400px par 400px)"], "image": None, }
def test_image_too_small(self, mock_get_distant_image, caplog, app): # Given caplog.set_level(logging.INFO) body = {"url": "https://example.com/icon.jpeg"} user = UserFactory() auth_request = TestClient(app.test_client()).with_auth(email=user.email) mock_get_distant_image.side_effect = exceptions.ImageTooSmall(min_width=400, min_height=400) # When response = auth_request.post( "/offers/thumbnail-url-validation", json=body, headers={"origin": "http://localhost:3000"} ) # Then assert response.status_code == 200 assert ( caplog.records[0].message == "When validating image at: https://example.com/icon.jpeg, this error was encountered: ImageTooSmall" ) assert response.json == { "errors": ["Utilisez une image plus grande (supérieure à 400px par 400px)"], "image": None, }