test_pfmarkdown.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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',
  22. content='The issue description',
  23. )
  24. expected_markup = (b'<a href="http://eh/" title="The issue summary">'
  25. b'My Issue</a>')
  26. element = pfmarkdown._obj_anchor_tag(
  27. 'jcline', None, None, issue, 'My Issue')
  28. self.assertEqual(expected_markup, ElementTree.tostring(element))
  29. def test_obj_anchor_tag_private_issue(self):
  30. """Assert links to private issues hide the title"""
  31. issue = model.Issue(
  32. title='The private issue summary',
  33. content='The issue description',
  34. private=True
  35. )
  36. expected_markup = (b'<a href="http://eh/" title="Private issue">'
  37. b'My Issue</a>')
  38. element = pfmarkdown._obj_anchor_tag(
  39. 'jcline', None, None, issue, 'My Issue')
  40. self.assertEqual(expected_markup, ElementTree.tostring(element))
  41. def test_obj_anchor_tag_pr(self):
  42. """Assert links to pull requests are generated correctly"""
  43. pr = model.PullRequest(title='The pull request summary')
  44. expected_markup = (b'<a href="http://eh/" title="The pull request '
  45. b'summary">My Pull Request</a>')
  46. element = pfmarkdown._obj_anchor_tag(
  47. 'jcline', None, None, pr, 'My Pull Request')
  48. self.assertEqual(expected_markup, ElementTree.tostring(element))
  49. if __name__ == '__main__':
  50. unittest.main(verbosity=2)