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())
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())