diff options
author | Marcin Kuzminski <marcin@python-works.com> | 2013-02-26 00:11:59 +0100 |
---|---|---|
committer | Marcin Kuzminski <marcin@python-works.com> | 2013-02-26 00:11:59 +0100 |
commit | 3574e99a0d5b234f1353cec994d828f0ffc4191c (patch) | |
tree | 976eb1f62db1b85ba90231a83eb4133dd0d35600 /rhodecode/tests | |
parent | 384f6ecb6333343813e3fa606330e6e5442f02cd (diff) |
fixed urlify changesets regex + tests
--HG--
branch : beta
Diffstat (limited to 'rhodecode/tests')
-rw-r--r-- | rhodecode/tests/test_libs.py | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/rhodecode/tests/test_libs.py b/rhodecode/tests/test_libs.py index 151c0393..135b5078 100644 --- a/rhodecode/tests/test_libs.py +++ b/rhodecode/tests/test_libs.py @@ -209,6 +209,21 @@ class TestLibs(unittest.TestCase): grav = gravatar_url(email_address=em, size=24) assert grav == 'https://server.com/%s/%s' % (_md5(em), 24) + def _quick_url(self, text, tmpl="""<a class="revision-link" href="%s">%s</a>""", url_=None): + """ + Changes `some text url[foo]` => `some text <a href="/">foo</a> + + :param text: + """ + import re + #quickly change expected url[] into a link + URL_PAT = re.compile(r'(?:url\[)(.+?)(?:\])') + + def url_func(match_obj): + _url = match_obj.groups()[0] + return tmpl % (url_ or '/some-url', _url) + return URL_PAT.sub(url_func, text) + @parameterized.expand([ ("", ""), @@ -228,27 +243,48 @@ class TestLibs(unittest.TestCase): "url[ffffffffffff] some text traalaa"), ("""Multi line 123123123123 - some text 123123123123""", + some text 123123123123 + sometimes ! + """, """Multi line url[123123123123] - some text url[123123123123]""") + some text url[123123123123] + sometimes ! + """) ]) def test_urlify_changesets(self, sample, expected): - import re - def fake_url(self, *args, **kwargs): return '/some-url' - #quickly change expected url[] into a link - URL_PAT = re.compile(r'(?:url\[)(.+?)(?:\])') - - def url_func(match_obj): - _url = match_obj.groups()[0] - tmpl = """<a class="revision-link" href="/some-url">%s</a>""" - return tmpl % _url - - expected = URL_PAT.sub(url_func, expected) + expected = self._quick_url(expected) with mock.patch('pylons.url', fake_url): from rhodecode.lib.helpers import urlify_changesets self.assertEqual(urlify_changesets(sample, 'repo_name'), expected) + + @parameterized.expand([ + ("", + "", + ""), + ("https://svn.apache.org/repos", + "url[https://svn.apache.org/repos]", + "https://svn.apache.org/repos"), + ("http://svn.apache.org/repos", + "url[http://svn.apache.org/repos]", + "http://svn.apache.org/repos"), + ("from rev a also rev http://google.com", + "from rev a also rev url[http://google.com]", + "http://google.com"), + ("""Multi line + https://foo.bar.com + some text lalala""", + """Multi line + url[https://foo.bar.com] + some text lalala""", + "https://foo.bar.com") + ]) + def test_urlify_test(self, sample, expected, url_): + from rhodecode.lib.helpers import urlify_text + expected = self._quick_url(expected, + tmpl="""<a href="%s">%s</a>""", url_=url_) + self.assertEqual(urlify_text(sample), expected) |