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_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_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)
     tag.set_attribute('name', 'new')
     self.assertEqual('old', tag.get_name())
     self.assertEqual('old', tag.get_attribute('name'))
    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 = {'transparent':True}
        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",1)
        tagtree.add_node(notag_tag)
        p = {'transparent':True}
        self.tasktree.add_filter(CoreConfig.NOTAG_TAG,\
                                    self.notag,parameters=p)
        # Build the separator
        sep_tag = Tag(CoreConfig.SEP_TAG,req=req)
        sep_tag.set_attribute("special","sep")
        sep_tag.set_attribute("order",2)
        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 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 test_get_all_attributes_initial(self):
     # Initially, a Tag has only the name attribute.
     tag = Tag('foo', self.req)
     self.assertEqual(['name'], tag.get_all_attributes())
 def test_missing_attribute_returns_none(self):
     # If get_attribute is called for an attribute that doesn't exist, it
     # returns None.
     tag = Tag('whatever', self.req)
     result = tag.get_attribute('no-such-attribute')
     self.assertEqual(None, result)
 def test_name_is_attribute(self):
     # The name of the tag is also stored as an attribute.
     tag = Tag('foo', self.req)
     self.assertEqual('foo', tag.get_attribute('name'))
 def test_name(self):
     # The first argument to the Tag constructor is the name, which you can
     # get with get_name().
     tag = Tag('foo', self.req)
     self.assertEqual('foo', tag.get_name())
 def test_set_name_doesnt_call_save(self):
     # Setting the name attribute doesn't call save.
     save_calls = []
     tag = Tag('old', self.req)
     tag.set_attribute('name', 'new')
     self.assertEqual(0, len(save_calls))