Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not apply nutriscore prediction if it does not match the current nutriscore of the product #772

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/unit/workers/tasks/test_import_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from PIL import Image
from robotoff.utils import get_image_from_url, get_logger, http_session

image = get_image_from_url('https://world.openfoodfacts.org/images/products/802/509/314/0251/4.jpg', error_raise=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, but you should put it in the repository instead (in a tests/data directory for example), we wont to avoid tests depending on an external service.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



def test_import_insights_from_image(mocker):
barcode = "4640028621441"
source_image = 'https://world.openfoodfacts.org/images/products/802/509/314/0251/4.jpg'
ocr_url = 'https://world.openfoodfacts.org/images/products/802/509/314/0251/4.json'
sever_domain = 'http://openfoodfacts.org/'

expected_predictions_all = get_predictions_from_image(barcode, image, source_image, ocr_url, sever_domain)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange that you call it, to mock it !
In test you won't have a model.
Instead you should create a list of Prediction using PredictionFactory.

You are a bit lost maybe because you don't know what to put inside it, but what you are testing should tell you what to put in it. I can also provides you some data from production.


predictions_all_mock = mocker.patch(
"robotoff.workers.tasks.import_image.import_insights_from_image.get_predictions_from_image",
return_value=[expected_predictions_all],
)

imported_mock = import_insights(predictions_all, server_domain, automatic=True)