class EntryHtmlContentTestCase(TestCase): def setUp(self): params = { 'title': 'My entry', 'content': 'My content', 'slug': 'my-entry' } self.entry = Entry(**params) self.original_rendering = entry.MARKUP_LANGUAGE def tearDown(self): entry.MARKUP_LANGUAGE = self.original_rendering def test_html_content_default(self): entry.MARKUP_LANGUAGE = None self.assertEquals(self.entry.html_content, '<p>My content</p>') self.entry.content = 'Hello world !\n' \ ' this is my content' self.assertEquals(self.entry.html_content, '<p>Hello world !<br /> this is my content</p>') @skipUnless(is_lib_available('textile'), 'Textile is not available') def test_html_content_textitle(self): entry.MARKUP_LANGUAGE = 'textile' self.entry.content = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' html_content = self.entry.html_content self.assertEquals( html_content, '\t<p>Hello world !</p>\n\n\t' '<p>this is my content :</p>\n\n\t' '<ul>\n\t\t<li>Item 1</li>\n\t\t' '<li>Item 2</li>\n\t</ul>') @skipUnless(is_lib_available('markdown'), 'Markdown is not available') def test_html_content_markdown(self): entry.MARKUP_LANGUAGE = 'markdown' self.entry.content = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' html_content = self.entry.html_content self.assertEquals( html_content, '<p>Hello world !</p>\n' '<p>this is my content :</p>' '\n<ul>\n<li>Item 1</li>\n' '<li>Item 2</li>\n</ul>') @skipUnless(is_lib_available('docutils'), 'Docutils is not available') def test_html_content_restructuredtext(self): entry.MARKUP_LANGUAGE = 'restructuredtext' self.entry.content = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' html_content = self.entry.html_content self.assertEquals( html_content, '<p>Hello world !</p>\n' '<p>this is my content :</p>' '\n<ul class="simple">\n<li>Item 1</li>\n' '<li>Item 2</li>\n</ul>\n')
class MarkupsTestCase(TestCase): text = 'Hello *World* !' @skipUnless(is_lib_available('textile'), 'Textile is not available') def test_textile(self): self.assertEqual( textile(self.text).strip(), '<p>Hello <strong>World</strong> !</p>') @skipUnless(is_lib_available('markdown'), 'Markdown is not available') def test_markdown(self): self.assertEqual( markdown(self.text).strip(), '<p>Hello <em>World</em> !</p>') @skipUnless(is_lib_available('markdown'), 'Markdown is not available') def test_markdown_extensions(self): text = '[TOC]\n\n# Header 1\n\n## Header 2' self.assertEqual( markdown(text).strip(), '<p>[TOC]</p>\n<h1>Header 1</h1>' '\n<h2>Header 2</h2>') self.assertEqual( markdown(text, extensions=['markdown.extensions.toc']).strip(), '<div class="toc">\n<ul>\n<li><a href="#header-1">' 'Header 1</a><ul>\n<li><a href="#header-2">' 'Header 2</a></li>\n</ul>\n</li>\n</ul>\n</div>' '\n<h1 id="header-1">Header 1</h1>\n' '<h2 id="header-2">Header 2</h2>') from markdown.extensions.toc import TocExtension tocext = TocExtension(marker='--TOC--', permalink='PL') self.assertEqual( markdown(text, extensions=[tocext]).strip(), '<p>[TOC]</p>\n<h1 id="header-1">Header 1' '<a class="headerlink" href="#header-1" ' 'title="Permanent link">PL</a></h1>\n' '<h2 id="header-2">Header 2' '<a class="headerlink" href="#header-2" ' 'title="Permanent link">PL</a></h2>') @skipUnless(is_lib_available('docutils'), 'Docutils is not available') def test_restructuredtext(self): self.assertEqual( restructuredtext(self.text).strip(), '<p>Hello <em>World</em> !</p>') @skipUnless(is_lib_available('docutils'), 'Docutils is not available') def test_restructuredtext_settings_override(self): text = 'My email is [email protected]' self.assertEqual( restructuredtext(text).strip(), '<p>My email is <a class="reference external" ' 'href="mailto:toto@example.com">' 'toto@example.com</a></p>') self.assertEqual( restructuredtext(text, { 'cloak_email_addresses': True }).strip(), '<p>My email is <a class="reference external" ' 'href="mailto:toto%40example.com">' 'toto<span>@</span>example<span>.</span>com</a></p>')
class HtmlFormatTestCase(TestCase): def setUp(self): self.original_rendering = markups.MARKUP_LANGUAGE def tearDown(self): markups.MARKUP_LANGUAGE = self.original_rendering def test_html_format_default(self): markups.MARKUP_LANGUAGE = None self.assertEquals(html_format(''), '') self.assertEquals(html_format('Content'), '<p>Content</p>') self.assertEquals(html_format('Content</p>'), 'Content</p>') self.assertEquals(html_format('Hello\nworld!'), '<p>Hello<br />world!</p>') @skipUnless(is_lib_available('textile'), 'Textile is not available') def test_html_content_textitle(self): markups.MARKUP_LANGUAGE = 'textile' value = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' self.assertEqual(html_format(value), '\t<p>Hello world !</p>\n\n\t' '<p>this is my content :</p>\n\n\t' '<ul>\n\t\t<li>Item 1</li>\n\t\t' '<li>Item 2</li>\n\t</ul>') @skipUnless(is_lib_available('markdown'), 'Markdown is not available') def test_html_content_markdown(self): markups.MARKUP_LANGUAGE = 'markdown' value = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' self.assertEqual(html_format(value), '<p>Hello world !</p>\n' '<p>this is my content :</p>' '\n<ul>\n<li>Item 1</li>\n' '<li>Item 2</li>\n</ul>') @skipUnless(is_lib_available('docutils'), 'Docutils is not available') def test_html_content_restructuredtext(self): markups.MARKUP_LANGUAGE = 'restructuredtext' value = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' self.assertEqual(html_format(value), '<p>Hello world !</p>\n' '<p>this is my content :</p>' '\n<ul class="simple">\n<li>Item 1</li>\n' '<li>Item 2</li>\n</ul>\n')
class EntryHtmlContentTestCase(TestCase): def setUp(self): params = {'title': 'My entry', 'content': 'My content', 'slug': 'my-entry'} self.entry = Entry(**params) self.original_rendering = entry.MARKUP_LANGUAGE def tearDown(self): entry.MARKUP_LANGUAGE = self.original_rendering def test_html_content_default(self): entry.MARKUP_LANGUAGE = None self.assertEqual(self.entry.html_content, '<p>My content</p>') self.entry.content = 'Hello world !\n' \ ' this is my content' self.assertEqual(self.entry.html_content, '<p>Hello world !<br /> this is my content</p>') self.entry.content = '' self.assertEqual(self.entry.html_content, '') @skipUnless(is_lib_available('textile'), 'Textile is not available') def test_html_content_textitle(self): entry.MARKUP_LANGUAGE = 'textile' self.entry.content = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' html_content = self.entry.html_content self.assertEqual(html_content, '\t<p>Hello world !</p>\n\n\t' '<p>this is my content :</p>\n\n\t' '<ul>\n\t\t<li>Item 1</li>\n\t\t' '<li>Item 2</li>\n\t</ul>') @skipUnless(is_lib_available('markdown'), 'Markdown is not available') def test_html_content_markdown(self): entry.MARKUP_LANGUAGE = 'markdown' self.entry.content = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' html_content = self.entry.html_content self.assertEqual(html_content, '<p>Hello world !</p>\n' '<p>this is my content :</p>' '\n<ul>\n<li>Item 1</li>\n' '<li>Item 2</li>\n</ul>') @skipUnless(is_lib_available('markdown'), 'Markdown is not available') def test_markdown_with_inline_html(self): entry.MARKUP_LANGUAGE = 'markdown' self.entry.content = ('Hello *World* !\n\n' '<p>This is an inline HTML paragraph</p>') html_content = self.entry.html_content self.assertEqual(html_content, '<p>Hello <em>World</em> !</p>\n' '<p>This is an inline HTML paragraph</p>') @skipUnless(is_lib_available('docutils'), 'Docutils is not available') def test_html_content_restructuredtext(self): entry.MARKUP_LANGUAGE = 'restructuredtext' self.entry.content = 'Hello world !\n\n' \ 'this is my content :\n\n' \ '* Item 1\n* Item 2' html_content = self.entry.html_content self.assertEqual(html_content, '<p>Hello world !</p>\n' '<p>this is my content :</p>' '\n<ul class="simple">\n<li>Item 1</li>\n' '<li>Item 2</li>\n</ul>\n') def test_html_preview(self): entry.MARKUP_LANGUAGE = None preview = self.entry.html_preview self.assertEqual(str(preview), '<p>My content</p>') self.assertEqual(preview.has_more, False) self.entry.lead = 'Lead paragraph' preview = self.entry.html_preview self.assertEqual(str(preview), '<p>Lead paragraph</p>') self.assertEqual(preview.has_more, True)
class EntryHtmlLeadTestCase(TestCase): def setUp(self): params = {'title': 'My entry', 'lead': 'My lead', 'slug': 'my-entry'} self.entry = Entry(**params) self.original_rendering = markups.MARKUP_LANGUAGE def tearDown(self): markups.MARKUP_LANGUAGE = self.original_rendering def test_html_lead_default(self): markups.MARKUP_LANGUAGE = None self.assertEqual(self.entry.html_lead, '<p>My lead</p>') self.entry.lead = 'Hello world !\n' \ ' this is my lead' self.assertEqual(self.entry.html_lead, '<p>Hello world !<br /> this is my lead</p>') self.entry.lead = '' self.assertEqual(self.entry.html_lead, '') @skipUnless(is_lib_available('textile'), 'Textile is not available') def test_html_lead_textitle(self): markups.MARKUP_LANGUAGE = 'textile' self.entry.lead = 'Hello world !\n\n' \ 'this is my lead :\n\n' \ '* Item 1\n* Item 2' html_lead = self.entry.html_lead self.assertEqual(html_lead, '\t<p>Hello world !</p>\n\n\t' '<p>this is my lead :</p>\n\n\t' '<ul>\n\t\t<li>Item 1</li>\n\t\t' '<li>Item 2</li>\n\t</ul>') @skipUnless(is_lib_available('markdown'), 'Markdown is not available') def test_html_lead_markdown(self): markups.MARKUP_LANGUAGE = 'markdown' self.entry.lead = 'Hello world !\n\n' \ 'this is my lead :\n\n' \ '* Item 1\n* Item 2' html_lead = self.entry.html_lead self.assertEqual(html_lead, '<p>Hello world !</p>\n' '<p>this is my lead :</p>' '\n<ul>\n<li>Item 1</li>\n' '<li>Item 2</li>\n</ul>') @skipUnless(is_lib_available('markdown'), 'Markdown is not available') def test_markdown_with_inline_html(self): markups.MARKUP_LANGUAGE = 'markdown' self.entry.lead = ('Hello *World* !\n\n' '<p>This is an inline HTML paragraph</p>') html_lead = self.entry.html_lead self.assertEqual(html_lead, '<p>Hello <em>World</em> !</p>\n' '<p>This is an inline HTML paragraph</p>') @skipUnless(is_lib_available('docutils'), 'Docutils is not available') def test_html_lead_restructuredtext(self): markups.MARKUP_LANGUAGE = 'restructuredtext' self.entry.lead = 'Hello world !\n\n' \ 'this is my lead :\n\n' \ '* Item 1\n* Item 2' html_lead = self.entry.html_lead self.assertEqual(html_lead, '<p>Hello world !</p>\n' '<p>this is my lead :</p>' '\n<ul class="simple">\n<li>Item 1</li>\n' '<li>Item 2</li>\n</ul>\n')