"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/utest_links.py $
$Id: utest_links.py 31152 2008-09-18 11:27:09Z dbinger $
"""
from dulcinea.common import CommonTest
from dulcinea.contact import Contact
from dulcinea.links import LinkItem, LinkFolder, get_lower_title


class AdminContact(Contact):

    def is_admin(self):
        return True


class LinksTest (CommonTest):

    def check_link(self):
        self.link = LinkItem()
        self.link.set_link_url('http://www.example.org')
        self.link.get_link_url()
        self.link.set_text('hi')
        assert self.link.get_text() == 'hi'
        self.link.set_email('hi')
        assert self.link.get_email() == 'hi'
        self.link.as_text()
        self.link.as_email()
        assert self.link.is_approved() == False
        self.link.set_approved(True)
        assert self.link.is_approved() == True
        self.link.get_allowed_mime_types()
        self.link.get_allowed_mime_types(user=AdminContact('superuser'))
        assert self.link.get_local_url() == '/links/None/'
        self.link2 = LinkItem()
        [self.link, self.link2].sort(key=get_lower_title)

    def check_link_folder(self):
        self.link_db = LinkFolder()
        self.link_db.get_category('foo')
        self.link_db.links_with_category('foo')


if __name__ == "__main__":
    LinksTest()
