Exemple #1
0
    def is_valid(self, barcode: str, tag: str, seen_set: Set[str]) -> bool:
        brand_prefix: Set[Tuple[str, str]] = BRAND_PREFIX_STORE.get()
        brand_blacklist: Set[str] = BRAND_BLACKLIST_STORE.get()

        if tag in seen_set:
            return False

        if tag in brand_blacklist:
            return False

        if not in_barcode_range(brand_prefix, tag, barcode):
            logger.warn("Barcode {} of brand {} not in barcode "
                        "range".format(barcode, tag))
            return False

        product = self.product_store[barcode]

        if not product:
            return True

        if product.brands_tags:
            # For now, don't annotate if a brand has already been provided
            return False

        return True
Exemple #2
0
    def is_valid(barcode: str, tag: str) -> bool:
        brand_prefix: Set[Tuple[str, str]] = BRAND_PREFIX_STORE.get()

        if not in_barcode_range(brand_prefix, tag, barcode):
            logger.info(
                f"Barcode {barcode} of brand {tag} not in barcode range")
            return False

        return True
Exemple #3
0
    def is_valid(self, product: Optional[Product], barcode: str, tag: str,
                 seen_set: Set[str]) -> bool:
        brand_prefix: Set[Tuple[str, str]] = BRAND_PREFIX_STORE.get()

        if not in_barcode_range(brand_prefix, tag, barcode):
            logger.warn("Barcode {} of brand {} not in barcode "
                        "range".format(barcode, tag))
            return False

        return True
Exemple #4
0
    def is_valid(self, insight: ProductInsight, product: Optional[Product] = None):
        brand_prefix = BRAND_PREFIX_STORE.get()
        brand_tag = insight.value_tag
        barcode = insight.barcode

        if not in_barcode_range(brand_prefix, brand_tag, barcode):
            logger.info(
                "Barcode {} of brand {} not in barcode "
                "range".format(barcode, brand_tag)
            )
            return False

        if product is None:
            product = self.product_store[insight.barcode]

            if product is None:
                return True

        if brand_tag in product.brands_tags:
            return False

        return True
def test_in_barcode_range(barcode, brand_tag, is_valid):
    brand_prefix = BRAND_PREFIX_STORE.get()
    assert in_barcode_range(brand_prefix, brand_tag, barcode) is is_valid