Example #1
0
    def test_revision_include(self):
        """Simple include markup."""
        p = WikiParser(True)
        d = document(title='Test title')
        d.save()
        r = revision(document=d, content='Test content', is_approved=True)
        r.save()

        # Existing title returns document's content
        doc = pq(p.parse('[[Include:Test title]]'))
        eq_('Test content', doc.text())

        # Nonexisting title returns 'Document not found'
        doc = pq(p.parse('[[Include:Another title]]'))
        eq_('The document "Another title" does not exist.', doc.text())
Example #2
0
 def setUp(self):
     self.d = document(title='Installing Firefox')
     self.d.save()
     self.r = revision(document=self.d, content='Test content',
                       is_approved=True)
     self.r.save()
     self.p = WikiParser()
Example #3
0
 def setUp(self):
     self.p = WikiParser()
Example #4
0
class TestWikiParser(TestCase):
    def setUp(self):
        self.d = document(title='Installing Firefox')
        self.d.save()
        self.r = revision(document=self.d, content='Test content',
                          is_approved=True)
        self.r.save()
        self.p = WikiParser()

    def setUp(self):
        self.p = WikiParser()

    def test_image_path_sanity(self):
        """Image URLs are prefixed with the upload path."""
        eq_(settings.WIKI_UPLOAD_URL + 'file.png',
            self.p._getImagePath('file.png'))

    def test_image_path_special_chars(self):
        """Image URLs with Unicode are prefixed with the upload path."""
        eq_(settings.WIKI_UPLOAD_URL + 'parl%C3%A9%20Fran%C3%A7ais.png',
            self.p._getImagePath(u'parl\u00e9 Fran\u00e7ais.png'))

    def test_image_params_page(self):
        """_buildImageParams handles wiki pages."""
        items = ['page=Installing Firefox']
        params = self.p._buildImageParams(items)
        eq_('/kb/Installing+Firefox', params['link'])

    def test_image_params_link(self):
        """_buildImageParams handles external links."""
        items = ['link=http://example.com']
        params = self.p._buildImageParams(items)
        eq_('http://example.com', params['link'])

    def test_image_params_page_link(self):
        """_buildImageParams - wiki page overrides link."""
        items = ['page=Installing Firefox', 'link=http://example.com']
        params = self.p._buildImageParams(items)
        eq_('/kb/Installing+Firefox', params['link'])

    def test_image_params_align(self):
        """Align valid options."""
        align_vals = ('none', 'left', 'center', 'right')
        for align in align_vals:
            items = ['align=' + align]
            params = self.p._buildImageParams(items)
            eq_(align, params['align'])

    def test_image_params_align_invalid(self):
        """Align invalid options."""
        items = ['align=zzz']
        params = self.p._buildImageParams(items)
        assert not 'align' in params, 'Align is present in params'

    def test_image_params_valign(self):
        """Vertical align valid options."""
        valign_vals = ('baseline', 'sub', 'super', 'top', 'text-top',
                       'middle', 'bottom', 'text-bottom')
        for valign in valign_vals:
            items = ['valign=' + valign]
            params = self.p._buildImageParams(items)
            eq_(valign, params['valign'])

    def test_image_params_valign_invalid(self):
        """Vertical align invalid options."""
        items = ['valign=zzz']
        params = self.p._buildImageParams(items)
        assert not 'valign' in params, 'Vertical align is present in params'

    def test_image_params_alt(self):
        """Image alt override."""
        items = ['alt=some alternative text']
        params = self.p._buildImageParams(items)
        eq_('some alternative text', params['alt'])

    def test_image_params_frameless(self):
        """Frameless image."""
        items = ['frameless']
        params = self.p._buildImageParams(items)
        eq_(True, params['frameless'])

    def test_image_params_width_height(self):
        """Image width."""
        items = ['width=10', 'height=20']
        params = self.p._buildImageParams(items)
        eq_('10', params['width'])
        eq_('20', params['height'])

    def test_get_wiki_link(self):
        """Wiki links are properly built for existing pages."""
        eq_('/kb/Installing+Firefox',
            self.p._getWikiLink('Installing Firefox'))
