#!/www/python/bin/python
"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/test_links.py $
$Id: test_links.py 24756 2004-07-21 16:57:56Z dbinger $
"""

from sancho.unittest import TestScenario, parse_args, run_scenarios

# dulcinea.links requires dulcinea.local.
# This provides a replacement for purposes of this test.
import dulcinea
class TestLocal:
    SITE = 'Test'
dulcinea.local = TestLocal

from dulcinea.links import LinkItem, LinkFolder, sort_reverse_by_date, \
     sort_by_title
from dulcinea.contact import Contact

tested_modules = ["dulcinea.links"]

class LinksTest (TestScenario):

    class AdminContact(Contact):

        def is_admin(self):
            return True

    def check_link(self):
        self.test_stmt("self.link = LinkItem()")
        self.test_stmt("self.link.set_link_url('http://www.mems-exchange.org')")
        self.test_stmt("self.link.get_link_url()")
        self.test_stmt("self.link.get_user()")
        self.test_stmt("self.link.set_text('hi')")
        self.test_val("self.link.get_text()", 'hi')
        self.test_stmt("self.link.set_email('hi')")
        self.test_val("self.link.get_email()", 'hi')
        self.test_stmt("self.link.as_html()")
        self.test_stmt("self.link.as_html(full=1)")
        self.test_stmt("self.link.as_html(action_links='action')")
        self.test_stmt("self.link.as_text()")
        self.test_stmt("self.link.as_rss()")
        self.test_stmt("self.link.as_email()")
        self.test_val("self.link.is_approved()", False)
        self.test_stmt("self.link.set_approved(True)")
        self.test_val("self.link.is_approved()", True)
        self.test_stmt("self.link.get_allowed_mime_types()")
        self.test_stmt("self.link.get_allowed_mime_types("
                       "user=self.AdminContact('superuser'))")
        self.test_val("self.link.get_url()", '/links/None/')
        self.test_stmt("self.link2 = LinkItem()")
        self.test_stmt("[self.link, self.link2].sort(sort_reverse_by_date)")
        self.test_stmt("[self.link, self.link2].sort(sort_by_title)")

    def check_link_folder(self):
        self.test_stmt("self.link_db = LinkFolder()")
        self.test_stmt("self.link_db.get_group('foo')")
        self.test_stmt("self.link_db.links_with_group('foo')")


if __name__ == "__main__":
    (scenarios, options) = parse_args()
    options.show_coverage = 1
    #options.show_coverage_lines = 1
    run_scenarios(scenarios, options)
