1
0

test_pfmarkdown.py 1.9 KB

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