##// END OF EJS Templates
tests: add basic tests for urlify_issues...
Thomas De Schampheleire -
r7082:b43e77fa default
parent child Browse files
Show More
@@ -403,6 +403,66 b' class TestLibs(TestController):'
403 from kallithea.lib.helpers import urlify_text
403 from kallithea.lib.helpers import urlify_text
404 assert urlify_text(sample, 'repo_name', link_='#the-link') == expected
404 assert urlify_text(sample, 'repo_name', link_='#the-link') == expected
405
405
406 @parametrize('issue_pat,issue_server,issue_prefix,sample,expected', [
407 (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#',
408 'issue #123', 'issue <a class="issue-tracker-link" href="http://foo/repo_name/issue/123">#123</a>'),
409 (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#',
410 'issue#456', 'issue<a class="issue-tracker-link" href="http://foo/repo_name/issue/456">#456</a>'),
411 (r'#(\d+)', 'http://foo/{repo}/issue/{id}', 'PR',
412 'interesting issue #123', 'interesting issue <a class="issue-tracker-link" href="http://foo/repo_name/issue/123">PR123</a>'),
413 (r'BUG\d{5}', 'https://bar/{repo}/{id}', 'BUG',
414 'silly me, I did not parenthesize the {id}, BUG12345.', 'silly me, I did not parenthesize the {id}, <a class="issue-tracker-link" href="https://bar/repo_name/">BUG</a>.'),
415 (r'BUG(\d{5})', 'https://bar/{repo}/', 'BUG',
416 'silly me, the URL does not contain {id}, BUG12345.', 'silly me, the URL does not contain {id}, <a class="issue-tracker-link" href="https://bar/repo_name/">BUG12345</a>.'),
417 (r'(PR-\d+)', 'http://foo/{repo}/issue/{id}', '',
418 'interesting issue #123, err PR-56', 'interesting issue #123, err PR-56'), # no match because empty prefix
419 ])
420 def test_urlify_issues(self, issue_pat, issue_server, issue_prefix, sample, expected):
421 from kallithea.lib.helpers import urlify_issues
422 config_stub = {
423 'sqlalchemy.url': 'foo',
424 'issue_pat': issue_pat,
425 'issue_server_link': issue_server,
426 'issue_prefix': issue_prefix,
427 }
428 # force recreation of lazy function
429 with mock.patch('kallithea.lib.helpers._urlify_issues_f', None):
430 with mock.patch('kallithea.CONFIG', config_stub):
431 assert urlify_issues(sample, 'repo_name') == expected
432
433 @parametrize('sample,expected', [
434 ('abc X5', 'abc <a class="issue-tracker-link" href="http://main/repo_name/main/5/">#5</a>'),
435 ('abc pullrequest #6 xyz', 'abc <a class="issue-tracker-link" href="http://pr/repo_name/pr/6">PR#6</a> xyz'),
436 ('pull request7 #', '<a class="issue-tracker-link" href="http://pr/repo_name/pr/7">PR#7</a> #'),
437 ('look PR9 and pr #11', 'look <a class="issue-tracker-link" href="http://pr/repo_name/pr/9">PR#9</a> and <a class="issue-tracker-link" href="http://pr/repo_name/pr/11">PR#11</a>'),
438 ('pullrequest#10 solves issue 9', '<a class="issue-tracker-link" href="http://pr/repo_name/pr/10">PR#10</a> solves <a class="issue-tracker-link" href="http://bug/repo_name/bug/9">bug#9</a>'),
439 ('issue FAIL67', 'issue FAIL67'), # no match because empty prefix
440 ('issue FAILMORE89', 'issue FAILMORE89'), # no match because absent prefix
441 ])
442 def test_urlify_issues_multiple_issue_patterns(self, sample, expected):
443 from kallithea.lib.helpers import urlify_issues
444 config_stub = {
445 'sqlalchemy.url': 'foo',
446 'issue_pat': 'X(\d+)',
447 'issue_server_link': 'http://main/{repo}/main/{id}/',
448 'issue_prefix': '#',
449 'issue_pat_pr': '(?:pullrequest|pull request|PR|pr) ?#?(\d+)',
450 'issue_server_link_pr': 'http://pr/{repo}/pr/{id}',
451 'issue_prefix_pr': 'PR#',
452 'issue_pat_bug': '(?:BUG|bug|issue) ?#?(\d+)',
453 'issue_server_link_bug': 'http://bug/{repo}/bug/{id}',
454 'issue_prefix_bug': 'bug#',
455 'issue_pat_empty_prefix': 'FAIL(\d+)',
456 'issue_server_link_empty_prefix': 'http://fail/{repo}/{id}',
457 'issue_prefix_empty_prefix': '',
458 'issue_pat_absent_prefix': 'FAILMORE(\d+)',
459 'issue_server_link_absent_prefix': 'http://failmore/{repo}/{id}',
460 }
461 # force recreation of lazy function
462 with mock.patch('kallithea.lib.helpers._urlify_issues_f', None):
463 with mock.patch('kallithea.CONFIG', config_stub):
464 assert urlify_issues(sample, 'repo_name') == expected
465
406 @parametrize('test,expected', [
466 @parametrize('test,expected', [
407 ("", None),
467 ("", None),
408 ("/_2", '2'),
468 ("/_2", '2'),
General Comments 0
You need to be logged in to leave comments. Login now