Example #1
0
    def __testListingMatched(self, products, listing, should_match=True):
        """ Helper method for the tests. We test if listing is found as a match
        for one of products. If should_match == False, we instead check that
        listing is not found as a match for product."""

        if isinstance(products, str):
            products = [products]

        self.matcher = ProductListingMatcher("", "", "")
        self.matcher._ProductListingMatcher__loadProducts(products)
        self.matcher._ProductListingMatcher__matchListings([listing])

        for product_set in (filter(
                lambda x: len(x) != 0,
                self.matcher._ProductListingMatcher__product_dict.values())):
            product, = product_set
            listing_results = self.matcher._ProductListingMatcher__product_listing_dict[
                product]
            if should_match:
                self.assertEqual(len(listing_results), 1)
            else:
                self.assertEqual(len(listing_results), 0)