Show More
@@ -996,24 +996,29 b' def urlify_changesets(text_, repository)' | |||||
996 | :param text_: |
|
996 | :param text_: | |
997 | :param repository: |
|
997 | :param repository: | |
998 | """ |
|
998 | """ | |
999 |
|
999 | from pylons import url # doh, we need to re-import url to mock it later | ||
1000 | URL_PAT = re.compile(r'([0-9a-fA-F]{12,})') |
|
1000 | URL_PAT = re.compile(r'(?:^|\s)([0-9a-fA-F]{12,40})(?:$|\s)') | |
1001 |
|
1001 | |||
1002 | def url_func(match_obj): |
|
1002 | def url_func(match_obj): | |
1003 | rev = match_obj.groups()[0] |
|
1003 | rev = match_obj.groups()[0] | |
1004 | pref = '' |
|
1004 | pref = '' | |
|
1005 | suf = '' | |||
1005 | if match_obj.group().startswith(' '): |
|
1006 | if match_obj.group().startswith(' '): | |
1006 | pref = ' ' |
|
1007 | pref = ' ' | |
|
1008 | if match_obj.group().endswith(' '): | |||
|
1009 | suf = ' ' | |||
1007 | tmpl = ( |
|
1010 | tmpl = ( | |
1008 | '%(pref)s<a class="%(cls)s" href="%(url)s">' |
|
1011 | '%(pref)s<a class="%(cls)s" href="%(url)s">' | |
1009 | '%(rev)s' |
|
1012 | '%(rev)s' | |
1010 | '</a>' |
|
1013 | '</a>' | |
|
1014 | '%(suf)s' | |||
1011 | ) |
|
1015 | ) | |
1012 | return tmpl % { |
|
1016 | return tmpl % { | |
1013 | 'pref': pref, |
|
1017 | 'pref': pref, | |
1014 | 'cls': 'revision-link', |
|
1018 | 'cls': 'revision-link', | |
1015 | 'url': url('changeset_home', repo_name=repository, revision=rev), |
|
1019 | 'url': url('changeset_home', repo_name=repository, revision=rev), | |
1016 | 'rev': rev, |
|
1020 | 'rev': rev, | |
|
1021 | 'suf': suf | |||
1017 | } |
|
1022 | } | |
1018 |
|
1023 | |||
1019 | newtext = URL_PAT.sub(url_func, text_) |
|
1024 | newtext = URL_PAT.sub(url_func, text_) |
@@ -66,41 +66,37 b' TEST_URLS += [' | |||||
66 |
|
66 | |||
67 | class TestLibs(unittest.TestCase): |
|
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 | from rhodecode.lib.utils2 import uri_filter |
|
71 | from rhodecode.lib.utils2 import uri_filter | |
|
72 | self.assertEqual(uri_filter(test_url), expected) | |||
71 |
|
73 | |||
72 | for url in TEST_URLS: |
|
74 | @parameterized.expand(TEST_URLS) | |
73 | self.assertEqual(uri_filter(url[0]), url[1]) |
|
75 | def test_credentials_filter(self, test_url, expected, expected_creds): | |
|
76 | from rhodecode.lib.utils2 import credentials_filter | |||
|
77 | self.assertEqual(credentials_filter(test_url), expected_creds) | |||
74 |
|
78 | |||
75 | def test_credentials_filter(self): |
|
79 | @parameterized.expand([('t', True), | |
76 | from rhodecode.lib.utils2 import credentials_filter |
|
80 | ('true', True), | |
77 |
|
81 | ('y', True), | ||
78 | for url in TEST_URLS: |
|
82 | ('yes', True), | |
79 | self.assertEqual(credentials_filter(url[0]), url[2]) |
|
83 | ('on', True), | |
80 |
|
84 | ('1', True), | ||
81 | def test_str2bool(self): |
|
85 | ('Y', True), | |
|
86 | ('yeS', True), | |||
|
87 | ('Y', True), | |||
|
88 | ('TRUE', True), | |||
|
89 | ('T', True), | |||
|
90 | ('False', False), | |||
|
91 | ('F', False), | |||
|
92 | ('FALSE', False), | |||
|
93 | ('0', False), | |||
|
94 | ('-1', False), | |||
|
95 | ('', False) | |||
|
96 | ]) | |||
|
97 | def test_str2bool(self, str_bool, expected): | |||
82 | from rhodecode.lib.utils2 import str2bool |
|
98 | from rhodecode.lib.utils2 import str2bool | |
83 | test_cases = [ |
|
99 | self.assertEqual(str2bool(str_bool), expected) | |
84 | ('t', True), |
|
|||
85 | ('true', True), |
|
|||
86 | ('y', True), |
|
|||
87 | ('yes', True), |
|
|||
88 | ('on', True), |
|
|||
89 | ('1', True), |
|
|||
90 | ('Y', True), |
|
|||
91 | ('yeS', True), |
|
|||
92 | ('Y', True), |
|
|||
93 | ('TRUE', True), |
|
|||
94 | ('T', True), |
|
|||
95 | ('False', False), |
|
|||
96 | ('F', False), |
|
|||
97 | ('FALSE', False), |
|
|||
98 | ('0', False), |
|
|||
99 | ('-1', False), |
|
|||
100 | ('', False), ] |
|
|||
101 |
|
||||
102 | for case in test_cases: |
|
|||
103 | self.assertEqual(str2bool(case[0]), case[1]) |
|
|||
104 |
|
100 | |||
105 | def test_mention_extractor(self): |
|
101 | def test_mention_extractor(self): | |
106 | from rhodecode.lib.utils2 import extract_mentioned_users |
|
102 | from rhodecode.lib.utils2 import extract_mentioned_users | |
@@ -212,3 +208,47 b' class TestLibs(unittest.TestCase):' | |||||
212 | em = 'test@foo.com' |
|
208 | em = 'test@foo.com' | |
213 | grav = gravatar_url(email_address=em, size=24) |
|
209 | grav = gravatar_url(email_address=em, size=24) | |
214 | assert grav == 'https://server.com/%s/%s' % (_md5(em), 24) |
|
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