def test_raw_section_source(self): """The raw source for a document section can be requested""" client = LocalizingClient() client.login(username='******', password='******') d, r = doc_rev(""" <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """) expected = """ <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> """ response = client.get('%s?section=s2&raw=true' % reverse('wiki.document', args=[d.slug])) eq_(normalize_html(expected), normalize_html(response.content))
def test_raw_with_editing_links_source(self): """The raw source for a document can be requested, with section editing links""" client = LocalizingClient() client.login(username='******', password='******') d, r = doc_rev(""" <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """) expected = """ <h1 id="s1"><a class="edit-section" data-section-id="s1" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s1" href="/en-US/docs/%(slug)s$edit?section=s1&edit_links=true" title="Edit section">Edit</a>Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2"><a class="edit-section" data-section-id="s2" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s2" href="/en-US/docs/%(slug)s$edit?section=s2&edit_links=true" title="Edit section">Edit</a>Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3"><a class="edit-section" data-section-id="s3" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s3" href="/en-US/docs/%(slug)s$edit?section=s3&edit_links=true" title="Edit section">Edit</a>Head 3</h1> <p>test</p> <p>test</p> """ % {'slug': d.slug} response = client.get('%s?raw=true&edit_links=true' % reverse('wiki.document', args=[d.slug])) eq_(normalize_html(expected), normalize_html(response.content))
def test_ignore_heading_section_replace(self): doc_src = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ replace_src = """ <p>replacement worked yay hooray</p> """ expected = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>replacement worked yay hooray</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ result = (wiki.content .parse(doc_src) .replaceSection(id="s2", replace_src=replace_src, ignore_heading=True) .serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_keep_markup(self): content = """ <h2 id="Summary">Summary</h2> <p>The <strong>Document Object Model </strong> (<strong>DOM</strong>) is an API for <a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a> and <a href="/en-US/docs/XML" title="en-US/docs/XML">XML</a> documents. It provides a structural representation of the document, enabling you to modify its content and visual presentation by using a scripting language such as <a href="/en-US/docs/JavaScript" title="https://developer.mozilla.org/en-US/docs/JavaScript"> JavaScript</a>.</span></p> """ expected = """ The <strong>Document Object Model </strong> (<strong>DOM</strong>) is an API for <a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a> and <a href="/en-US/docs/XML" title="en-US/docs/XML">XML</a> documents. It provides a structural representation of the document, enabling you to modify its content and visual presentation by using a scripting language such as <a href="/en-US/docs/JavaScript" title="https://developer.mozilla.org/en-US/docs/JavaScript"> JavaScript</a>.</span> """ eq_(normalize_html(expected), normalize_html(get_seo_description(content, "en-US", False)))
def test_raw_with_editing_links_source(self): """The raw source for a document can be requested, with section editing links""" client = LocalizingClient() client.login(username='******', password='******') d, r = doc_rev(""" <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """) expected = """ <h1 id="s1"><a class="edit-section" data-section-id="s1" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s1" href="/en-US/docs/%(slug)s$edit?section=s1&edit_links=true" title="Edit section">Edit</a>Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2"><a class="edit-section" data-section-id="s2" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s2" href="/en-US/docs/%(slug)s$edit?section=s2&edit_links=true" title="Edit section">Edit</a>Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3"><a class="edit-section" data-section-id="s3" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s3" href="/en-US/docs/%(slug)s$edit?section=s3&edit_links=true" title="Edit section">Edit</a>Head 3</h1> <p>test</p> <p>test</p> """ % { 'slug': d.slug } response = client.get('%s?raw=true&edit_links=true' % reverse('wiki.document', args=[d.slug])) eq_(normalize_html(expected), normalize_html(response.content))
def test_code_syntax_conversion(self): doc_src = """ <h2>Some JavaScript</h2>: <pre class="deki-transform" function="syntax.JavaScript"> function foo(){ alert("bar"); } </pre> <pre>Some CSS:</pre> <pre class="dek-trans" function="syntax.CSS"> .dek-trans { color: red; } </pre> """ expected = """ <h2>Some JavaScript</h2>: <pre class="brush: js"> function foo(){ alert("bar"); } </pre> <pre>Some CSS:</pre> <pre class="brush: css"> .dek-trans { color: red; } </pre> """ result = ( wiki.content.parse(doc_src).filter(CodeSyntaxFilter).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_form_loaded_with_section(self): """RevisionForm given section_id should load initial content for only one section""" d, r = doc_rev( """ <h1 id="s1">s1</h1> <p>test</p> <p>test</p> <h1 id="s2">s2</h1> <p>test</p> <p>test</p> <h1 id="s3">s3</h1> <p>test</p> <p>test</p> """ ) expected = """ <h1 id="s2">s2</h1> <p>test</p> <p>test</p> """ rev_form = RevisionForm(instance=r, section_id="s2") eq_(normalize_html(expected), normalize_html(rev_form.initial["content"]))
def test_generate_toc(self): doc_src = """ <h1 id="HTML">HTML</h1> <h2 id="HTML5">HTML5</h2> <h1 id="JavaScript">JavaScript</h1> JavaScript is awesome. <h2 id="WebGL">WebGL</h2> <h2 id="Audio">Audio</h2> <h3 id="Audio-API">Audio API</h3> <h1 id="CSS">CSS</h1> """ expected = """ <li><a rel="internal" href="#HTML">HTML</a> <ol> <li><a rel="internal" href="#HTML5">HTML5</a></li> </ol> </li> <li><a rel="internal" href="#JavaScript">JavaScript</a> <ol> <li><a rel="internal" href="#WebGL">WebGL</a> <li><a rel="internal" href="#Audio">Audio</a> <ol> <li><a rel="internal" href="#Audio-API">Audio API</a></li> </ol> </li> </ol> </li> <li><a rel="internal" href="#CSS">CSS</a></li> """ result = ( wiki.content.parse(doc_src).filter(SectionTOCFilter).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_multilevel_implicit_section_extract(self): doc_src = """ <p>test</p> <h1 id="s4">Head 4</h1> <p>test</p> <p>test</p> <h2 id="s4-1">Head 4-1</h2> <p>test</p> <p>test</p> <h3 id="s4-2">Head 4-1-1</h3> <p>test</p> <p>test</p> <h1 id="s4-next">Head</h1> <p>test</p> """ expected = """ <h1 id="s4">Head 4</h1> <p>test</p> <p>test</p> <h2 id="s4-1">Head 4-1</h1> <p>test</p> <p>test</p> <h3 id="s4-2">Head 4-1-1</h1> <p>test</p> <p>test</p> """ result = wiki.content.parse(doc_src).extractSection(id="s4").serialize() eq_(normalize_html(expected), normalize_html(result))
def test_editor_safety_filter(self): """Markup that's hazardous for editing should be stripped""" doc_src = """ <svg><circle onload=confirm(3)> <h1 class="header1">Header One</h1> <p>test</p> <section> <h1 class="header2">Header Two</h1> <p>test</p> </section> <h1 class="header3">Header Three</h1> <p>test</p> """ expected_src = """ <svg><circle> <h1 class="header1">Header One</h1> <p>test</p> <section> <h1 class="header2">Header Two</h1> <p>test</p> </section> <h1 class="header3">Header Three</h1> <p>test</p> """ result_src = (wiki.content.parse(doc_src) .filterEditorSafety() .serialize()) eq_(normalize_html(expected_src), normalize_html(result_src))
def test_generate_toc(self): doc_src = """ <h1 id="HTML">HTML</h1> <h2 id="HTML5">HTML5</h2> <h1 id="JavaScript">JavaScript</h1> JavaScript is awesome. <h2 id="WebGL">WebGL</h2> <h2 id="Audio">Audio</h2> <h3 id="Audio-API">Audio API</h3> <h1 id="CSS">CSS</h1> """ expected = """ <li><a rel="internal" href="#HTML">HTML</a> <ol> <li><a rel="internal" href="#HTML5">HTML5</a></li> </ol> </li> <li><a rel="internal" href="#JavaScript">JavaScript</a> <ol> <li><a rel="internal" href="#WebGL">WebGL</a> <li><a rel="internal" href="#Audio">Audio</a> <ol> <li><a rel="internal" href="#Audio-API">Audio API</a></li> </ol> </li> </ol> </li> <li><a rel="internal" href="#CSS">CSS</a></li> """ result = (wiki.content .parse(doc_src) .filter(SectionTOCFilter).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_basic_section_replace(self): doc_src = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ replace_src = """ <h1 id="s2">Head 2</h1> <p>replacement worked</p> """ expected = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>replacement worked</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ result = (wiki.content.parse(doc_src).replaceSection( id="s2", replace_src=replace_src).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_section_edit_links(self): doc_src = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h2 id="s2">Head 2</h2> <p>test</p> <p>test</p> <h3 id="s3">Head 3</h3> <p>test</p> <p>test</p> """ expected = """ <h1 id="s1"><a class="edit-section" data-section-id="s1" data-section-src-url="/en-US/docs/some-slug?raw=true&section=s1" href="/en-US/docs/some-slug$edit?section=s1&edit_links=true" title="Edit section">Edit</a>Head 1</h1> <p>test</p> <p>test</p> <h2 id="s2"><a class="edit-section" data-section-id="s2" data-section-src-url="/en-US/docs/some-slug?raw=true&section=s2" href="/en-US/docs/some-slug$edit?section=s2&edit_links=true" title="Edit section">Edit</a>Head 2</h2> <p>test</p> <p>test</p> <h3 id="s3"><a class="edit-section" data-section-id="s3" data-section-src-url="/en-US/docs/some-slug?raw=true&section=s3" href="/en-US/docs/some-slug$edit?section=s3&edit_links=true" title="Edit section">Edit</a>Head 3</h3> <p>test</p> <p>test</p> """ result = (wiki.content.parse(doc_src).injectSectionEditingLinks( 'some-slug', 'en-US').serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_generate_toc_h2(self): doc_src = """ <h2 id="HTML">HTML</h2> <h3 id="HTML5_canvas_element">HTML5 <code>canvas</code> element</h3> <h2 id="JavaScript">JavaScript</h2> JavaScript is awesome. <h3 id="WebGL">WebGL</h3> <h3 id="Audio">Audio</h3> <h4 id="Audio-API">Audio API</h4> <h2 id="CSS">CSS</h2> <h4 id="CSS_transforms">CSS transforms</h4> <h3 id="Gradients">Gradients</h3> <h4 id="Scaling_backgrounds">Scaling backgrounds</h4> """ expected = """ <li><a rel="internal" href="#HTML">HTML</a> </li> <li><a rel="internal" href="#JavaScript">JavaScript</a> </li> <li><a rel="internal" href="#CSS">CSS</a> </li> """ result = (wiki.content .parse(doc_src) .filter(H2TOCFilter).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_keep_markup(self): content = """ <h2 id="Summary">Summary</h2> <p>The <strong>Document Object Model </strong> (<strong>DOM</strong>) is an API for <a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a> and <a href="/en-US/docs/XML" title="en-US/docs/XML">XML</a> documents. It provides a structural representation of the document, enabling you to modify its content and visual presentation by using a scripting language such as <a href="/en-US/docs/JavaScript" title="https://developer.mozilla.org/en-US/docs/JavaScript"> JavaScript</a>.</span></p> """ expected = """ The <strong>Document Object Model </strong> (<strong>DOM</strong>) is an API for <a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a> and <a href="/en-US/docs/XML" title="en-US/docs/XML">XML</a> documents. It provides a structural representation of the document, enabling you to modify its content and visual presentation by using a scripting language such as <a href="/en-US/docs/JavaScript" title="https://developer.mozilla.org/en-US/docs/JavaScript"> JavaScript</a>.</span> """ eq_(normalize_html(expected), normalize_html(get_seo_description(content, 'en-US', False)))
def test_form_save_section(self): d, r = doc_rev(""" <h1 id="s1">s1</h1> <p>test</p> <p>test</p> <h1 id="s2">s2</h1> <p>test</p> <p>test</p> <h1 id="s3">s3</h1> <p>test</p> <p>test</p> """) replace_content = """ <h1 id="s2">New stuff</h1> <p>new stuff</p> """ expected = """ <h1 id="s1">s1</h1> <p>test</p> <p>test</p> <h1 id="s2">New stuff</h1> <p>new stuff</p> <h1 id="s3">s3</h1> <p>test</p> <p>test</p> """ rev_form = RevisionForm({"content": replace_content}, instance=r, section_id="s2") new_rev = rev_form.save(r.creator, d) eq_(normalize_html(expected), normalize_html(new_rev.content))
def test_form_save_section(self): d, r = doc_rev( """ <h1 id="s1">s1</h1> <p>test</p> <p>test</p> <h1 id="s2">s2</h1> <p>test</p> <p>test</p> <h1 id="s3">s3</h1> <p>test</p> <p>test</p> """ ) replace_content = """ <h1 id="s2">New stuff</h1> <p>new stuff</p> """ expected = """ <h1 id="s1">s1</h1> <p>test</p> <p>test</p> <h1 id="s2">New stuff</h1> <p>new stuff</p> <h1 id="s3">s3</h1> <p>test</p> <p>test</p> """ rev_form = RevisionForm({"content": replace_content}, instance=r, section_id="s2") new_rev = rev_form.save(r.creator, d) eq_(normalize_html(expected), normalize_html(new_rev.content))
def test_basic_section_replace(self): doc_src = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ replace_src = """ <h1 id="s2">Head 2</h1> <p>replacement worked</p> """ expected = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>replacement worked</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ result = wiki.content.parse(doc_src).replaceSection(id="s2", replace_src=replace_src).serialize() eq_(normalize_html(expected), normalize_html(result))
def test_section_edit_links(self): doc_src = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h2 id="s2">Head 2</h2> <p>test</p> <p>test</p> <h3 id="s3">Head 3</h3> <p>test</p> <p>test</p> """ expected = """ <h1 id="s1"><a class="edit-section" data-section-id="s1" data-section-src-url="/en-US/docs/some-slug?raw=true&section=s1" href="/en-US/docs/some-slug$edit?section=s1&edit_links=true" title="Edit section">Edit</a>Head 1</h1> <p>test</p> <p>test</p> <h2 id="s2"><a class="edit-section" data-section-id="s2" data-section-src-url="/en-US/docs/some-slug?raw=true&section=s2" href="/en-US/docs/some-slug$edit?section=s2&edit_links=true" title="Edit section">Edit</a>Head 2</h2> <p>test</p> <p>test</p> <h3 id="s3"><a class="edit-section" data-section-id="s3" data-section-src-url="/en-US/docs/some-slug?raw=true&section=s3" href="/en-US/docs/some-slug$edit?section=s3&edit_links=true" title="Edit section">Edit</a>Head 3</h3> <p>test</p> <p>test</p> """ result = wiki.content.parse(doc_src).injectSectionEditingLinks("some-slug", "en-US").serialize() eq_(normalize_html(expected), normalize_html(result))
def test_code_syntax_conversion(self): doc_src = """ <h2>Some JavaScript</h2>: <pre class="deki-transform" function="syntax.JavaScript"> function foo(){ alert("bar"); } </pre> <pre>Some CSS:</pre> <pre class="dek-trans" function="syntax.CSS"> .dek-trans { color: red; } </pre> """ expected = """ <h2>Some JavaScript</h2>: <pre class="brush: js"> function foo(){ alert("bar"); } </pre> <pre>Some CSS:</pre> <pre class="brush: css"> .dek-trans { color: red; } </pre> """ result = wiki.content.parse(doc_src).filter(CodeSyntaxFilter).serialize() eq_(normalize_html(expected), normalize_html(result))
def test_multilevel_implicit_section_extract(self): doc_src = """ <p>test</p> <h1 id="s4">Head 4</h1> <p>test</p> <p>test</p> <h2 id="s4-1">Head 4-1</h2> <p>test</p> <p>test</p> <h3 id="s4-2">Head 4-1-1</h3> <p>test</p> <p>test</p> <h1 id="s4-next">Head</h1> <p>test</p> """ expected = """ <h1 id="s4">Head 4</h1> <p>test</p> <p>test</p> <h2 id="s4-1">Head 4-1</h1> <p>test</p> <p>test</p> <h3 id="s4-2">Head 4-1-1</h1> <p>test</p> <p>test</p> """ result = (wiki.content.parse(doc_src).extractSection( id="s4").serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_stripped_ie_comment(self): """bug 801046: strip IE conditional comments""" content = """ <p>Hi there.</p> <!--[if]><script>alert(1)</script --> <!--[if<img src=x onerror=alert(2)//]> --> <p>Goodbye</p> """ expected = """ <p>Hi there.</p> <p>Goodbye</p> """ result = Document.objects.clean_content(content) eq_(normalize_html(expected), normalize_html(result))
def test_section_extract(self): src = """ <h2>Foo</h2> <p>Bar</p> <h3 id="Quick_Links">Quick Links</h3> <p>Foo, yay</p> <h2>Baz</h2> <p>Baz</p> """ expected = """ <p>Foo, yay</p> """ result = section_extract(src, 'Quick_Links') eq_(normalize_html(expected), normalize_html(result))
def test_bug_925043(self): '''Bug 925043 - Redesign TOC has a bunch of empty <code> tags in markup''' doc_src = """ <h2 id="Print">Mastering <code>print</code></h2> <code>print 'Hello World!'</code> """ expected = """ <li> <a href="#Print" rel="internal">Mastering<code>print</code></a> </li> """ result = ( wiki.content.parse(doc_src).filter(SectionTOCFilter).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_iframe_host_contents_filter(self): """Any contents inside an <iframe> should be removed""" doc_src = """ <iframe> <iframe src="javascript:alert(1);"></iframe> </iframe> """ expected_src = """ <iframe> </iframe> """ result_src = (wiki.content.parse(doc_src).filterIframeHosts( '^https?\:\/\/sampleserver').serialize()) eq_(normalize_html(expected_src), normalize_html(result_src))
def test_bug_925043(self): '''Bug 925043 - Redesign TOC has a bunch of empty <code> tags in markup''' doc_src = """ <h2 id="Print">Mastering <code>print</code></h2> <code>print 'Hello World!'</code> """ expected = """ <li> <a href="#Print" rel="internal">Mastering<code>print</code></a> </li> """ result = (wiki.content .parse(doc_src) .filter(SectionTOCFilter).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_iframe_host_contents_filter(self): """Any contents inside an <iframe> should be removed""" doc_src = """ <iframe> <iframe src="javascript:alert(1);"></iframe> </iframe> """ expected_src = """ <iframe> </iframe> """ result_src = (wiki.content.parse(doc_src) .filterIframeHosts('^https?\:\/\/sampleserver') .serialize()) eq_(normalize_html(expected_src), normalize_html(result_src))
def test_raw_section_edit(self): client = LocalizingClient() client.login(username='******', password='******') d, r = doc_rev(""" <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """) replace = """ <h1 id="s2">Replace</h1> <p>replace</p> """ expected = """ <h1 id="s2">Replace</h1> <p>replace</p> """ response = client.post('%s?section=s2&raw=true' % reverse('wiki.edit_document', args=[d.slug]), {"form": "rev", "content": replace}, follow=True) eq_(normalize_html(expected), normalize_html(response.content)) expected = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Replace</h1> <p>replace</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ response = client.get('%s?raw=true' % reverse('wiki.document', args=[d.slug])) eq_(normalize_html(expected), normalize_html(response.content))
def test_raw_section_edit(self): client = LocalizingClient() client.login(username='******', password='******') d, r = doc_rev(""" <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """) replace = """ <h1 id="s2">Replace</h1> <p>replace</p> """ expected = """ <h1 id="s2">Replace</h1> <p>replace</p> """ response = client.post('%s?section=s2&raw=true' % reverse('wiki.edit_document', args=[d.slug]), { "form": "rev", "content": replace }, follow=True) eq_(normalize_html(expected), normalize_html(response.content)) expected = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Replace</h1> <p>replace</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ response = client.get('%s?raw=true' % reverse('wiki.document', args=[d.slug])) eq_(normalize_html(expected), normalize_html(response.content))
def test_morelevels_implicit_section_extract(self): doc_src = """ <h1 id="s7">Head 7</h1> <p>test</p> <p>test</p> <h1 id="s8">Head</h1> <p>test</p> <h2 id="s8-1">Head</h1> <p>test</p> <h3 id="s8-1-1">Head</h3> <p>test</p> <h2 id="s8-2">Head</h1> <p>test</p> <h3 id="s8-2-1">Head</h3> <p>test</p> <h4 id="s8-2-1-1">Head</h4> <p>test</p> <h2 id="s8-3">Head</h1> <p>test</p> <h1 id="s9">Head</h1> <p>test</p> <p>test</p> """ expected = """ <h1 id="s8">Head</h1> <p>test</p> <h2 id="s8-1">Head</h1> <p>test</p> <h3 id="s8-1-1">Head</h3> <p>test</p> <h2 id="s8-2">Head</h1> <p>test</p> <h3 id="s8-2-1">Head</h3> <p>test</p> <h4 id="s8-2-1-1">Head</h4> <p>test</p> <h2 id="s8-3">Head</h1> <p>test</p> """ result = (wiki.content .parse(doc_src) .extractSection(id="s8") .serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_simple_implicit_section_extract(self): doc_src = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> """ expected = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> """ result = wiki.content.parse(doc_src).extractSection(id="s1").serialize() eq_(normalize_html(expected), normalize_html(result))
def test_simple_implicit_section_extract(self): doc_src = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> """ expected = """ <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> """ result = (wiki.content.parse(doc_src).extractSection( id="s1").serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_dekiscript_macro_conversion(self): doc_src = u""" <span>Just a span</span> <span class="notascript">Hi there</span> <li><span class="script">Warning("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong>strongly</strong> discouraged!")</span></li> <li><span class="script">Note("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong class="important">strongly</strong> discouraged!")</span></li> <li><span class="script">MixedCaseName('parameter1', 'parameter2')</span></li> <li><span class="script">bug(689641)</span></li> <li><span class="script">template.lowercasename('border')</span></li> <li><span class="script">Template.UpperCaseTemplate("foo")</span></li> <li><span class="script">wiki.template('英語版章題', [ "Reusing tabs" ])</span></li> <li><span class="script">template("non-standard_inline", ["Reusing tabs", "YAY"])</span></li> <li><span class="script">wiki.template('英語版章題')</span></li> <li><span class="script">template("non-standard_inline")</span></li> """ expected = u""" <span>Just a span</span> <span class="notascript">Hi there</span> <li>{{ Warning("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong>strongly</strong> discouraged!") }}</li> <li>{{ Note("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong class="important">strongly</strong> discouraged!") }}</li> <li>{{ MixedCaseName('parameter1', 'parameter2') }}</li> <li>{{ bug("689641") }}</li> <li>{{ lowercasename('border') }}</li> <li>{{ UpperCaseTemplate("foo") }}</li> <li>{{ 英語版章題("Reusing tabs") }}</li> <li>{{ non-standard_inline("Reusing tabs", "YAY") }}</li> <li>{{ 英語版章題() }}</li> <li>{{ non-standard_inline() }}</li> """ # Check line-by-line, to help work out any issues failure-by-failure doc_src_lines = doc_src.split("\n") expected_lines = expected.split("\n") for i in range(0, len(doc_src_lines)): result = (wiki.content .parse(doc_src_lines[i]) .filter(DekiscriptMacroFilter).serialize()) eq_(normalize_html(expected_lines[i]), normalize_html(result)) # But, the whole thing should work in the filter, as well. result = (wiki.content .parse(doc_src) .filter(DekiscriptMacroFilter).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_explicit_section_extract(self): doc_src = """ <h1 id="s4-next">Head</h1> <p>test</p> <section id="parent-s5"> <h1 id="s5">Head 5</h1> <p>test</p> <p>test</p> <section> <h1>head subsection</h1> </section> <h2 id="s5-1">Head 5-1</h2> <p>test</p> <p>test</p> <h1 id="s5-next">Head 5 next</h1> <p>test</p> <p>test</p> </section> <h1 id="s7">Head 7</h1> <p>test</p> <p>test</p> """ expected = """ <h1 id="s5">Head 5</h1> <p>test</p> <p>test</p> <section> <h1>head subsection</h1> </section> <h2 id="s5-1">Head 5-1</h2> <p>test</p> <p>test</p> <h1 id="s5-next">Head 5 next</h1> <p>test</p> <p>test</p> """ result = (wiki.content .parse(doc_src) .extractSection(id="parent-s5") .serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_dekiscript_macro_conversion(self): doc_src = u""" <span>Just a span</span> <span class="notascript">Hi there</span> <li><span class="script">Warning("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong>strongly</strong> discouraged!")</span></li> <li><span class="script">Note("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong class="important">strongly</strong> discouraged!")</span></li> <li><span class="script">MixedCaseName('parameter1', 'parameter2')</span></li> <li><span class="script">template.lowercasename('border')</span></li> <li><span class="script">Template.UpperCaseTemplate("foo")</span></li> <li><span class="script">wiki.template('英語版章題', [ "Reusing tabs" ])</span></li> <li><span class="script">template("non-standard_inline", ["Reusing tabs", "YAY"])</span></li> <li><span class="script">wiki.template('英語版章題')</span></li> <li><span class="script">template("non-standard_inline")</span></li> """ expected = u""" <span>Just a span</span> <span class="notascript">Hi there</span> <li>{{ Warning("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong>strongly</strong> discouraged!") }}</li> <li>{{ Note("Performing synchronous IO on the main thread can cause serious performance problems. As a result, this method of modifying the database is <strong class="important">strongly</strong> discouraged!") }}</li> <li>{{ MixedCaseName('parameter1', 'parameter2') }}</li> <li>{{ lowercasename('border') }}</li> <li>{{ UpperCaseTemplate("foo") }}</li> <li>{{ 英語版章題("Reusing tabs") }}</li> <li>{{ non-standard_inline("Reusing tabs", "YAY") }}</li> <li>{{ 英語版章題() }}</li> <li>{{ non-standard_inline() }}</li> """ # Check line-by-line, to help work out any issues failure-by-failure doc_src_lines = doc_src.split("\n") expected_lines = expected.split("\n") for i in range(0, len(doc_src_lines)): result = (wiki.content .parse(doc_src_lines[i]) .filter(DekiscriptMacroFilter).serialize()) eq_(normalize_html(expected_lines[i]), normalize_html(result)) # But, the whole thing should work in the filter, as well. result = (wiki.content .parse(doc_src) .filter(DekiscriptMacroFilter).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_ignore_heading_section_extract(self): doc_src = """ <p>test</p> <h1 id="s4">Head 4</h1> <p>test</p> <h2 id="s4-1">Head 4-1</h2> <p>test</p> <h3 id="s4-2">Head 4-1-1</h3> <p>test s4-2</p> <h1 id="s4-next">Head</h1> <p>test</p> """ expected = """ <p>test</p> <h3 id="s4-2">Head 4-1-1</h3> <p>test s4-2</p> """ result = (wiki.content.parse(doc_src).extractSection( id="s4-1", ignore_heading=True).serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_noinclude(self): doc_src = u""" <div class="noinclude">{{ XULRefAttr() }}</div> <dl> <dt>{{ XULAttr("maxlength") }}</dt> <dd>Type: <em>integer</em></dd> <dd>Przykłady 例 예제 示例</dd> </dl> <div class="noinclude"> <p>{{ languages( { "ja": "ja/XUL/Attribute/maxlength" } ) }}</p> </div> """ expected = u""" <dl> <dt>{{ XULAttr("maxlength") }}</dt> <dd>Type: <em>integer</em></dd> <dd>Przykłady 例 예제 示例</dd> </dl> """ result = wiki.content.filter_out_noinclude(doc_src) eq_(normalize_html(expected), normalize_html(result))
def test_noinclude(self): doc_src = u""" <div class="noinclude">{{ XULRefAttr() }}</div> <dl> <dt>{{ XULAttr("maxlength") }}</dt> <dd>Type: <em>integer</em></dd> <dd>Przykłady 例 예제 示例</dd> </dl> <div class="noinclude"> <p>{{ languages( { "ja": "ja/XUL/Attribute/maxlength" } ) }}</p> </div> """ expected = u""" <dl> <dt>{{ XULAttr("maxlength") }}</dt> <dd>Type: <em>integer</em></dd> <dd>Przykłady 例 예제 示例</dd> </dl> """ result = (wiki.content.filter_out_noinclude(doc_src)) eq_(normalize_html(expected), normalize_html(result))
def test_ignore_heading_section_extract(self): doc_src = """ <p>test</p> <h1 id="s4">Head 4</h1> <p>test</p> <h2 id="s4-1">Head 4-1</h2> <p>test</p> <h3 id="s4-2">Head 4-1-1</h3> <p>test s4-2</p> <h1 id="s4-next">Head</h1> <p>test</p> """ expected = """ <p>test</p> <h3 id="s4-2">Head 4-1-1</h3> <p>test s4-2</p> """ result = (wiki.content .parse(doc_src) .extractSection(id="s4-1", ignore_heading=True) .serialize()) eq_(normalize_html(expected), normalize_html(result))
def test_zone_section_extract(self): root_result = zone_section_extract(self.root_doc, 'links') eq_(normalize_html(root_result), normalize_html(self.root_links_content)) sub_result = zone_section_extract(self.sub_doc, 'links') eq_(normalize_html(sub_result), normalize_html(self.root_links_content)) sub_sub_result = zone_section_extract(self.sub_sub_doc, 'links') eq_(normalize_html(sub_sub_result), normalize_html(self.sub_sub_links_content))
def test_form_loaded_with_section(self): """RevisionForm given section_id should load initial content for only one section""" d, r = doc_rev(""" <h1 id="s1">s1</h1> <p>test</p> <p>test</p> <h1 id="s2">s2</h1> <p>test</p> <p>test</p> <h1 id="s3">s3</h1> <p>test</p> <p>test</p> """) expected = """ <h1 id="s2">s2</h1> <p>test</p> <p>test</p> """ rev_form = RevisionForm(instance=r, section_id="s2") eq_(normalize_html(expected), normalize_html(rev_form.initial['content']))
def test_link_annotation(self): d, r = doc_rev("This document exists") d.save() r.save() d2 = document(title=u'Héritée', locale=u'fr', slug=u'CSS/Héritage', save=True) base_url = u'http://testserver/' vars = dict( base_url=base_url, exist_url=d.get_absolute_url(), exist_url_with_base=urljoin(base_url, d.get_absolute_url()), uilocale_url=u'/en-US/docs/%s/%s' % (d.locale, d.slug), noexist_url=u'/en-US/docs/no-such-doc', noexist_url_with_base=urljoin(base_url, u'/en-US/docs/no-such-doc'), noexist_uilocale_url=u'/en-US/docs/en-US/blah-blah-blah', nonen_slug='/fr/docs/CSS/H%c3%a9ritage', ) doc_src = u""" <li><a href="%(nonen_slug)s">Héritée</a></li> <li><a href="%(exist_url)s">This doc should exist</a></li> <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li> <li><a href="%(uilocale_url)s">This doc should exist</a></li> <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li> <li><a href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li> <li><a href="%(noexist_url)s">This doc should NOT exist</a></li> <li><a href="%(noexist_url_with_base)s">This doc should NOT exist</a></li> <li><a href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li> <li><a href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li> <li><a class="foobar" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li> <li><a href="http://mozilla.org/">This is an external link</a></li> <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li> <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li> """ % vars expected = u""" <li><a href="%(nonen_slug)s">Héritée</a></li> <li><a href="%(exist_url)s">This doc should exist</a></li> <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li> <li><a href="%(uilocale_url)s">This doc should exist</a></li> <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li> <li><a class="new" href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url)s">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url_with_base)s">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li> <li><a class="foobar new" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li> <li><a class="external" href="http://mozilla.org/">This is an external link</a></li> <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li> <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li> """ % vars # Split the markup into lines, to better see failures doc_lines = doc_src.strip().split("\n") expected_lines = expected.strip().split("\n") for idx in range(0, len(doc_lines)): doc_line = doc_lines[idx] expected_line = expected_lines[idx] result_line = (wiki.content.parse(doc_line).annotateLinks( base_url=vars['base_url']).serialize()) eq_(normalize_html(expected_line), normalize_html(result_line))
def test_midair_section_merge(self): """If a page was changed while someone was editing, but the changes didn't affect the specific section being edited, then ignore the midair warning""" client = LocalizingClient() client.login(username='******', password='******') doc, rev = doc_rev(""" <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """) replace_1 = """ <h1 id="s1">replace</h1> <p>replace</p> """ replace_2 = """ <h1 id="s2">replace</h1> <p>replace</p> """ expected = """ <h1 id="s1">replace</h1> <p>replace</p> <h1 id="s2">replace</h1> <p>replace</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ data = { 'form': 'rev', 'content': rev.content } # Edit #1 starts... resp = client.get('%s?section=s1' % reverse('wiki.edit_document', args=[doc.slug])) page = pq(resp.content) rev_id1 = page.find('input[name="current_rev"]').attr('value') # Edit #2 starts... resp = client.get('%s?section=s2' % reverse('wiki.edit_document', args=[doc.slug])) page = pq(resp.content) rev_id2 = page.find('input[name="current_rev"]').attr('value') # Edit #2 submits successfully data.update({ 'form': 'rev', 'content': replace_2, 'current_rev': rev_id2 }) resp = client.post('%s?section=s2&raw=true' % reverse('wiki.edit_document', args=[doc.slug]), data) eq_(302, resp.status_code) # Edit #1 submits, but since it's a different section, there's no # mid-air collision data.update({ 'form': 'rev', 'content': replace_1, 'current_rev': rev_id1 }) resp = client.post('%s?section=s1&raw=true' % reverse('wiki.edit_document', args=[doc.slug]), data) # No conflict, but we should get a 205 Reset as an indication that the # page needs a refresh. eq_(205, resp.status_code) # Finally, make sure that all the edits landed response = client.get('%s?raw=true' % reverse('wiki.document', args=[doc.slug])) eq_(normalize_html(expected), normalize_html(response.content)) # Also, ensure that the revision is slipped into the headers eq_(unicode(Document.uncached.get(slug=doc.slug).current_revision.id), unicode(response['x-kuma-revision']))
def test_link_annotation(self): d, r = doc_rev("This document exists") d.save() r.save() d2 = document(title=u"Héritée", locale=u"fr", slug=u"CSS/Héritage", save=True) base_url = u"http://testserver/" vars = dict( base_url=base_url, exist_url=d.get_absolute_url(), exist_url_with_base=urljoin(base_url, d.get_absolute_url()), uilocale_url=u"/en-US/docs/%s/%s" % (d.locale, d.slug), noexist_url=u"/en-US/docs/no-such-doc", noexist_url_with_base=urljoin(base_url, u"/en-US/docs/no-such-doc"), noexist_uilocale_url=u"/en-US/docs/en-US/blah-blah-blah", nonen_slug="/fr/docs/CSS/H%c3%a9ritage", tag_url="/en-US/docs/tag/foo", feed_url="/en-US/docs/feeds/atom/all", templates_url="/en-US/docs/templates", ) doc_src = ( u""" <li><a href="%(nonen_slug)s">Héritée</a></li> <li><a href="%(exist_url)s">This doc should exist</a></li> <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li> <li><a href="%(uilocale_url)s">This doc should exist</a></li> <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li> <li><a href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li> <li><a href="%(noexist_url)s">This doc should NOT exist</a></li> <li><a href="%(noexist_url_with_base)s">This doc should NOT exist</a></li> <li><a href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li> <li><a href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li> <li><a class="foobar" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li> <li><a href="http://mozilla.org/">This is an external link</a></li> <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li> <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li> <a href="%(tag_url)s">Tag link</a> <a href="%(feed_url)s">Feed link</a> <a href="%(templates_url)s">Templates link</a> """ % vars ) expected = ( u""" <li><a href="%(nonen_slug)s">Héritée</a></li> <li><a href="%(exist_url)s">This doc should exist</a></li> <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li> <li><a href="%(uilocale_url)s">This doc should exist</a></li> <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li> <li><a class="new" href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url)s">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url_with_base)s">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li> <li><a class="foobar new" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li> <li><a class="external" href="http://mozilla.org/">This is an external link</a></li> <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li> <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li> <a href="%(tag_url)s">Tag link</a> <a href="%(feed_url)s">Feed link</a> <a href="%(templates_url)s">Templates link</a> """ % vars ) # Split the markup into lines, to better see failures doc_lines = doc_src.strip().split("\n") expected_lines = expected.strip().split("\n") for idx in range(0, len(doc_lines)): doc_line = doc_lines[idx] expected_line = expected_lines[idx] result_line = wiki.content.parse(doc_line).annotateLinks(base_url=vars["base_url"]).serialize() eq_(normalize_html(expected_line), normalize_html(result_line))
def test_link_annotation(self): d, r = doc_rev("This document exists") d.save() r.save() document(title=u'Héritée', locale=u'fr', slug=u'CSS/Héritage', save=True) document(title=u'DOM/StyleSheet', locale=u'en-US', slug=u'DOM/StyleSheet', save=True) base_url = u'http://testserver/' vars = dict( base_url=base_url, exist_url=d.get_absolute_url(), exist_url_with_base=urljoin(base_url, d.get_absolute_url()), uilocale_url=u'/en-US/docs/%s/%s' % (d.locale, d.slug), noexist_url=u'/en-US/docs/no-such-doc', noexist_url_with_base=urljoin(base_url, u'/en-US/docs/no-such-doc'), noexist_uilocale_url=u'/en-US/docs/en-US/blah-blah-blah', nonen_slug='/fr/docs/CSS/H%c3%a9ritage', tag_url='/en-US/docs/tag/foo', feed_url='/en-US/docs/feeds/atom/all', templates_url='/en-US/docs/templates', ) doc_src = u""" <li><a href="%(nonen_slug)s">Héritée</a></li> <li><a href="%(exist_url)s">This doc should exist</a></li> <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li> <li><a href="%(uilocale_url)s">This doc should exist</a></li> <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li> <li><a href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li> <li><a href="%(noexist_url)s">This doc should NOT exist</a></li> <li><a href="%(noexist_url_with_base)s">This doc should NOT exist</a></li> <li><a href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li> <li><a href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li> <li><a class="foobar" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li> <li><a href="http://mozilla.org/">This is an external link</a></li> <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li> <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li> <a href="%(tag_url)s">Tag link</a> <a href="%(feed_url)s">Feed link</a> <a href="%(templates_url)s">Templates link</a> <a href="/en-US/docs/DOM/stylesheet">Case sensitive 1</a> <a href="/en-US/docs/DOM/Stylesheet">Case sensitive 1</a> <a href="/en-US/docs/DOM/StyleSheet">Case sensitive 1</a> <a href="/en-us/docs/dom/StyleSheet">Case sensitive 1</a> <a href="/en-US/docs/dom/Styles">For good measure</a> """ % vars expected = u""" <li><a href="%(nonen_slug)s">Héritée</a></li> <li><a href="%(exist_url)s">This doc should exist</a></li> <li><a href="%(exist_url)s#withanchor">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s">This doc should exist</a></li> <li><a href="%(exist_url_with_base)s#withanchor">This doc should exist</a></li> <li><a href="%(uilocale_url)s">This doc should exist</a></li> <li><a class="foobar" href="%(exist_url)s">This doc should exist, and its class should be left alone.</a></li> <li><a class="new" href="%(noexist_url)s#withanchor">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url)s">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url_with_base)s">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_url_with_base)s#withanchor">This doc should NOT exist</a></li> <li><a class="new" href="%(noexist_uilocale_url)s">This doc should NOT exist</a></li> <li><a class="foobar new" href="%(noexist_url)s">This doc should NOT exist, and its class should be altered</a></li> <li><a class="external" href="http://mozilla.org/">This is an external link</a></li> <li><a class="foobar" name="quux">A lack of href should not cause a problem.</a></li> <li><a>In fact, a "link" with no attributes should be no problem as well.</a></li> <a href="%(tag_url)s">Tag link</a> <a href="%(feed_url)s">Feed link</a> <a href="%(templates_url)s">Templates link</a> <a href="/en-US/docs/DOM/stylesheet">Case sensitive 1</a> <a href="/en-US/docs/DOM/Stylesheet">Case sensitive 1</a> <a href="/en-US/docs/DOM/StyleSheet">Case sensitive 1</a> <a href="/en-us/docs/dom/StyleSheet">Case sensitive 1</a> <a class="new" href="/en-US/docs/dom/Styles">For good measure</a> """ % vars # Split the markup into lines, to better see failures doc_lines = doc_src.strip().split("\n") expected_lines = expected.strip().split("\n") for idx in range(0, len(doc_lines)): doc_line = doc_lines[idx] expected_line = expected_lines[idx] result_line = (wiki.content.parse(doc_line) .annotateLinks(base_url=vars['base_url']) .serialize()) eq_(normalize_html(expected_line), normalize_html(result_line))
def test_midair_section_merge(self): """If a page was changed while someone was editing, but the changes didn't affect the specific section being edited, then ignore the midair warning""" client = LocalizingClient() client.login(username='******', password='******') doc, rev = doc_rev(""" <h1 id="s1">Head 1</h1> <p>test</p> <p>test</p> <h1 id="s2">Head 2</h1> <p>test</p> <p>test</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """) replace_1 = """ <h1 id="s1">replace</h1> <p>replace</p> """ replace_2 = """ <h1 id="s2">replace</h1> <p>replace</p> """ expected = """ <h1 id="s1">replace</h1> <p>replace</p> <h1 id="s2">replace</h1> <p>replace</p> <h1 id="s3">Head 3</h1> <p>test</p> <p>test</p> """ data = {'form': 'rev', 'content': rev.content} # Edit #1 starts... resp = client.get('%s?section=s1' % reverse('wiki.edit_document', args=[doc.slug])) page = pq(resp.content) rev_id1 = page.find('input[name="current_rev"]').attr('value') # Edit #2 starts... resp = client.get('%s?section=s2' % reverse('wiki.edit_document', args=[doc.slug])) page = pq(resp.content) rev_id2 = page.find('input[name="current_rev"]').attr('value') # Edit #2 submits successfully data.update({ 'form': 'rev', 'content': replace_2, 'current_rev': rev_id2 }) resp = client.post( '%s?section=s2&raw=true' % reverse('wiki.edit_document', args=[doc.slug]), data) eq_(302, resp.status_code) # Edit #1 submits, but since it's a different section, there's no # mid-air collision data.update({ 'form': 'rev', 'content': replace_1, 'current_rev': rev_id1 }) resp = client.post( '%s?section=s1&raw=true' % reverse('wiki.edit_document', args=[doc.slug]), data) # No conflict, but we should get a 205 Reset as an indication that the # page needs a refresh. eq_(205, resp.status_code) # Finally, make sure that all the edits landed response = client.get('%s?raw=true' % reverse('wiki.document', args=[doc.slug])) eq_(normalize_html(expected), normalize_html(response.content)) # Also, ensure that the revision is slipped into the headers eq_(unicode(Document.uncached.get(slug=doc.slug).current_revision.id), unicode(response['x-kuma-revision']))