def test_image_brand_annotation(client, monkeypatch, fake_taxonomy): ann = LogoAnnotationFactory( image_prediction__image__source_image="/images/2.jpg", annotation_type="brand" ) barcode = ann.image_prediction.image.barcode _fake_store(monkeypatch, barcode) monkeypatch.setattr( BRAND_PREFIX_STORE, "get", lambda: {("Etorki", "0000000xxxxxx")} ) start = datetime.utcnow() result = client.simulate_post( "/api/v1/images/logos/annotate", json={ "withCredentials": True, "annotations": [{"logo_id": ann.id, "value": "etorki", "type": "brand"}], }, headers=_AUTH_HEADER, ) end = datetime.utcnow() assert result.status_code == 200 assert result.json == {"created insights": 1} ann = LogoAnnotation.get(LogoAnnotation.id == ann.id) assert ann.annotation_type == "brand" assert ann.annotation_value == "etorki" assert ann.annotation_value_tag == "etorki" assert ann.taxonomy_value == "Etorki" assert ann.username == "a" assert start <= ann.completed_at <= end # we generate a prediction predictions = list(Prediction.select().filter(barcode=barcode).execute()) assert len(predictions) == 1 (prediction,) = predictions assert prediction.type == "brand" assert prediction.data == { "logo_id": ann.id, "confidence": 1.0, "username": "******", "is_annotation": True, "notify": True, } assert prediction.value == "Etorki" assert prediction.value_tag == "Etorki" assert prediction.predictor == "universal-logo-detector" assert start <= prediction.timestamp <= end assert prediction.automatic_processing # We check that this prediction in turn generates an insight insights = list(ProductInsight.select().filter(barcode=barcode).execute()) assert len(insights) == 1 (insight,) = insights assert insight.type == "brand" assert insight.data == { "logo_id": ann.id, "confidence": 1.0, "username": "******", "is_annotation": True, "notify": True, } assert insight.value == "Etorki" assert insight.value_tag == "Etorki" assert insight.predictor == "universal-logo-detector" assert start <= prediction.timestamp <= end assert insight.automatic_processing assert insight.username == "a" assert insight.completed_at is None # we did not run annotate yet
def test_image_label_annotation(client, monkeypatch, fake_taxonomy): """This test will check that, given an image with a logo above the confidence threshold, that is then fed into the ANN logos and labels model, we annotate properly a product. """ ann = LogoAnnotationFactory(image_prediction__image__source_image="/images/2.jpg") barcode = ann.image_prediction.image.barcode _fake_store(monkeypatch, barcode) start = datetime.utcnow() result = client.simulate_post( "/api/v1/images/logos/annotate", json={ "withCredentials": True, "annotations": [ {"logo_id": ann.id, "value": "EU Organic", "type": "label"} ], }, headers=_AUTH_HEADER, ) end = datetime.utcnow() assert result.status_code == 200 assert result.json == {"created insights": 1} ann = LogoAnnotation.get(LogoAnnotation.id == ann.id) assert ann.annotation_type == "label" assert ann.annotation_value == "EU Organic" assert ann.annotation_value_tag == "eu-organic" assert ann.taxonomy_value == "en:eu-organic" assert ann.username == "a" assert start <= ann.completed_at <= end # we generate a prediction predictions = list(Prediction.select().filter(barcode=barcode).execute()) assert len(predictions) == 1 (prediction,) = predictions assert prediction.type == "label" assert prediction.data == { "logo_id": ann.id, "confidence": 1.0, "username": "******", "is_annotation": True, "notify": True, } assert prediction.value is None assert prediction.value_tag == "en:eu-organic" assert prediction.predictor == "universal-logo-detector" assert start <= prediction.timestamp <= end assert prediction.automatic_processing # We check that this prediction in turn generates an insight insights = list(ProductInsight.select().filter(barcode=barcode).execute()) assert len(insights) == 1 (insight,) = insights assert insight.type == "label" assert insight.data == { "logo_id": ann.id, "confidence": 1.0, "username": "******", "is_annotation": True, "notify": True, } assert insight.value is None assert insight.value_tag == "en:eu-organic" assert insight.predictor == "universal-logo-detector" assert start <= prediction.timestamp <= end assert insight.automatic_processing assert insight.username == "a" assert insight.completed_at is None