Blame tests/test_pfmarkdown.py

Pierre-Yves Chibon 68a7d7
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 68a7d7
Pierre-Yves Chibon 68a7d7
"""
Pierre-Yves Chibon 68a7d7
 (c) 2016 - Copyright Red Hat Inc
Pierre-Yves Chibon 68a7d7
Pierre-Yves Chibon 68a7d7
 Authors:
Pierre-Yves Chibon 68a7d7
   Jeremy Cline <jeremy@jcline.org></jeremy@jcline.org>
Pierre-Yves Chibon 68a7d7
Pierre-Yves Chibon 68a7d7
"""
Aurélien Bompard dcf6f6
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
Jeremy Cline e1630c
import unittest
Jeremy Cline e1630c
from xml.etree import ElementTree
Jeremy Cline e1630c
Jeremy Cline e1630c
from mock import patch, Mock
Jeremy Cline e1630c
Jeremy Cline e1630c
from pagure import pfmarkdown
Jeremy Cline e1630c
from pagure.lib import model
Jeremy Cline e1630c
Jeremy Cline e1630c
Pierre-Yves Chibon 73d120
@patch("pagure.pfmarkdown.flask.url_for", Mock(return_value="http://eh/"))
Jeremy Cline e1630c
class TestObjAnchorTag(unittest.TestCase):
Jeremy Cline e1630c
    """
Jeremy Cline e1630c
    A set of tests for the pagure.pfmarkdown._obj_anchor_tag function
Jeremy Cline e1630c
    """
Jeremy Cline e1630c
Jeremy Cline e1630c
    def test_obj_anchor_tag_issue(self):
Jeremy Cline e1630c
        """Assert links to issues are generated correctly"""
Jeremy Cline e1630c
        issue = model.Issue(
Pierre-Yves Chibon 73d120
            title="The issue summary", content="The issue description"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        expected_markup = (
Pierre-Yves Chibon 73d120
            b'' b"My Issue"
Jeremy Cline e1630c
        )
Jeremy Cline e1630c
        element = pfmarkdown._obj_anchor_tag(
Pierre-Yves Chibon 73d120
            "jcline", None, None, issue, "My Issue"
Pierre-Yves Chibon 73d120
        )
Jeremy Cline e1630c
Jeremy Cline e1630c
        self.assertEqual(expected_markup, ElementTree.tostring(element))
Jeremy Cline e1630c
Jeremy Cline e1630c
    def test_obj_anchor_tag_private_issue(self):
Jeremy Cline e1630c
        """Assert links to private issues hide the title"""
Jeremy Cline e1630c
        issue = model.Issue(
Pierre-Yves Chibon 73d120
            title="The private issue summary",
Pierre-Yves Chibon 73d120
            content="The issue description",
Pierre-Yves Chibon 73d120
            private=True,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        expected_markup = (
Pierre-Yves Chibon 73d120
            b'' b"My Issue"
Jeremy Cline e1630c
        )
Jeremy Cline e1630c
        element = pfmarkdown._obj_anchor_tag(
Pierre-Yves Chibon 73d120
            "jcline", None, None, issue, "My Issue"
Pierre-Yves Chibon 73d120
        )
Jeremy Cline e1630c
Jeremy Cline e1630c
        self.assertEqual(expected_markup, ElementTree.tostring(element))
Jeremy Cline e1630c
Jeremy Cline e1630c
    def test_obj_anchor_tag_pr(self):
Jeremy Cline e1630c
        """Assert links to pull requests are generated correctly"""
Pierre-Yves Chibon 73d120
        pr = model.PullRequest(title="The pull request summary")
Pierre-Yves Chibon 73d120
        expected_markup = (
Pierre-Yves Chibon 73d120
            b'
Pierre-Yves Chibon 73d120
            b'summary">My Pull Request'
Pierre-Yves Chibon 73d120
        )
Jeremy Cline e1630c
        element = pfmarkdown._obj_anchor_tag(
Pierre-Yves Chibon 73d120
            "jcline", None, None, pr, "My Pull Request"
Pierre-Yves Chibon 73d120
        )
Jeremy Cline e1630c
Jeremy Cline e1630c
        self.assertEqual(expected_markup, ElementTree.tostring(element))
Jeremy Cline e1630c
Jeremy Cline e1630c
Pierre-Yves Chibon 73d120
if __name__ == "__main__":
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)