def testGetTopLevelCategories(self):
     """
     """
     cm = ICategoryManagement(self.shop)
     ids = [c.id for c in cm.getTopLevelCategories()]
     
     self.assertEqual(ids, ["category_1", "category_2", "category_3"])
    def testGetCategories(self):
        """
        """        
        cm = ICategoryManagement(self.shop)
        ids = [c.id for c in cm.getCategories()]

        self.failUnless("category_1"   in ids)
        self.failUnless("category_2"   in ids)        
        self.failUnless("category_11"  in ids)
        self.failUnless("category_111" in ids)
Esempio n. 3
0
    def testGetCategories(self):
        """
        """
        cm = ICategoryManagement(self.portal.myshop.categories.category_1)
        category_ids = [c.id for c in cm.getCategories()]
        
        for id in ["category_11", "category_12", "category_111"]:
            self.failUnless(id in category_ids)
        
        cm = ICategoryManagement(self.portal.myshop.categories.category_1.category_11)
        category_ids = [c.id for c in cm.getCategories()]
        self.assertEqual(["category_111"], category_ids)

        cm = ICategoryManagement(self.portal.myshop.categories.category_2)
        self.failUnless(len(cm.getCategories()) == 0)
    def testGetTopLevelCategories_1(self):
        """
        """
        cm = ICategoryManagement(self.product_1)

        ids = [c.getId() for c in cm.getTopLevelCategories()]
        self.assertEqual(ids, ["category_11"])

        # adding some more
        self.shop.categories.invokeFactory("Category", id="category_a")
        self.shop.categories.invokeFactory("Category", id="category_b")

        self.shop.categories.category_a.addReference(self.product_1,
                                                     "categories_products")
        self.shop.categories.category_b.addReference(self.product_1,
                                                     "categories_products")

        ids = [c.getId() for c in cm.getTopLevelCategories()]

        self.failUnless(len(ids) == 3)
        for id in ["category_11", "category_a", "category_b"]:
            self.failUnless(id in ids)
    def testGetTopLevelCategories_1(self):
        """
        """
        cm = ICategoryManagement(self.product_1)

        ids = [c.getId() for c in cm.getTopLevelCategories()]        
        self.assertEqual(ids, ["category_11"])

        # adding some more
        self.shop.categories.invokeFactory("Category", id="category_a")
        self.shop.categories.invokeFactory("Category", id="category_b")
        
        self.shop.categories.category_a.addReference(
            self.product_1, 
            "categories_products")
        self.shop.categories.category_b.addReference(
            self.product_1, 
            "categories_products")
                                        
        ids = [c.getId() for c in cm.getTopLevelCategories()]
        
        self.failUnless(len(ids) == 3)
        for id in ["category_11", "category_a", "category_b"]:
            self.failUnless(id in ids)
Esempio n. 6
0
    def testGetTopLevelCategories(self):
        """
        """
        cm = ICategoryManagement(self.portal.myshop.categories.category_1)
        category_ids = [c.id for c in cm.getTopLevelCategories()]
        
        self.failUnless(len(category_ids) == 2)
        for id in ["category_11", "category_12"]:
            self.failUnless(id in category_ids)

        cm = ICategoryManagement(self.category_2)
        self.failUnless(len(cm.getCategories()) == 0)
Esempio n. 7
0
def categories(object, portal, **kwargs):
    """Indexes all categories and parent categories of a product.
    """
    try:
        result = {}
        if IProduct.providedBy(object):
            for category in ICategoryManagement(object).getTopLevelCategories():
                result[category.UID()] = 1
                
                # Collect parent categories
                object = category
                while object is not None:
                    result[object.UID()] = 1
                    object = object.getParentCategory()
            
        return result.keys()
        
    except (ComponentLookupError, TypeError, ValueError):
        raise AttributeError
 def testGetTopLevelCategories_2(self):
     """No categories there
     """
     cm = ICategoryManagement(self.product_3)
     self.assertEqual(cm.getTopLevelCategories(), [])
 def testGetTopLevelCategories_2(self):
     """No categories there
     """
     cm = ICategoryManagement(self.product_3)
     self.assertEqual(cm.getTopLevelCategories(), [])