Mercurial > kallithea
changeset 7170:28317fc212f4
tests: issues: use urlify_text wrapper rather than urlify_issues directly
urlify_text is a wrapper around different kinds of urlification methods.
The other tests for urlification use that wrapper, while the new
urlify_issues tests introduced in commit b43e77fa50dd used urlify_issues
directly.
By itself this is not a real problem, but it does not allow to detect the
interplay between different urlification issues. For example, an issue
pattern normally detecting #123 conflicts with the escaping of an apostrophe
' into ' . Some new tests exposing this problem are added.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Wed, 14 Feb 2018 08:32:19 +0100 |
parents | 7d02958345ff |
children | f91844b26269 |
files | kallithea/tests/other/test_libs.py |
diffstat | 1 files changed, 13 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/tests/other/test_libs.py Thu Feb 15 00:23:52 2018 +0100 +++ b/kallithea/tests/other/test_libs.py Wed Feb 14 08:32:19 2018 +0100 @@ -380,6 +380,10 @@ """which must not come after whitespace """ """and not be followed by * or alphanumerical <b>*characters*</b>.""", "-"), + ("HTML escaping: <abc> 'single' \"double\" &pointer", + # problem: ' is encoded as ' which however is interpreted as #39 and expanded to a issue link + """HTML escaping: <abc> &<a class="issue-tracker-link" href="https://issues.example.com/repo_name/issue/39">#39</a>;single&<a class="issue-tracker-link" href="https://issues.example.com/repo_name/issue/39">#39</a>; "double" &pointer""", + "-"), # tags are covered by test_tag_extractor ]) def test_urlify_test(self, sample, expected, url_): @@ -416,9 +420,14 @@ '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>.'), (r'(PR-\d+)', 'http://foo/{repo}/issue/{id}', '', 'interesting issue #123, err PR-56', 'interesting issue #123, err <a class="issue-tracker-link" href="http://foo/repo_name/issue/PR-56">PR-56</a>'), + # problem: ' is encoded as ' which however is interpreted as #39 and expanded to a issue link + (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', + "some 'standard' text with apostrophes", 'some &<a class="issue-tracker-link" href="http://foo/repo_name/issue/39">#39</a>;standard&<a class="issue-tracker-link" href="http://foo/repo_name/issue/39">#39</a>; text with apostrophes'), + (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', + "some 'standard' issue #123", 'some &<a class="issue-tracker-link" href="http://foo/repo_name/issue/39">#39</a>;standard&<a class="issue-tracker-link" href="http://foo/repo_name/issue/39">#39</a>; issue <a class="issue-tracker-link" href="http://foo/repo_name/issue/123">#123</a>'), ]) def test_urlify_issues(self, issue_pat, issue_server, issue_prefix, sample, expected): - from kallithea.lib.helpers import urlify_issues + from kallithea.lib.helpers import urlify_text config_stub = { 'sqlalchemy.url': 'foo', 'issue_pat': issue_pat, @@ -428,7 +437,7 @@ # 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 + assert urlify_text(sample, 'repo_name') == expected @parametrize('sample,expected', [ ('abc X5', 'abc <a class="issue-tracker-link" href="http://main/repo_name/main/5/">#5</a>'), @@ -440,7 +449,7 @@ ('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 + from kallithea.lib.helpers import urlify_text config_stub = { 'sqlalchemy.url': 'foo', 'issue_pat': 'X(\d+)', @@ -461,7 +470,7 @@ # 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 + assert urlify_text(sample, 'repo_name') == expected @parametrize('test,expected', [ ("", None),