def test_content_too_large(self, mock_get_distant_image, app, offer, offerer): # given mock_get_distant_image.side_effect = exceptions.FileSizeExceeded(max_size=10_000_000) client = TestClient(app.test_client()).with_session_auth(email="*****@*****.**") data = { "offerId": humanize(offer.id), "thumbUrl": "https://example.com/image.jpg", } # when response = client.post("/offers/thumbnails", form=data) # then assert response.status_code == 400 assert response.json == {"errors": ["Utilisez une image dont le poids est inférieur à 10.0 MB"]}
def test_content_too_large(self, mock_check_image, app, offer, offerer): # given mock_check_image.side_effect = exceptions.FileSizeExceeded(max_size=10_000_000) client = TestClient(app.test_client()).with_session_auth(email="*****@*****.**") thumb = (IMAGES_DIR / "mouette_full_size.jpg").read_bytes() data = { "offerId": humanize(offer.id), "thumb": (BytesIO(thumb), "image.jpg"), } # when response = client.post("/offers/thumbnails", form=data) # then assert response.status_code == 400 assert response.json == {"errors": ["Utilisez une image dont le poids est inférieur à 10.0 MB"]}
def test_image_size_too_large(self, mock_get_distant_image, caplog, app): # Given caplog.set_level(logging.INFO) body = {"url": "https://example.com/wallpaper.jpg"} user = UserFactory() auth_request = TestClient(app.test_client()).with_auth(email=user.email) mock_get_distant_image.side_effect = exceptions.FileSizeExceeded(max_size=10_000_000) # 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/wallpaper.jpg, this error was encountered: FileSizeExceeded" ) assert response.json == {"errors": ["Utilisez une image dont le poids est inférieur à 10.0 MB"], "image": None}
def test_image_size_too_large(self, mock_get_distant_image, app): # Given body = {"url": "https://example.com/wallpaper.jpg"} user = ProFactory() auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) mock_get_distant_image.side_effect = exceptions.FileSizeExceeded( max_size=10_000_000) # When response = auth_request.post("/offers/thumbnail-url-validation", json=body) # Then assert response.status_code == 200 assert response.json == { "errors": ["Utilisez une image dont le poids est inférieur à 10.0 MB"], "image": None }