def test_set_non_str_attribute_casts_to_string(self): # If the value of the attribute passed to set_attribute is not a # string, it's cast to a string. tag = Tag('whatever', self.req) tag.set_attribute('new-attribute', 42) result = tag.get_attribute('new-attribute') self.assertEqual('42', result)
def test_set_then_get_attribute(self): # Attributes set with set_attribute can be retrieved with # get_attribute. tag = Tag('whatever', self.req) tag.set_attribute('new-attribute', 'value') result = tag.get_attribute('new-attribute') self.assertEqual('value', result)
def test_set_name_doesnt_call_save(self): # Setting the name attribute doesn't call save. save_calls = [] tag = Tag('old', self.req) try: tag.set_attribute('name', 'new') except Set_Name_Attribute_Error: pass self.assertEqual(0, len(save_calls))
def test_set_name_attribute_does_nothing(self): # The 'name' attribute is set by the constructor. After it is set, it # cannot be changed with further calls to set_attribute. tag = Tag('old', self.req) try: tag.set_attribute('name', 'new') except Set_Name_Attribute_Error: pass self.assertEqual('old', tag.get_name()) self.assertEqual('old', tag.get_attribute('name'))
class TestTag(TestCase): def setUp(self): self.tag = Tag('foo', None) # Do not allow notifying related tasks self.tag.notify_related_tasks = lambda: None def test_has_name(self): self.assertEqual('foo', self.tag.get_name()) def test_name_is_attribute(self): self.assertEqual('foo', self.tag.get_attribute('name')) def test_missing_attribute_returns_none(self): self.assertEqual(None, self.tag.get_attribute('no-such-attribute')) def test_set_then_get_attribute(self): self.tag.set_attribute('new-attribute', 'value') attr = self.tag.get_attribute('new-attribute') self.assertEqual('value', attr) def test_set_non_str_attribute_casts_to_string(self): self.tag.set_attribute('new-attribute', 42) attr = self.tag.get_attribute('new-attribute') self.assertEqual('42', attr) def test_initial_attribute_is_name_only(self): self.assertEqual(['name'], self.tag.get_all_attributes()) def test_can_add_new_attributes(self): self.tag.set_attribute('bar', 'baz') self.assertEqual({'name', 'bar'}, set(self.tag.get_all_attributes())) def test_get_all_attributes_but_name(self): self.assertEqual([], self.tag.get_all_attributes(butname=True)) self.tag.set_attribute('bar', 'baz') self.assertEqual(['bar'], self.tag.get_all_attributes(butname=True)) def test_name_cannot_be_changed(self): self.assertEqual('foo', self.tag.get_name()) with self.assertRaises(KeyError): self.tag.set_attribute('name', 'new') self.assertEqual('foo', self.tag.get_name()) self.assertEqual('foo', self.tag.get_attribute('name'))
def test_get_all_but_name(self): # If 'butname' is True, then exclude the 'name' attribute. tag = Tag('foo', self.req) self.assertEqual([], tag.get_all_attributes(butname=True)) tag.set_attribute('bar', 'baz') self.assertEqual(['bar'], tag.get_all_attributes(butname=True))
def test_get_all_attributes_after_setting(self): # After attributes are set, get_all_attributes includes those # attributes. The order is not guaranteed. tag = Tag('foo', self.req) tag.set_attribute('bar', 'baz') self.assertEqual(set(['name', 'bar']), set(tag.get_all_attributes()))
def get_tags_tree(self, req): '''This create a liblarch tree suitable for tags, including the all_tags_tag and notag_tag. ''' tagtree = Tree() ### building the initial tags # Build the "all tasks tag" alltag = Tag(CoreConfig.ALLTASKS_TAG, req=req) alltag.set_attribute("special", "all") alltag.set_attribute("label", "<span weight='bold'>%s</span>" % _("All tasks")) alltag.set_attribute("icon", "gtg-tags-all") alltag.set_attribute("order", 0) tagtree.add_node(alltag) p = {} self.tasktree.add_filter(CoreConfig.ALLTASKS_TAG, self.alltag, parameters=p) # Build the "without tag tag" notag_tag = Tag(CoreConfig.NOTAG_TAG, req=req) notag_tag.set_attribute("special", "notag") notag_tag.set_attribute( "label", "<span weight='bold'>%s</span>" % _("Tasks with no tags")) notag_tag.set_attribute("icon", "gtg-tags-none") notag_tag.set_attribute("order", 2) tagtree.add_node(notag_tag) p = {} self.tasktree.add_filter(CoreConfig.NOTAG_TAG, self.notag, parameters=p) # Build the search tag search_tag = Tag(CoreConfig.SEARCH_TAG, req=req) search_tag.set_attribute("special", "search") search_tag.set_attribute("label", "<span weight='bold'>%s</span>" % _("Search")) search_tag.set_attribute("icon", "search") search_tag.set_attribute("order", 1) tagtree.add_node(search_tag) p = {} self.tasktree.add_filter(CoreConfig.SEARCH_TAG, search_filter, parameters=p) # Build the separator sep_tag = Tag(CoreConfig.SEP_TAG, req=req) sep_tag.set_attribute("special", "sep") sep_tag.set_attribute("order", 3) tagtree.add_node(sep_tag) #### Filters tagtree.add_filter('activetag', self.actively_used_tag) tagtree.add_filter('usedtag', self.used_tag) activeview = tagtree.get_viewtree(name='activetags', refresh=False) activeview.apply_filter('activetag') # This view doesn't seem to be used. So it's not useful to build it now # usedview = tagtree.get_viewtree(name='usedtags',refresh=False) # usedview.apply_filter('usedtag') self.tagtree = tagtree self.tagtree_loaded = True return tagtree
def get_tags_tree(self, req): """This create a liblarch tree suitable for tags, including the all_tags_tag and notag_tag. """ tagtree = Tree() ### building the initial tags # Build the "all tasks tag" alltag = Tag(CoreConfig.ALLTASKS_TAG, req=req) alltag.set_attribute("special", "all") alltag.set_attribute("label", "<span weight='bold'>%s</span>" % _("All tasks")) alltag.set_attribute("icon", "gtg-tags-all") alltag.set_attribute("order", 0) tagtree.add_node(alltag) p = {} self.tasktree.add_filter(CoreConfig.ALLTASKS_TAG, self.alltag, parameters=p) # Build the "without tag tag" notag_tag = Tag(CoreConfig.NOTAG_TAG, req=req) notag_tag.set_attribute("special", "notag") notag_tag.set_attribute("label", "<span weight='bold'>%s</span>" % _("Tasks with no tags")) notag_tag.set_attribute("icon", "gtg-tags-none") notag_tag.set_attribute("order", 2) tagtree.add_node(notag_tag) p = {} self.tasktree.add_filter(CoreConfig.NOTAG_TAG, self.notag, parameters=p) # Build the search tag search_tag = Tag(CoreConfig.SEARCH_TAG, req=req) search_tag.set_attribute("special", "search") search_tag.set_attribute("label", "<span weight='bold'>%s</span>" % _("Search")) search_tag.set_attribute("icon", "search") search_tag.set_attribute("order", 1) tagtree.add_node(search_tag) p = {} self.tasktree.add_filter(CoreConfig.SEARCH_TAG, search_filter, parameters=p) # Build the separator sep_tag = Tag(CoreConfig.SEP_TAG, req=req) sep_tag.set_attribute("special", "sep") sep_tag.set_attribute("order", 3) tagtree.add_node(sep_tag) #### Filters tagtree.add_filter("activetag", self.actively_used_tag) tagtree.add_filter("usedtag", self.used_tag) activeview = tagtree.get_viewtree(name="activetags", refresh=False) activeview.apply_filter("activetag") # This view doesn't seem to be used. So it's not useful to build it now # usedview = tagtree.get_viewtree(name='usedtags',refresh=False) # usedview.apply_filter('usedtag') self.tagtree = tagtree self.tagtree_loaded = True return tagtree