예제 #1
0
 def test_simple_inline_custom(self):
     """Simple custom inline syntax: menu, button, filepath, pref"""
     p = WikiParser()
     tags = ['menu', 'button', 'filepath', 'pref']
     for tag in tags:
         doc = pq(p.parse('{%s this is a %s}' % (tag, tag)))
         eq_('this is a ' + tag, doc('span.' + tag).text())
예제 #2
0
 def test_key_inline(self):
     """{key} stays inline"""
     p = WikiParser()
     doc = pq(p.parse('{key Cmd+Shift+Q}'))
     eq_(1, len(doc('p')))
     eq_(u'<span class="key">Cmd</span> + <span class="key">Shift</span>'
         u' + <span class="key">Q</span>', doc.html().replace('\n', ''))
예제 #3
0
 def test_key_inline(self):
     """{key} stays inline"""
     p = WikiParser()
     doc = pq(p.parse('{key Cmd+Shift+Q}'))
     eq_(1, len(doc('p')))
     eq_(u'<span class="key">Cmd</span> + <span class="key">Shift</span>'
         u' + <span class="key">Q</span>', doc.html().replace('\n', ''))
예제 #4
0
 def test_warning_multiline_breaks(self):
     """Multiline breaks warning syntax"""
     p = WikiParser()
     doc = pq(
         p.parse('\n\n{warning}\n\nthis is a warning\n\n'
                 '{/warning}\n\n'))
     eq_('this is a warning', doc('div.warning').text())
예제 #5
0
 def test_simple_inline_custom(self):
     """Simple custom inline syntax: menu, button, filepath, pref"""
     p = WikiParser()
     tags = ['menu', 'button', 'filepath', 'pref']
     for tag in tags:
         doc = pq(p.parse('{%s this is a %s}' % (tag, tag)))
         eq_('this is a ' + tag, doc('span.' + tag).text())
예제 #6
0
 def test_simple_inline_custom(self):
     """Simple custom inline syntax: menu, button, filepath, pref"""
     p = WikiParser()
     tags = ["menu", "button", "filepath", "pref"]
     for tag in tags:
         doc = pq(p.parse("{%s this is a %s}" % (tag, tag)))
         eq_("this is a " + tag, doc("span." + tag).text())
예제 #7
0
    def test_internal_links(self):
        """Make sure internal links work correctly when not to redirected
        articles and when to redirected articles"""
        p = WikiParser()

        # Create a new article
        rev = ApprovedRevisionFactory()
        doc = rev.document
        doc.current_revision = rev
        doc.title = "Real article"
        doc.save()

        # Change the slug of the article to create a redirected article
        old_slug = doc.slug
        doc.slug = "real-article"
        doc.save()
        redirect = Document.objects.get(slug=old_slug)

        # Both internal links should link to the same article
        eq_(
            p.parse("[[%s]]" % doc.title),
            '<p><a href="/en-US/kb/%s">%s</a>\n</p>' % (doc.slug, doc.title),
        )
        eq_(
            p.parse("[[%s]]" % redirect.title),
            '<p><a href="/en-US/kb/%s">%s</a>\n</p>' % (doc.slug, doc.title),
        )
예제 #8
0
 def test_button_for_nesting(self):
     """You can nest {for}s inside {button}."""
     text = '{button start {for mac}mac{/for}{for win}win{/for} rest}'
     p = WikiParser()
     content = p.parse(text)
     eq_(u'<p><span class="button">start '
         u'<span class="for" data-for="mac">mac</span>'
         u'<span class="for" data-for="win">win</span> '
         u'rest</span>\n</p>', content)
예제 #9
0
 def test_button_image_for_nesting(self):
     """You can nest [[Image:]] inside {for} inside {button}."""
     image(title='image-file.png')
     text = '{button {for mac}[[Image:image-file.png]]{/for} text}'
     p = WikiParser()
     doc = pq(p.parse(text))
     assert 'frameless' in doc('img').attr('class')
     eq_(0, doc('div.caption').length)
     eq_(0, doc('div.img').length)
예제 #10
0
 def test_button_for_nesting(self):
     """You can nest {for}s inside {button}."""
     text = '{button start {for mac}mac{/for}{for win}win{/for} rest}'
     p = WikiParser()
     content = p.parse(text)
     eq_(u'<p><span class="button">start '
         u'<span class="for" data-for="mac">mac</span>'
         u'<span class="for" data-for="win">win</span> '
         u'rest</span>\n</p>', content)
