def test_breadcrumbs_singleton(self): brd = Breadcrumbs() brd(**self.data[0]) brd2 = Breadcrumbs() brd2(**self.data[1]) # test 3 instances to see if singleton really works self.assertEqual(self.breadcrumbs[0].__dict__, Breadcrumb(**self.data[0]).__dict__) self.assertEqual(self.breadcrumbs[1].__dict__, Breadcrumb(**self.data[1]).__dict__) self.assertEqual(brd[1].__dict__, Breadcrumbs()[1].__dict__)
def __fill_bds(self, bd): """ simple interface to add Breadcrumb to bds """ if hasattr(bd, 'name') and hasattr(bd, 'url'): bd = Breadcrumb(bd.name, bd.url) else: bd = Breadcrumb(*bd) if bd.url not in self.__urls: self.__bds.append(bd) self.__urls.append(bd.url)
def __validate(self, obj, index): """ check for object type and return a string as name for each item of a list or tuple with items, if error was found raise BreadcrumbsInvalidFormat """ # for list or tuple if type(obj) in (list, tuple): if len(obj) == 2: if (not obj[0] and not obj[1]) or \ (type(obj[0]) not in (str, unicode) and \ type(obj[1]) not in (str, unicode)): raise BreadcrumbsInvalidFormat(u"Invalid format for \ breadcrumb %s in %s" % (index, type(obj).__name__)) if len(obj) != 2: raise BreadcrumbsInvalidFormat( u"Wrong itens number in breadcrumb %s in %s. \ You need to send as example (name,url)" % \ (index, type(obj).__name__) ) # for objects and dicts else: if isinstance(obj, dict) and obj.get('name') and obj.get('url'): obj = Breadcrumb(obj['name'], obj['url']) if not hasattr(obj, 'name') and not hasattr(obj, 'url'): raise BreadcrumbsInvalidFormat( u"You need to use a tuple like " "(name, url) or dict or one object with name and url " "attributes for breadcrumb.") return True
def test_breadcrumbs_params_and_iteration(self): b = self.breadcrumbs b(self.data[0]['name'], self.data[0]['url']) b(*self.data[1].values()) b(**self.data[2]) b(self.data[3:5]) for i, bd in enumerate(b): self.assertEqual(bd.__dict__, Breadcrumb(**self.data[i]).__dict__)
def test_breadcrumb_class(self): b = Breadcrumb(**self.data[0]) self.assertEqual(b.name, self.data[0]['name']) self.assertEqual(b.url, self.data[0]['url'])
def test_breadcrumb_class(self): b = Breadcrumb("Home", "/") self.assertEqual(b.name, "Home") self.assertEqual(b.url, "/")