##// END OF EJS Templates
revision extraction function shouldn't be so eager, just extract commits that are...
marcink -
r3385:d21c762f beta
parent child Browse files
Show More
@@ -996,24 +996,29 def urlify_changesets(text_, repository)
996 996 :param text_:
997 997 :param repository:
998 998 """
999
1000 URL_PAT = re.compile(r'([0-9a-fA-F]{12,})')
999 from pylons import url # doh, we need to re-import url to mock it later
1000 URL_PAT = re.compile(r'(?:^|\s)([0-9a-fA-F]{12,40})(?:$|\s)')
1001 1001
1002 1002 def url_func(match_obj):
1003 1003 rev = match_obj.groups()[0]
1004 1004 pref = ''
1005 suf = ''
1005 1006 if match_obj.group().startswith(' '):
1006 1007 pref = ' '
1008 if match_obj.group().endswith(' '):
1009 suf = ' '
1007 1010 tmpl = (
1008 1011 '%(pref)s<a class="%(cls)s" href="%(url)s">'
1009 1012 '%(rev)s'
1010 1013 '</a>'
1014 '%(suf)s'
1011 1015 )
1012 1016 return tmpl % {
1013 1017 'pref': pref,
1014 1018 'cls': 'revision-link',
1015 1019 'url': url('changeset_home', repo_name=repository, revision=rev),
1016 1020 'rev': rev,
1021 'suf': suf
1017 1022 }
1018 1023
1019 1024 newtext = URL_PAT.sub(url_func, text_)
@@ -66,22 +66,17 TEST_URLS += [
66 66
67 67 class TestLibs(unittest.TestCase):
68 68
69 def test_uri_filter(self):
69 @parameterized.expand(TEST_URLS)
70 def test_uri_filter(self, test_url, expected, expected_creds):
70 71 from rhodecode.lib.utils2 import uri_filter
72 self.assertEqual(uri_filter(test_url), expected)
71 73
72 for url in TEST_URLS:
73 self.assertEqual(uri_filter(url[0]), url[1])
74
75 def test_credentials_filter(self):
74 @parameterized.expand(TEST_URLS)
75 def test_credentials_filter(self, test_url, expected, expected_creds):
76 76 from rhodecode.lib.utils2 import credentials_filter
77
78 for url in TEST_URLS:
79 self.assertEqual(credentials_filter(url[0]), url[2])
77 self.assertEqual(credentials_filter(test_url), expected_creds)
80 78
81 def test_str2bool(self):
82 from rhodecode.lib.utils2 import str2bool
83 test_cases = [
84 ('t', True),
79 @parameterized.expand([('t', True),
85 80 ('true', True),
86 81 ('y', True),
87 82 ('yes', True),
@@ -97,10 +92,11 class TestLibs(unittest.TestCase):
97 92 ('FALSE', False),
98 93 ('0', False),
99 94 ('-1', False),
100 ('', False), ]
101
102 for case in test_cases:
103 self.assertEqual(str2bool(case[0]), case[1])
95 ('', False)
96 ])
97 def test_str2bool(self, str_bool, expected):
98 from rhodecode.lib.utils2 import str2bool
99 self.assertEqual(str2bool(str_bool), expected)
104 100
105 101 def test_mention_extractor(self):
106 102 from rhodecode.lib.utils2 import extract_mentioned_users
@@ -212,3 +208,47 class TestLibs(unittest.TestCase):
212 208 em = 'test@foo.com'
213 209 grav = gravatar_url(email_address=em, size=24)
214 210 assert grav == 'https://server.com/%s/%s' % (_md5(em), 24)
211
212 @parameterized.expand([
213 ("",
214 ""),
215 ("git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68",
216 "git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68"),
217 ("from rev 000000000000",
218 "from rev url[000000000000]"),
219 ("from rev 000000000000123123 also rev 000000000000",
220 "from rev url[000000000000123123] also rev url[000000000000]"),
221 ("this should-000 00",
222 "this should-000 00"),
223 ("longtextffffffffff rev 123123123123",
224 "longtextffffffffff rev url[123123123123]"),
225 ("rev ffffffffffffffffffffffffffffffffffffffffffffffffff",
226 "rev ffffffffffffffffffffffffffffffffffffffffffffffffff"),
227 ("ffffffffffff some text traalaa",
228 "url[ffffffffffff] some text traalaa"),
229 ("""Multi line
230 123123123123
231 some text 123123123123""",
232 """Multi line
233 url[123123123123]
234 some text url[123123123123]""")
235 ])
236 def test_urlify_changesets(self, sample, expected):
237 import re
238
239 def fake_url(self, *args, **kwargs):
240 return '/some-url'
241
242 #quickly change expected url[] into a link
243 URL_PAT = re.compile(r'(?:url\[)(.+?)(?:\])')
244
245 def url_func(match_obj):
246 _url = match_obj.groups()[0]
247 tmpl = """<a class="revision-link" href="/some-url">%s</a>"""
248 return tmpl % _url
249
250 expected = URL_PAT.sub(url_func, expected)
251
252 with mock.patch('pylons.url', fake_url):
253 from rhodecode.lib.helpers import urlify_changesets
254 self.assertEqual(urlify_changesets(sample, 'repo_name'), expected)
General Comments 0
You need to be logged in to leave comments. Login now