예제 #11
0
 def test_button_image_for_nesting(self):
     """You can nest [[Image:]] inside {for} inside {button}."""
     image(title='image-file.png')
     text = '{button {for mac}[[Image:image-file.png]]{/for} text}'
     p = WikiParser()
     doc = pq(p.parse(text))
     assert 'frameless' in doc('img').attr('class')
     eq_(0, doc('div.caption').length)
     eq_(0, doc('div.img').length)
예제 #12
0
 def test_button_image_for_nesting(self):
     """You can nest [[Image:]] inside {for} inside {button}."""
     ImageFactory(title="image-file.png")
     text = "{button {for mac}[[Image:image-file.png]]{/for} text}"
     p = WikiParser()
     doc = pq(p.parse(text))
     assert "frameless" in doc("img").attr("class")
     eq_(0, doc("div.caption").length)
     eq_(0, doc("div.img").length)
예제 #13
0
 def test_for_in_template(self):
     """Verify that {for}'s render correctly in template."""
     d = TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + 'for')
     ApprovedRevisionFactory(document=d, content='{for win}windows{/for}{for mac}mac{/for}')
     p = WikiParser()
     content = p.parse('[[{}for]]'.format(TEMPLATE_TITLE_PREFIX))
     eq_('<p><span class="for" data-for="win">windows</span>'
         '<span class="for" data-for="mac">mac</span>\n\n</p>',
         content)
예제 #14
0
 def test_key_inline(self):
     """{key} stays inline"""
     p = WikiParser()
     doc = pq(p.parse("{key Cmd+Shift+Q}"))
     eq_(1, len(doc("p")))
     eq_(
         '<span class="key">Cmd</span> + <span class="key">Shift</span>'
         ' + <span class="key">Q</span>',
         doc.html().replace("\n", ""),
     )
예제 #15
0
 def test_for_in_template(self):
     """Verify that {for}'s render correctly in template."""
     d = TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + 'for')
     ApprovedRevisionFactory(
         document=d, content='{for win}windows{/for}{for mac}mac{/for}')
     p = WikiParser()
     content = p.parse('[[{}for]]'.format(TEMPLATE_TITLE_PREFIX))
     eq_(
         '<p><span class="for" data-for="win">windows</span>'
         '<span class="for" data-for="mac">mac</span>\n\n</p>', content)
예제 #16
0
 def test_video_fallback_french(self):
     """English video is found in French."""
     p = WikiParser()
     self.test_video_english()
     doc = pq(p.parse('[[V:Some title]]', locale='fr'))
     eq_('video', doc('div.video').attr('class'))
     eq_(1, len(doc('video')))
     eq_(2, len(doc('source')))
     data_fallback = doc('video').attr('data-fallback')
     eq_(Video.objects.all()[0].flv.url, data_fallback)
예제 #17
0
 def test_video_fallback_french(self):
     """English video is found in French."""
     p = WikiParser()
     self.test_video_english()
     doc = pq(p.parse('[[V:Some title]]', locale='fr'))
     eq_('video', doc('div.video').attr('class'))
     eq_(1, len(doc('video')))
     eq_(2, len(doc('source')))
     data_fallback = doc('video').attr('data-fallback')
     eq_(Video.objects.all()[0].flv.url, data_fallback)
예제 #18
0
    def test_comments(self):
        """Markup containing taggy comments shouldn't truncate afterward."""
        p = WikiParser()

        # This used to truncate after the comment when rendered:
        eq_(p.parse("Start <!-- <foo --> End"), "<p>Start  End\n</p>")

        # Just make sure these don't go awry either:
        eq_(p.parse("Start <!-- <foo> --> End"), "<p>Start  End\n</p>")
        eq_(p.parse("Start <!-- foo> --> End"), "<p>Start  End\n</p>")
예제 #19
0
 def test_video_fallback_french(self):
     """English video is found in French."""
     p = WikiParser()
     v = VideoFactory()
     doc = pq(p.parse("[[V:%s]]" % v.title, locale="fr"))
     eq_("video", doc("div.video").attr("class"))
     eq_(1, len(doc("video")))
     eq_(2, len(doc("source")))
     data_fallback = doc("video").attr("data-fallback")
     eq_(Video.objects.all()[0].flv.url, data_fallback)
예제 #20
0
 def test_adjacent_blocks(self):
     """Make sure one block-level {for} doesn't absorb an adjacent one."""
     p = WikiParser()
     html = p.parse('{for fx4}\n'
                    '{for mac}Fx4{/for}\n'
                    '{/for}\n'
                    '{for fx3}\n'
                    '{for mac}Fx3{/for}\n'
                    '{/for}')
     # The two div.fors should be siblings, not nested:
     eq_([], pq(html)('div.for div.for'))
