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 all commits
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
82 changes: 82 additions & 0 deletions tests/unit/workers/tasks/test_import_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import requests
from PIL import Image

from robotoff import settings
from tests.integration.models_utils import PredictionFactory


def test_import_insights_from_image(mocker):
barcode = "3302740030949"
source_image = "https://world.openfoodfacts.org/images/products/330/274/003/0949/front_fr.110.400.jpg"
ocr_url = "https://world.openfoodfacts.org/images/products/802/509/314/0251/4.json"
server_domain = settings.OFF_SERVER_DOMAIN

image = Image.open(requests.get(source_image, stream=True).raw)

mock_import_insights = mocker.patch(
"robotoff.insights.importer.import_insights", return_value=4
)
mock_get_predictions_from_image = mocker.patch(
"robotoff.insights.extraction.get_predictions_from_image"
Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the code I was not able to figure out what will get_predictions_from_image return

)

predictions_list = [
PredictionFactory(
type="label",
barcode=3302740030949,
data={
"model": "nutriscore",
"confidence": 0.871872,
"bounding_box": [1441.3848, 1036.8024, 1685.6928, 1430.2488],
},
value_tag="en:nutriscore-c",
value="",
automatic_processing=False,
),
PredictionFactory(
type="label",
barcode=3302740030949,
data={
"model": "nutriscore",
"confidence": 0.816114128,
"bounding_box": [0.591395915, 0.477426708, 0.688566923, 0.624632716],
},
value_tag="en:nutriscore-a",
value="",
automatic_processing=False,
),
PredictionFactory(
type="label",
barcode=3302740030949,
data={
"model": "nutriscore",
"confidence": 0.913557172,
"bounding_box": [0.596912444, 0.429353863, 0.70557, 0.592592061],
},
value_tag="en:nutriscore-c",
value="",
automatic_processing=False,
),
PredictionFactory(
type="label",
barcode=3302740030949,
data={
"model": "nutriscore",
"confidence": 0.99035,
"bounding_box": [0.575399518, 0.472130537, 0.691237211, 0.625134587],
},
value_tag="en:nutriscore-e",
value="",
automatic_processing=False,
),
]

mock_import_insights.assert_called_once_with(
predictions=predictions_list,
server_domain=server_domain,
automatic=True,
)

mock_get_predictions_from_image.assert_called_once_with(
Copy link
Member Author

Choose a reason for hiding this comment

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

Both assert_called_once_with throw the error saying assert_called_once_with shou d be called once but called 0 times

I was not able to resolve it. I did see the existing examples in the code. I read where to patch and tried to follow the steps in the document but no luck.

barcode=barcode, image=image, source_image=source_image, ocr_url=ocr_url
)