Show More
@@ -1004,21 +1004,16 b' def urlify_changesets(text_, repository)' | |||
|
1004 | 1004 | :param repository: repo name to build the URL with |
|
1005 | 1005 | """ |
|
1006 | 1006 | from pylons import url # doh, we need to re-import url to mock it later |
|
1007 |
URL_PAT = re.compile(r'( |
|
|
1007 | URL_PAT = re.compile(r'(^|\s)([0-9a-fA-F]{12,40})($|\s)') | |
|
1008 | 1008 | |
|
1009 | 1009 | def url_func(match_obj): |
|
1010 |
rev = match_obj.groups()[ |
|
|
1011 | pref = '' | |
|
1012 | suf = '' | |
|
1013 | if match_obj.group().startswith(' '): | |
|
1014 | pref = ' ' | |
|
1015 | if match_obj.group().endswith(' '): | |
|
1016 | suf = ' ' | |
|
1010 | rev = match_obj.groups()[1] | |
|
1011 | pref = match_obj.groups()[0] | |
|
1012 | suf = match_obj.groups()[2] | |
|
1013 | ||
|
1017 | 1014 | tmpl = ( |
|
1018 | 1015 | '%(pref)s<a class="%(cls)s" href="%(url)s">' |
|
1019 | '%(rev)s' | |
|
1020 | '</a>' | |
|
1021 | '%(suf)s' | |
|
1016 | '%(rev)s</a>%(suf)s' | |
|
1022 | 1017 | ) |
|
1023 | 1018 | return tmpl % { |
|
1024 | 1019 | 'pref': pref, |
@@ -209,6 +209,21 b' class TestLibs(unittest.TestCase):' | |||
|
209 | 209 | grav = gravatar_url(email_address=em, size=24) |
|
210 | 210 | assert grav == 'https://server.com/%s/%s' % (_md5(em), 24) |
|
211 | 211 | |
|
212 | def _quick_url(self, text, tmpl="""<a class="revision-link" href="%s">%s</a>""", url_=None): | |
|
213 | """ | |
|
214 | Changes `some text url[foo]` => `some text <a href="/">foo</a> | |
|
215 | ||
|
216 | :param text: | |
|
217 | """ | |
|
218 | import re | |
|
219 | #quickly change expected url[] into a link | |
|
220 | URL_PAT = re.compile(r'(?:url\[)(.+?)(?:\])') | |
|
221 | ||
|
222 | def url_func(match_obj): | |
|
223 | _url = match_obj.groups()[0] | |
|
224 | return tmpl % (url_ or '/some-url', _url) | |
|
225 | return URL_PAT.sub(url_func, text) | |
|
226 | ||
|
212 | 227 | @parameterized.expand([ |
|
213 | 228 | ("", |
|
214 | 229 | ""), |
@@ -228,27 +243,48 b' class TestLibs(unittest.TestCase):' | |||
|
228 | 243 | "url[ffffffffffff] some text traalaa"), |
|
229 | 244 | ("""Multi line |
|
230 | 245 | 123123123123 |
|
231 |
some text 123123123123 |
|
|
246 | some text 123123123123 | |
|
247 | sometimes ! | |
|
248 | """, | |
|
232 | 249 | """Multi line |
|
233 | 250 | url[123123123123] |
|
234 |
some text url[123123123123] |
|
|
251 | some text url[123123123123] | |
|
252 | sometimes ! | |
|
253 | """) | |
|
235 | 254 | ]) |
|
236 | 255 | def test_urlify_changesets(self, sample, expected): |
|
237 | import re | |
|
238 | ||
|
239 | 256 | def fake_url(self, *args, **kwargs): |
|
240 | 257 | return '/some-url' |
|
241 | 258 | |
|
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) | |
|
259 | expected = self._quick_url(expected) | |
|
251 | 260 | |
|
252 | 261 | with mock.patch('pylons.url', fake_url): |
|
253 | 262 | from rhodecode.lib.helpers import urlify_changesets |
|
254 | 263 | self.assertEqual(urlify_changesets(sample, 'repo_name'), expected) |
|
264 | ||
|
265 | @parameterized.expand([ | |
|
266 | ("", | |
|
267 | "", | |
|
268 | ""), | |
|
269 | ("https://svn.apache.org/repos", | |
|
270 | "url[https://svn.apache.org/repos]", | |
|
271 | "https://svn.apache.org/repos"), | |
|
272 | ("http://svn.apache.org/repos", | |
|
273 | "url[http://svn.apache.org/repos]", | |
|
274 | "http://svn.apache.org/repos"), | |
|
275 | ("from rev a also rev http://google.com", | |
|
276 | "from rev a also rev url[http://google.com]", | |
|
277 | "http://google.com"), | |
|
278 | ("""Multi line | |
|
279 | https://foo.bar.com | |
|
280 | some text lalala""", | |
|
281 | """Multi line | |
|
282 | url[https://foo.bar.com] | |
|
283 | some text lalala""", | |
|
284 | "https://foo.bar.com") | |
|
285 | ]) | |
|
286 | def test_urlify_test(self, sample, expected, url_): | |
|
287 | from rhodecode.lib.helpers import urlify_text | |
|
288 | expected = self._quick_url(expected, | |
|
289 | tmpl="""<a href="%s">%s</a>""", url_=url_) | |
|
290 | self.assertEqual(urlify_text(sample), expected) |
General Comments 0
You need to be logged in to leave comments.
Login now