Example #5
0
class TestWikiInternalLinks(TestCase):
    def setUp(self):
        self.d = document(title='Installing Firefox')
        self.d.save()
        self.r = revision(document=self.d, content='Test content',
                          is_approved=True)
        self.r.save()
        self.p = WikiParser()

    def setUp(self):
        self.p = WikiParser()

    def test_simple(self):
        """Simple internal link markup."""
        link = pq_link(self.p, '[[Installing Firefox]]')
        eq_('/kb/Installing+Firefox', link.attr('href'))
        eq_('Installing Firefox', link.text())

    def test_simple_markup(self):
        text = '[[Installing Firefox]]'
        eq_('<p><a href="/kb/Installing+Firefox" rel="nofollow">' +
            'Installing Firefox</a>\n</p>',
            self.p.parse(text))

    def test_link_hash(self):
        """Internal link with hash."""
        link = pq_link(self.p, '[[Installing Firefox#section name]]')
        eq_('/kb/Installing+Firefox#section_name', link.attr('href'))
        eq_('Installing Firefox#section name', link.text())

    def test_link_hash_markup(self):
        """Internal link with hash."""
        text = '[[Installing Firefox#section name]]'
        eq_('<p><a href="/kb/Installing+Firefox#section_name"' +
                ' rel="nofollow">Installing Firefox#section name</a>\n</p>',
            self.p.parse(text))

    def test_hash_only(self):
        """Internal hash only."""
        link = pq_link(self.p, '[[#section 3]]')
        eq_('#section_3', link.attr('href'))
        eq_('#section 3', link.text())

    def test_link_name(self):
        """Internal link with name."""
        link = pq_link(self.p, '[[Installing Firefox|this name]]')
        eq_('/kb/Installing+Firefox', link.attr('href'))
        eq_('this name', link.text())

    def test_link_with_extra_pipe(self):
        link = pq_link(self.p, '[[Installing Firefox|with|pipe]]')
        eq_('/kb/Installing+Firefox', link.attr('href'))
        eq_('with|pipe', link.text())

    def test_hash_name(self):
        """Internal hash with name."""
        link = pq_link(self.p, '[[#section 3|this name]]')
        eq_('#section_3', link.attr('href'))
        eq_('this name', link.text())

    def test_link_hash_name(self):
        """Internal link with hash and name."""
        link = pq_link(self.p, '[[Installing Firefox#section 3|this name]]')
        eq_('/kb/Installing+Firefox#section_3', link.attr('href'))
        eq_('this name', link.text())

    def test_link_hash_name_markup(self):
        """Internal link with hash and name."""
        text = '[[Installing Firefox#section 3|this name]]'
        eq_('<p><a href="/kb/Installing+Firefox#section_3"' +
            ' rel="nofollow">this name</a>\n</p>', self.p.parse(text))

    def test_simple_create(self):
        """Simple link for inexistent page."""
        link = pq_link(self.p, '[[A new page]]')
        eq_('/kb/A+new+page', link.attr('href'))
        eq_('A new page', link.text())

    def test_link_edit_hash_name(self):
        """Internal link for inexistent page with hash and name."""
        link = pq_link(self.p, '[[A new page#section 3|this name]]')
        eq_('/kb/A+new+page#section_3', link.attr('href'))
        eq_('this name', link.text())
Example #6
0
class TestWikiParser(TestCase):
    def setUp(self):
        self.d = document(title="Installing Firefox")
        self.d.save()
        self.r = revision(document=self.d, content="Test content", is_approved=True)
        self.r.save()
        self.p = WikiParser()

    def test_image_path_sanity(self):
        """Image URLs are prefixed with the upload path."""
        eq_(settings.WIKI_UPLOAD_URL + "file.png", self.p._getImagePath("file.png"))

    def test_image_path_special_chars(self):
        """Image URLs with Unicode are prefixed with the upload path."""
        eq_(
            settings.WIKI_UPLOAD_URL + "parl%C3%A9%20Fran%C3%A7ais.png",
            self.p._getImagePath(u"parl\u00e9 Fran\u00e7ais.png"),
        )

    def test_image_params_page(self):
        """_buildImageParams handles wiki pages."""
        items = ["page=Installing Firefox"]
        params = self.p._buildImageParams(items)
        eq_("/kb/Installing+Firefox", params["link"])

    def test_image_params_link(self):
        """_buildImageParams handles external links."""
        items = ["link=http://example.com"]
        params = self.p._buildImageParams(items)
        eq_("http://example.com", params["link"])

    def test_image_params_page_link(self):
        """_buildImageParams - wiki page overrides link."""
        items = ["page=Installing Firefox", "link=http://example.com"]
        params = self.p._buildImageParams(items)
        eq_("/kb/Installing+Firefox", params["link"])

    def test_image_params_align(self):
        """Align valid options."""
        align_vals = ("none", "left", "center", "right")
        for align in align_vals:
            items = ["align=" + align]
            params = self.p._buildImageParams(items)
            eq_(align, params["align"])

    def test_image_params_align_invalid(self):
        """Align invalid options."""
        items = ["align=zzz"]
        params = self.p._buildImageParams(items)
        assert not "align" in params, "Align is present in params"

    def test_image_params_valign(self):
        """Vertical align valid options."""
        valign_vals = ("baseline", "sub", "super", "top", "text-top", "middle", "bottom", "text-bottom")
        for valign in valign_vals:
            items = ["valign=" + valign]
            params = self.p._buildImageParams(items)
            eq_(valign, params["valign"])

    def test_image_params_valign_invalid(self):
        """Vertical align invalid options."""
        items = ["valign=zzz"]
        params = self.p._buildImageParams(items)
        assert not "valign" in params, "Vertical align is present in params"

    def test_image_params_alt(self):
        """Image alt override."""
        items = ["alt=some alternative text"]
        params = self.p._buildImageParams(items)
        eq_("some alternative text", params["alt"])

    def test_image_params_frameless(self):
        """Frameless image."""
        items = ["frameless"]
        params = self.p._buildImageParams(items)
        eq_(True, params["frameless"])

    def test_image_params_width_height(self):
        """Image width."""
        items = ["width=10", "height=20"]
        params = self.p._buildImageParams(items)
        eq_("10", params["width"])
        eq_("20", params["height"])

    def test_get_wiki_link(self):
        """Wiki links are properly built for existing pages."""
        eq_("/kb/Installing+Firefox", self.p._getWikiLink("Installing Firefox"))