# HG changeset patch # User Thomas De Schampheleire # Date 1518563579 -3600 # Node ID b43e77fa50ddd1c3357a68974fa988c45f8828c3 # Parent e87b0804be890c76dd2623a47d4f0403b9785d72 tests: add basic tests for urlify_issues Add some tests to cover the existing behavior of urlify_issues. diff -r e87b0804be89 -r b43e77fa50dd kallithea/tests/other/test_libs.py --- a/kallithea/tests/other/test_libs.py Sun Oct 29 21:30:23 2017 +0100 +++ b/kallithea/tests/other/test_libs.py Wed Feb 14 00:12:59 2018 +0100 @@ -403,6 +403,66 @@ from kallithea.lib.helpers import urlify_text assert urlify_text(sample, 'repo_name', link_='#the-link') == expected + @parametrize('issue_pat,issue_server,issue_prefix,sample,expected', [ + (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', + 'issue #123', 'issue #123'), + (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', + 'issue#456', 'issue#456'), + (r'#(\d+)', 'http://foo/{repo}/issue/{id}', 'PR', + 'interesting issue #123', 'interesting issue PR123'), + (r'BUG\d{5}', 'https://bar/{repo}/{id}', 'BUG', + 'silly me, I did not parenthesize the {id}, BUG12345.', 'silly me, I did not parenthesize the {id}, BUG.'), + (r'BUG(\d{5})', 'https://bar/{repo}/', 'BUG', + 'silly me, the URL does not contain {id}, BUG12345.', 'silly me, the URL does not contain {id}, BUG12345.'), + (r'(PR-\d+)', 'http://foo/{repo}/issue/{id}', '', + 'interesting issue #123, err PR-56', 'interesting issue #123, err PR-56'), # no match because empty prefix + ]) + def test_urlify_issues(self, issue_pat, issue_server, issue_prefix, sample, expected): + from kallithea.lib.helpers import urlify_issues + config_stub = { + 'sqlalchemy.url': 'foo', + 'issue_pat': issue_pat, + 'issue_server_link': issue_server, + 'issue_prefix': issue_prefix, + } + # force recreation of lazy function + with mock.patch('kallithea.lib.helpers._urlify_issues_f', None): + with mock.patch('kallithea.CONFIG', config_stub): + assert urlify_issues(sample, 'repo_name') == expected + + @parametrize('sample,expected', [ + ('abc X5', 'abc #5'), + ('abc pullrequest #6 xyz', 'abc PR#6 xyz'), + ('pull request7 #', 'PR#7 #'), + ('look PR9 and pr #11', 'look PR#9 and PR#11'), + ('pullrequest#10 solves issue 9', 'PR#10 solves bug#9'), + ('issue FAIL67', 'issue FAIL67'), # no match because empty prefix + ('issue FAILMORE89', 'issue FAILMORE89'), # no match because absent prefix + ]) + def test_urlify_issues_multiple_issue_patterns(self, sample, expected): + from kallithea.lib.helpers import urlify_issues + config_stub = { + 'sqlalchemy.url': 'foo', + 'issue_pat': 'X(\d+)', + 'issue_server_link': 'http://main/{repo}/main/{id}/', + 'issue_prefix': '#', + 'issue_pat_pr': '(?:pullrequest|pull request|PR|pr) ?#?(\d+)', + 'issue_server_link_pr': 'http://pr/{repo}/pr/{id}', + 'issue_prefix_pr': 'PR#', + 'issue_pat_bug': '(?:BUG|bug|issue) ?#?(\d+)', + 'issue_server_link_bug': 'http://bug/{repo}/bug/{id}', + 'issue_prefix_bug': 'bug#', + 'issue_pat_empty_prefix': 'FAIL(\d+)', + 'issue_server_link_empty_prefix': 'http://fail/{repo}/{id}', + 'issue_prefix_empty_prefix': '', + 'issue_pat_absent_prefix': 'FAILMORE(\d+)', + 'issue_server_link_absent_prefix': 'http://failmore/{repo}/{id}', + } + # force recreation of lazy function + with mock.patch('kallithea.lib.helpers._urlify_issues_f', None): + with mock.patch('kallithea.CONFIG', config_stub): + assert urlify_issues(sample, 'repo_name') == expected + @parametrize('test,expected', [ ("", None), ("/_2", '2'),