1
0

test_pfmarkdown.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2016 - Copyright Red Hat Inc
  4. Authors:
  5. Jeremy Cline <jeremy@jcline.org>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import unittest
  9. from xml.etree import ElementTree
  10. from mock import patch, Mock
  11. from pagure import pfmarkdown
  12. from pagure.lib import model
  13. @patch("pagure.pfmarkdown.flask.url_for", Mock(return_value="http://eh/"))
  14. class TestObjAnchorTag(unittest.TestCase):
  15. """
  16. A set of tests for the pagure.pfmarkdown._obj_anchor_tag function
  17. """
  18. def test_obj_anchor_tag_issue(self):
  19. """Assert links to issues are generated correctly"""
  20. issue = model.Issue(
  21. title="The issue summary", content="The issue description"
  22. )
  23. expected_markup = (
  24. b'<a href="http://eh/" title="The issue summary">' b"My Issue</a>"
  25. )
  26. element = pfmarkdown._obj_anchor_tag(
  27. "jcline", None, None, issue, "My Issue"
  28. )
  29. self.assertEqual(expected_markup, ElementTree.tostring(element))
  30. def test_obj_anchor_tag_private_issue(self):
  31. """Assert links to private issues hide the title"""
  32. issue = model.Issue(
  33. title="The private issue summary",
  34. content="The issue description",
  35. private=True,
  36. )
  37. expected_markup = (
  38. b'<a href="http://eh/" title="Private issue">' b"My Issue</a>"
  39. )
  40. element = pfmarkdown._obj_anchor_tag(
  41. "jcline", None, None, issue, "My Issue"
  42. )
  43. self.assertEqual(expected_markup, ElementTree.tostring(element))
  44. def test_obj_anchor_tag_pr(self):
  45. """Assert links to pull requests are generated correctly"""
  46. pr = model.PullRequest(title="The pull request summary")
  47. expected_markup = (
  48. b'<a href="http://eh/" title="The pull request '
  49. b'summary">My Pull Request</a>'
  50. )
  51. element = pfmarkdown._obj_anchor_tag(
  52. "jcline", None, None, pr, "My Pull Request"
  53. )
  54. self.assertEqual(expected_markup, ElementTree.tostring(element))
  55. if __name__ == "__main__":
  56. unittest.main(verbosity=2)