Пример #1
0
    def test_markdown2html_does_bleach_unsafe_code(self):
        self.assertEqual(
            markdown2html("### hello <script>alert('gotcha');</script>"),
            "<h3>hello &lt;script&gt;alert('gotcha');&lt;/script&gt;</h3>",
        )

        self.assertEqual(
            markdown2html("<canvas><bgsound><audio><applet>"),
            "&lt;canvas&gt;&lt;bgsound&gt;&lt;audio&gt;&lt;applet&gt;",
        )

        self.assertEqual(
            markdown2html("""_hello_ <html><head></head>
<body></body></html>"""),
            """<p><em>hello</em> &lt;html&gt;&lt;head&gt;&lt;/head&gt;</p>
&lt;body&gt;&lt;/body&gt;\n<p>&lt;/html&gt;</p>""",
        )

        self.assertEqual(
            markdown2html("""__hello__ <xmp><video><track>
<title><rt><ruby><param>"""),
            """<p><strong>hello</strong> &lt;xmp&gt;&lt;video&gt;&lt;track&gt;<br>
&lt;title&gt;&lt;rt&gt;&lt;ruby&gt;&lt;param&gt;</p>""",
        )

        self.assertEqual(
            markdown2html("""*hello* <object><link><iframe>
<frame><frameset><embed>"""),
            """<p><em>hello</em> &lt;object&gt;&lt;link&gt;&lt;iframe&gt;<br>
&lt;frame&gt;&lt;frameset&gt;&lt;embed&gt;</p>""",
        )
Пример #2
0
    def test_markdown2html_convert_nl2br(self):
        self.assertEqual(
            markdown2html("""Line 1
Line 2"""),
            """<p>Line 1<br>
Line 2</p>""",
        )
Пример #3
0
    def test_markdown2html_convert_fenced_code(self):
        self.assertEqual(markdown2html("""```{
"firstName": "John",
"lastName": "Smith",
"age": 25}``` """), """<p><code>{
"firstName": "John",
"lastName": "Smith",
"age": 25}</code> </p>""")
Пример #4
0
    def test_markdown2html_with_codehilite(self):
        self.assertEqual(markdown2html("""```python
def hello():
    pass
```"""), """<div class="codehilite"><pre><span></span>\
<code><span class="k">def</span> <span class="nf">hello</span><span class="p">():</span>
    <span class="k">pass</span>
</code></pre></div>""")
Пример #5
0
    def test_reopen_a_closed_bug(self):
        bug = BugFactory(status=False)

        edit_bug_data = {"bug": bug.pk, "text": "Reopen the bug.", "action": "reopen"}

        redirect_url = reverse("bugs-get", args=[bug.pk])
        response = self.client.post(self.comment_bug_url, edit_bug_data, follow=True)

        self.assertContains(response, markdown2html(_("*bug reopened*")))
        self.assertContains(response, "Reopen the bug.")
        self.assertRedirects(response, redirect_url)
        bug.refresh_from_db()
        self.assertTrue(bug.status)
Пример #6
0
    def test_reopen_a_closed_bug(self):
        bug = BugFactory(status=False)

        edit_bug_data = {
            'bug': bug.pk,
            'text': 'Reopen the bug.',
            'action': 'reopen'
        }

        redirect_url = reverse('bugs-get', args=[bug.pk])
        response = self.client.post(self.comment_bug_url, edit_bug_data, follow=True)

        self.assertContains(response, markdown2html(_('*bug reopened*')))
        self.assertContains(response, 'Reopen the bug.')
        self.assertRedirects(response, redirect_url)
        bug.refresh_from_db()
        self.assertTrue(bug.status)
Пример #7
0
    def report_issue_from_testexecution(self, execution, user):
        """
        AzureBoards creates the Work Item with Title
        """

        create_body = [
            {
                "op": "add",
                "path": "/fields/System.Title",
                "from": "null",
                "value": f"Failed test: {execution.case.summary}",
            }
        ]

        update_body = [
            {
                "op": "replace",
                "path": "/fields/System.Description",
                "from": "null",
                "value": markdown2html(self._report_comment(execution)),
            }
        ]

        try:
            issue = self.rpc.create_issue(create_body)
            self.rpc.update_issue(issue["id"], update_body)

            issue_url = (
                self.bug_system.base_url + "/_workitems/edit/" + str(issue["id"])
            )
            # add a link reference that will be shown in the UI
            LinkReference.objects.get_or_create(
                execution=execution,
                url=issue_url,
                is_defect=True,
            )

            return issue_url
        except Exception:  # pylint: disable=broad-except
            # something above didn't work so return a link for manually
            # entering issue details with info pre-filled
            url = self.bug_system.base_url
            if not url.endswith("/"):
                url += "/"

            return url + "_workitems/create/Issue"
Пример #8
0
    def test_markdown2html_convert_tables(self):
        self.assertEqual(markdown2html("""|Stx |Desc |\n|----|-----|\n|Head|Title|\n|Txt|Txt |"""),
                         """<table>
<thead>
<tr>
<th>Stx</th>
<th>Desc</th>
</tr>
</thead>
<tbody>
<tr>
<td>Head</td>
<td>Title</td>
</tr>
<tr>
<td>Txt</td>
<td>Txt</td>
</tr>
</tbody>
</table>""")
Пример #9
0
def render(text):
    """
    .. function:: RPC Markdown.render(text)

        Returns the input string rendered into HTML with all the filters
        and extensions available in markdown2html().

        Note: when used via the front-end all of the HTML tags will be
        escaped eventhough they are safe to use! The FE client should
        unescape them in case this HTML is to be shown on the screen!

        :param text: Markdown text
        :type text: str
        :return: Rendered HTML text
        :rtype: str
    """
    result = cache.get(text)
    if result:
        return result

    result = markdown2html(text)
    cache.set(text, result)
    return result
Пример #10
0
 def post_comment(self):
     # NOTE: Posting comment is in preview state in API v6.0.
     comment_body = {
             "text": markdown2html(self.text())
         }
     self.rpc.add_comment(self.bug_id, comment_body)
Пример #11
0
 def test_markdown2html_convert_paragraphs(self):
     self.assertEqual(markdown2html("__*hello!*__"),
                      "<p><strong><em>hello!</em></strong></p>")