This looks sane, but I really would like to see some unit tests for this.
1 new commit added
So it's good to have this as part of the large functional test, but the function is a perfect candidate for unit testing.
It'd be great if there was a test class for the function that at least had a test for a public issue, a private issue, and a pull request.
Basically what I had in mind is something like
From e46e5326bcf7972d266d8b46e07d084377f5ec2f Mon Sep 17 00:00:00 2001 From: Jeremy Cline <jeremy@jcline.org> Date: Thu, 3 Nov 2016 14:26:52 -0400 Subject: [PATCH] Add unit tests for pfmarkdown's _obj_anchor_tag Signed-off-by: Jeremy Cline <jeremy@jcline.org> --- pagure/pfmarkdown.py | 7 +++++- tests/test_pfmarkdown.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/test_pfmarkdown.py diff --git a/pagure/pfmarkdown.py b/pagure/pfmarkdown.py index 694c1fc..f7824d3 100644 --- a/pagure/pfmarkdown.py +++ b/pagure/pfmarkdown.py @@ -267,7 +267,12 @@ def _pr_exists(user, namespace, repo, idx): def _obj_anchor_tag(user, namespace, repo, obj, text): - """ Utility method generating the link to an issue or a PR. """ + """ + Utility method generating the link to an issue or a PR. + + :return: An element tree containing the href to the issue or PR + :rtype: xml.etree.ElementTree.Element + """ if obj.isa == 'issue': url = flask.url_for( 'view_issue', username=user, namespace=namespace, repo=repo, diff --git a/tests/test_pfmarkdown.py b/tests/test_pfmarkdown.py new file mode 100644 index 0000000..de9329d --- /dev/null +++ b/tests/test_pfmarkdown.py @@ -0,0 +1,55 @@ +import unittest +from xml.etree import ElementTree + +from mock import patch, Mock + +from pagure import pfmarkdown +from pagure.lib import model + + +@patch('pagure.pfmarkdown.flask.url_for', Mock(return_value='http://eh/')) +class TestObjAnchorTag(unittest.TestCase): + """ + A set of tests for the pagure.pfmarkdown._obj_anchor_tag function + """ + + def test_obj_anchor_tag_issue(self): + """Assert links to issues are generated correctly""" + issue = model.Issue( + title='The issue summary', + content='The issue description', + ) + expected_markup = ('<a href="http://eh/" title="The issue summary">' + 'My Issue</a>') + element = pfmarkdown._obj_anchor_tag( + 'jcline', None, None, issue, 'My Issue') + + self.assertEqual(expected_markup, ElementTree.tostring(element)) + + def test_obj_anchor_tag_private_issue(self): + """Assert links to private issues hide the title""" + issue = model.Issue( + title='The private issue summary', + content='The issue description', + private=True + ) + expected_markup = ('<a href="http://eh/" title="Private issue">' + 'My Issue</a>') + element = pfmarkdown._obj_anchor_tag( + 'jcline', None, None, issue, 'My Issue') + + self.assertEqual(expected_markup, ElementTree.tostring(element)) + + def test_obj_anchor_tag_pr(self): + """Assert links to pull requests are generated correctly""" + pr = model.PullRequest(title='The pull request summary') + expected_markup = ('<a href="http://eh/" title="The pull request ' + 'summary">My Pull Request</a>') + element = pfmarkdown._obj_anchor_tag( + 'jcline', None, None, pr, 'My Pull Request') + + self.assertEqual(expected_markup, ElementTree.tostring(element)) + + +if __name__ == '__main__': + unittest.main() -- 2.9.3
Sorry for being so nitpicky.
:thumbsup:
Thanks :)
Pull-Request has been merged by pingou