예제 #21
0
 def test_adjacent_blocks(self):
     """Make sure one block-level {for} doesn't absorb an adjacent one."""
     p = WikiParser()
     html = p.parse('{for fx4}\n'
                    '{for mac}Fx4{/for}\n'
                    '{/for}\n'
                    '{for fx3}\n'
                    '{for mac}Fx3{/for}\n'
                    '{/for}')
     # The two div.fors should be siblings, not nested:
     eq_([], pq(html)('div.for div.for'))
예제 #22
0
 def test_general_warning_note_inline_custom(self):
     """A mix of custom inline syntax with warnings and notes"""
     p = WikiParser()
     doc = pq(p.parse('\n\n{warning}\n\nthis is a {button warning}\n{note}'
                      'this is a {menu note}{warning}!{/warning}{/note}'
                      "'''{filepath internal}''' ''{menu hi!}''{/warning}"))
     eq_('warning', doc('div.warning span.button').text())
     eq_('this is a note !', doc('div.note').text())
     eq_('note', doc('div.warning div.note span.menu').text())
     eq_('internal', doc('strong span.filepath').text())
     eq_('hi!', doc('em span.menu').text())
예제 #23
0
 def test_general_warning_note_inline_custom(self):
     """A mix of custom inline syntax with warnings and notes"""
     p = WikiParser()
     doc = pq(p.parse('\n\n{warning}\n\nthis is a {button warning}\n{note}'
                      'this is a {menu note}{warning}!{/warning}{/note}'
                      "'''{filepath internal}''' ''{menu hi!}''{/warning}"))
     eq_('warning', doc('div.warning span.button').text())
     eq_('this is a note !', doc('div.note').text())
     eq_('note', doc('div.warning div.note span.menu').text())
     eq_('internal', doc('strong span.filepath').text())
     eq_('hi!', doc('em span.menu').text())
예제 #24
0
 def test_general_warning_note(self):
     """A bunch of wiki text with {warning} and {note}"""
     p = WikiParser()
     doc = pq(p.parse('\n\n{warning}\n\nthis is a warning\n\n{note}'
                      'this is a note{warning}!{/warning}{/note}'
                      "[[Installing Firefox]] '''internal''' ''link''"
                      '{/warning}\n\n'))
     eq_('!', doc('div.warning div.warning').text())
     eq_('this is a note !', doc('div.note').text())
     eq_('Installing Firefox', doc('a').text())
     eq_('internal', doc('strong').text())
     eq_('link', doc('em').text())
예제 #25
0
    def test_youtube_video(self):
        """Verify youtube embeds."""
        urls = ['http://www.youtube.com/watch?v=oHg5SJYRHA0',
                'https://youtube.com/watch?v=oHg5SJYRHA0'
                'http://youtu.be/oHg5SJYRHA0'
                'https://youtu.be/oHg5SJYRHA0']
        parser = WikiParser()

        for url in urls:
            doc = pq(parser.parse('[[V:%s]]' % url))
            assert doc('iframe')[0].attrib['src'].startswith(
                '//www.youtube.com/embed/oHg5SJYRHA0')
