test_pfmarkdown.py 2.0 KB

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