예제 #26
0
    def test_revision_include(self):
        """Simple include markup."""
        p = WikiParser()
        _, _, p = doc_rev_parser('Test content', 'Test title')

        # Existing title returns document's content
        doc = pq(p.parse('[[I: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())
예제 #27
0
 def test_general_warning_note_inline_custom(self):
     """A mix of custom inline syntax with warnings and notes"""
     p = WikiParser()
     doc = pq(
         p.parse("\n\n{warning}\n\nthis is a {button warning}\n{note}"
                 "this is a {menu note}{warning}!{/warning}{/note}"
                 "'''{filepath internal}''' ''{menu hi!}''{/warning}"))
     eq_("warning", doc("div.warning span.button").text())
     eq_("this is a note !", doc("div.note").text())
     eq_("note", doc("div.warning div.note span.menu").text())
     eq_("internal", doc("strong span.filepath").text())
     eq_("hi!", doc("em span.menu").text())
예제 #28
0
    def test_revision_include(self):
        """Simple include markup."""
        p = WikiParser()
        _, _, p = doc_rev_parser("Test content", "Test title")

        # Existing title returns document's content
        doc = pq(p.parse("[[I: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())
예제 #29
0
 def test_general_warning_note(self):
     """A bunch of wiki text with {warning} and {note}"""
     p = WikiParser()
     doc = pq(p.parse('\n\n{warning}\n\nthis is a warning\n\n{note}'
                      'this is a note{warning}!{/warning}{/note}'
                      "[[Installing Firefox]] '''internal''' ''link''"
                      '{/warning}\n\n'))
     eq_('!', doc('div.warning div.warning').text())
     eq_('this is a note !', doc('div.note').text())
     eq_('Installing Firefox', doc('a').text())
     eq_('internal', doc('strong').text())
     eq_('link', doc('em').text())
예제 #30
0
    def test_youtube_video(self):
        """Verify youtube embeds."""
        urls = ['http://www.youtube.com/watch?v=oHg5SJYRHA0',
                'https://youtube.com/watch?v=oHg5SJYRHA0'
                'http://youtu.be/oHg5SJYRHA0'
                'https://youtu.be/oHg5SJYRHA0']
        parser = WikiParser()

        for url in urls:
            doc = pq(parser.parse('[[V:%s]]' % url))
            assert doc('iframe')[0].attrib['src'].startswith(
                '//www.youtube.com/embed/oHg5SJYRHA0')
예제 #31
0
    def test_comments(self):
        """Markup containing taggy comments shouldn't truncate afterward."""
        p = WikiParser()

        # This used to truncate after the comment when rendered:
        eq_(p.parse('Start <!-- <foo --> End'),
            '<p>Start  End\n</p>')

        # Just make sure these don't go awry either:
        eq_(p.parse('Start <!-- <foo> --> End'),
            '<p>Start  End\n</p>')
        eq_(p.parse('Start <!-- foo> --> End'),
            '<p>Start  End\n</p>')
예제 #32
0
 def test_for_in_template(self):
     """Verify that {for}'s render correctly in template."""
     d = document(title='Template:for')
     d.save()
     r = revision(document=d,
                  content='{for win}windows{/for}{for mac}mac{/for}')
     r.is_approved = True
     r.save()
     p = WikiParser()
     content = p.parse('[[Template:for]]')
     eq_('<p><span class="for" data-for="win">windows</span>'
         '<span class="for" data-for="mac">mac</span>\n\n</p>',
         content)
예제 #33
0
 def test_for_in_template(self):
     """Verify that {for}'s render correctly in template."""
     d = document(title='Template:for')
     d.save()
     r = revision(document=d,
                  content='{for win}windows{/for}{for mac}mac{/for}')
     r.is_approved = True
     r.save()
     p = WikiParser()
     content = p.parse('[[Template:for]]')
     eq_(
         '<p><span class="for" data-for="win">windows</span>'
         '<span class="for" data-for="mac">mac</span>\n\n</p>', content)
예제 #34
0
    def test_youtube_video(self):
        """Verify youtube embeds."""
        urls = [
            "http://www.youtube.com/watch?v=oHg5SJYRHA0",
            "https://youtube.com/watch?v=oHg5SJYRHA0"
            "http://youtu.be/oHg5SJYRHA0"
            "https://youtu.be/oHg5SJYRHA0",
        ]
        parser = WikiParser()

        for url in urls:
            doc = pq(parser.parse("[[V:%s]]" % url))
            assert doc("iframe")[0].attrib["src"].startswith("//www.youtube.com/embed/oHg5SJYRHA0")
예제 #35
0
 def test_general_warning_note(self):
     """A bunch of wiki text with {warning} and {note}"""
     p = WikiParser()
     doc = pq(
         p.parse("\n\n{warning}\n\nthis is a warning\n\n{note}"
                 "this is a note{warning}!{/warning}{/note}"
                 "[[Installing Firefox]] '''internal''' ''link''"
                 "{/warning}\n\n"))
     eq_("!", doc("div.warning div.warning").text())
     eq_("this is a note !", doc("div.note").text())
     eq_("Installing Firefox", doc("a").text())
     eq_("internal", doc("strong").text())
     eq_("link", doc("em").text())
예제 #36
0
    def test_internal_links(self):
        """Make sure internal links work correctly when not to redirected
           articles and when to redirected articles"""
        p = WikiParser()

        # Create a new article
        rev = revision(is_approved=True, save=True)
        doc = rev.document
        doc.current_revision = rev
        doc.title = 'Real article'
        doc.save()

        # Change the slug of the article to create a redirected article
        old_slug = doc.slug
        doc.slug = 'real-article'
        doc.save()
        redirect = Document.objects.get(slug=old_slug)

        # Both internal links should link to the same article
        eq_(p.parse('[[%s]]' % doc.title),
            '<p><a href="/en-US/kb/%s">%s</a>\n</p>' % (doc.slug, doc.title))
        eq_(p.parse('[[%s]]' % redirect.title),
            '<p><a href="/en-US/kb/%s">%s</a>\n</p>' % (doc.slug, doc.title))
예제 #37
0
 def test_unapproved_template(self):
     TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + 'new')
     p = WikiParser()
     doc = pq(p.parse('[[T:new]]'))
     eq_('The template "new" does not exist or has no approved revision.',
         doc.text())
예제 #38
0
 def test_note_simple(self):
     """Simple note syntax"""
     p = WikiParser()
     doc = pq(p.parse("{note}this is a note{/note}"))
     eq_("this is a note", doc("div.note").text())
예제 #39
0
def parsed_eq(want, to_parse):
    p = WikiParser()
    eq_(want, p.parse(to_parse).strip().replace('\n', ''))
예제 #40
0
 def test_block_level_section(self):
     """Make sure we recognize <section> as a block element."""
     p = WikiParser()
     html = p.parse("{for}<section>hi</section>{/for}")
     assert "<div" in html, "Didn't detect <section> tag as block level"
예제 #41
0
 def test_warning_multiline_breaks(self):
     """Multiline breaks warning syntax"""
     p = WikiParser()
     doc = pq(p.parse("\n\n{warning}\n\nthis is a warning\n\n{/warning}\n\n"))
     eq_("this is a warning", doc("div.warning").text())
예제 #42
0
 def test_warning_multiline(self):
     """Multiline warning syntax"""
     p = WikiParser()
     doc = pq(p.parse('{warning}\nthis is a warning\n{/warning}'))
     eq_('this is a warning', doc('div.warning').text())
예제 #43
0
 def test_video_not_exist(self):
     """Video does not exist."""
     p = WikiParser()
     doc = pq(p.parse('[[V:Some title]]', locale='fr'))
     eq_('The video "Some title" does not exist.', doc.text())
예제 #44
0
 def test_unapproved_template(self):
     document(title='Template:new').save()
     p = WikiParser()
     doc = pq(p.parse('[[T:new]]'))
     eq_('The template "new" does not exist or has no approved revision.',
         doc.text())
예제 #45
0
 def test_warning_multiline_breaks(self):
     """Multiline breaks warning syntax"""
     p = WikiParser()
     doc = pq(p.parse('\n\n{warning}\n\nthis is a warning\n\n'
                      '{/warning}\n\n'))
     eq_('this is a warning', doc('div.warning').text())
예제 #46
0
 def test_template_not_exist(self):
     """If template does not exist in set locale or English."""
     p = WikiParser()
     doc = pq(p.parse('[[T:test]]', locale='fr'))
     eq_('The template "test" does not exist or has no approved revision.',
         doc.text())
예제 #47
0
 def test_video_not_exist(self):
     """Video does not exist."""
     p = WikiParser()
     doc = pq(p.parse("[[V:404]]", locale="fr"))
     eq_('The video "404" does not exist.', doc.text())
예제 #48
0
 def test_warning_simple(self):
     """Simple warning syntax"""
     p = WikiParser()
     doc = pq(p.parse("{warning}this is a warning{/warning}"))
     eq_("this is a warning", doc("div.warning").text())
예제 #49
0
 def test_warning_simple(self):
     """Simple warning syntax"""
     p = WikiParser()
     doc = pq(p.parse('{warning}this is a warning{/warning}'))
     eq_('this is a warning', doc('div.warning').text())
예제 #50
0
 def assertWikiHtmlEqual(self, wiki, html, msg=None):
     self.assertHTMLEqual(WikiParser().parse(wiki), html, msg=msg)
예제 #51
0
 def test_unapproved_template(self):
     TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + "new")
     p = WikiParser()
     doc = pq(p.parse("[[T:new]]"))
     eq_('The template "new" does not exist or has no approved revision.', doc.text())
예제 #52
0
 def test_leading_newlines(self):
     """Make sure leading newlines don't cause a block-level {for} to be
     sucked into the leading blank paragraph, causing the actual text to
     always be shown."""
     doc = pq(WikiParser().parse("\n\n{for linux}\nunixify\n{/for}"))
     eq_("unixify", doc(".for").text().strip())
예제 #53
0
 def test_note_simple(self):
     """Simple note syntax"""
     p = WikiParser()
     doc = pq(p.parse('{note}this is a note{/note}'))
     eq_('this is a note', doc('div.note').text())
예제 #54
0
 def test_template_does_not_exist(self):
     """Return a message if template does not exist"""
     p = WikiParser()
     doc = pq(p.parse('[[Template:test]]'))
     eq_('The template "test" does not exist or has no approved revision.',
         doc.text())
예제 #55
0
 def test_block_level_section(self):
     """Make sure we recognize <section> as a block element."""
     p = WikiParser()
     html = p.parse('{for}<section>hi</section>{/for}')
     assert '<div' in html, "Didn't detect <section> tag as block level"