annotate kallithea/tests/other/test_libs.py @ 4208:ad38f9f93b3b kallithea-2.2.5-rebrand

Correct licensing information in individual files. The top-level license file is now LICENSE.md. Also, in various places where there should have been joint copyright holders listed, a single copyright holder was listed. It does not appear easy to add a link to a large list of copyright holders in these places, so it simply refers to the fact that various authors hold copyright. In future, if an easy method is discovered to link to a list from those places, we should do so. Finally, text is added to LICENSE.md to point to where the full list of copyright holders is, and that Kallithea as a whole is GPLv3'd.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 21 May 2014 16:59:37 -0400
parents d1addaf7a91e
children 1948ede028ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1372
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
2 # This program is free software: you can redistribute it and/or modify
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
3 # it under the terms of the GNU General Public License as published by
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
5 # (at your option) any later version.
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
6 #
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
7 # This program is distributed in the hope that it will be useful,
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
10 # GNU General Public License for more details.
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
11 #
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
12 # You should have received a copy of the GNU General Public License
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1416
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
14 """
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
15 kallithea.tests.test_libs
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
18 Package for testing various lib/helper functions in rhodecode
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
20 :created_on: Jun 9, 2011
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
4208
ad38f9f93b3b Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
23 :license: GPLv3, see LICENSE.md for more details.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
24 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
25
2790
3c0ae44557c4 more py2.5 compatibility patches
Marcin Kuzminski <marcin@python-works.com>
parents: 2753
diff changeset
26 from __future__ import with_statement
2317
c4d8ed624728 Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents: 2201
diff changeset
27 import datetime
2753
e34a6b1eb594 added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
28 import hashlib
e34a6b1eb594 added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
29 import mock
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
30 from kallithea.tests import *
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
31 from kallithea.lib.utils2 import AttributeDict
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
32 from kallithea.model.db import Repository
1372
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 proto = 'http'
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 TEST_URLS = [
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 ('%s://127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 '%s://127.0.0.1' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 ('%s://marcink@127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 '%s://127.0.0.1' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 ('%s://marcink:pass@127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 '%s://127.0.0.1' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 ('%s://127.0.0.1:8080' % proto, ['%s://' % proto, '127.0.0.1', '8080'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 '%s://127.0.0.1:8080' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 '%s://domain.org' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 ('%s://user:pass@domain.org:8080' % proto, ['%s://' % proto, 'domain.org',
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 '8080'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 '%s://domain.org:8080' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 ]
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 proto = 'https'
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 TEST_URLS += [
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 ('%s://127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 '%s://127.0.0.1' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 ('%s://marcink@127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 '%s://127.0.0.1' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 ('%s://marcink:pass@127.0.0.1' % proto, ['%s://' % proto, '127.0.0.1'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 '%s://127.0.0.1' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 ('%s://127.0.0.1:8080' % proto, ['%s://' % proto, '127.0.0.1', '8080'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 '%s://127.0.0.1:8080' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 '%s://domain.org' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 ('%s://user:pass@domain.org:8080' % proto, ['%s://' % proto, 'domain.org',
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 '8080'],
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 '%s://domain.org:8080' % proto),
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 ]
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3824
diff changeset
69 class TestLibs(BaseTestCase):
1372
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
71 @parameterized.expand(TEST_URLS)
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
72 def test_uri_filter(self, test_url, expected, expected_creds):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
73 from kallithea.lib.utils2 import uri_filter
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
74 self.assertEqual(uri_filter(test_url), expected)
1372
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
76 @parameterized.expand(TEST_URLS)
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
77 def test_credentials_filter(self, test_url, expected, expected_creds):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
78 from kallithea.lib.utils2 import credentials_filter
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
79 self.assertEqual(credentials_filter(test_url), expected_creds)
1372
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
81 @parameterized.expand([('t', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
82 ('true', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
83 ('y', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
84 ('yes', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
85 ('on', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
86 ('1', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
87 ('Y', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
88 ('yeS', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
89 ('Y', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
90 ('TRUE', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
91 ('T', True),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
92 ('False', False),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
93 ('F', False),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
94 ('FALSE', False),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
95 ('0', False),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
96 ('-1', False),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
97 ('', False)
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
98 ])
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
99 def test_str2bool(self, str_bool, expected):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
100 from kallithea.lib.utils2 import str2bool
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
101 self.assertEqual(str2bool(str_bool), expected)
1372
fced98787f40 Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
103 def test_mention_extractor(self):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
104 from kallithea.lib.utils2 import extract_mentioned_users
2201
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
105 sample = (
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
106 "@first hi there @marcink here's my email marcin@email.com "
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
107 "@lukaszb check @one_more22 it pls @ ttwelve @D[] @one@two@three "
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
108 "@MARCIN @maRCiN @2one_more22 @john please see this http://org.pl "
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
109 "@marian.user just do it @marco-polo and next extract @marco_polo "
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
110 "user.dot hej ! not-needed maril@domain.org"
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
111 )
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
112
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
113 s = sorted([
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
114 'first', 'marcink', 'lukaszb', 'one_more22', 'MARCIN', 'maRCiN', 'john',
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
115 'marian.user', 'marco-polo', 'marco_polo'
ea5ff843b200 #426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
116 ], key=lambda k: k.lower())
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
117 self.assertEqual(s, extract_mentioned_users(sample))
2317
c4d8ed624728 Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents: 2201
diff changeset
118
3644
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
119 @parameterized.expand([
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
120 (dict(), u'just now'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
121 (dict(seconds= -1), u'1 second ago'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
122 (dict(seconds= -60 * 2), u'2 minutes ago'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
123 (dict(hours= -1), u'1 hour ago'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
124 (dict(hours= -24), u'1 day ago'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
125 (dict(hours= -24 * 5), u'5 days ago'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
126 (dict(months= -1), u'1 month ago'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
127 (dict(months= -1, days= -2), u'1 month and 2 days ago'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
128 (dict(years= -1, months= -1), u'1 year and 1 month ago'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
129 ])
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
130 def test_age(self, age_args, expected):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
131 from kallithea.lib.utils2 import age
3261
54a439edaf99 fixed AGE funtion for future dates, testa are now cleaner with dateutil usage
Marcin Kuzminski <marcin@python-works.com>
parents: 3132
diff changeset
132 from dateutil import relativedelta
3644
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
133 n = datetime.datetime(year=2012, month=5, day=17)
3261
54a439edaf99 fixed AGE funtion for future dates, testa are now cleaner with dateutil usage
Marcin Kuzminski <marcin@python-works.com>
parents: 3132
diff changeset
134 delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs)
3644
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
135 self.assertEqual(age(n + delt(**age_args), now=n), expected)
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
136
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
137 @parameterized.expand([
3261
54a439edaf99 fixed AGE funtion for future dates, testa are now cleaner with dateutil usage
Marcin Kuzminski <marcin@python-works.com>
parents: 3132
diff changeset
138
3644
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
139 (dict(), u'just now'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
140 (dict(seconds=1), u'in 1 second'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
141 (dict(seconds=60 * 2), u'in 2 minutes'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
142 (dict(hours=1), u'in 1 hour'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
143 (dict(hours=24), u'in 1 day'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
144 (dict(hours=24 * 5), u'in 5 days'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
145 (dict(months=1), u'in 1 month'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
146 (dict(months=1, days=1), u'in 1 month and 1 day'),
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
147 (dict(years=1, months=1), u'in 1 year and 1 month')
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
148 ])
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
149 def test_age_in_future(self, age_args, expected):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
150 from kallithea.lib.utils2 import age
3261
54a439edaf99 fixed AGE funtion for future dates, testa are now cleaner with dateutil usage
Marcin Kuzminski <marcin@python-works.com>
parents: 3132
diff changeset
151 from dateutil import relativedelta
3644
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
152 n = datetime.datetime(year=2012, month=5, day=17)
3261
54a439edaf99 fixed AGE funtion for future dates, testa are now cleaner with dateutil usage
Marcin Kuzminski <marcin@python-works.com>
parents: 3132
diff changeset
153 delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs)
3644
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
154 self.assertEqual(age(n + delt(**age_args), now=n), expected)
2902
e2b2791d1e7c fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents: 2846
diff changeset
155
2674
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
156 def test_tag_exctrator(self):
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
157 sample = (
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
158 "hello pta[tag] gog [[]] [[] sda ero[or]d [me =>>< sa]"
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
159 "[requires] [stale] [see<>=>] [see => http://url.com]"
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
160 "[requires => url] [lang => python] [just a tag]"
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
161 "[,d] [ => ULR ] [obsolete] [desc]]"
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
162 )
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
163 from kallithea.lib.helpers import desc_stylize
2674
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
164 res = desc_stylize(sample)
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
165 self.assertTrue('<div class="metatag" tag="tag">tag</div>' in res)
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
166 self.assertTrue('<div class="metatag" tag="obsolete">obsolete</div>' in res)
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
167 self.assertTrue('<div class="metatag" tag="stale">stale</div>' in res)
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
168 self.assertTrue('<div class="metatag" tag="lang">python</div>' in res)
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
169 self.assertTrue('<div class="metatag" tag="requires">requires =&gt; <a href="/url">url</a></div>' in res)
a221706dab50 merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents: 2371
diff changeset
170 self.assertTrue('<div class="metatag" tag="tag">tag</div>' in res)
2753
e34a6b1eb594 added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
171
e34a6b1eb594 added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
172 def test_alternative_gravatar(self):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
173 from kallithea.lib.helpers import gravatar_url
2753
e34a6b1eb594 added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
174 _md5 = lambda s: hashlib.md5(s).hexdigest()
e34a6b1eb594 added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
175
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
176 #mock pylons.url
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
177 class fake_url(object):
2836
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
178 @classmethod
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
179 def current(cls, *args, **kwargs):
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
180 return 'https://server.com'
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
181
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
182 #mock pylons.tmpl_context
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
183 def fake_tmpl_context(_url):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
184 _c = AttributeDict()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
185 _c.visual = AttributeDict()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
186 _c.visual.use_gravatar = True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
187 _c.visual.gravatar_url = _url
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
188
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
189 return _c
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
190
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
191
2836
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
192 with mock.patch('pylons.url', fake_url):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
193 fake = fake_tmpl_context(_url='http://test.com/{email}')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
194 with mock.patch('pylons.tmpl_context', fake):
2836
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
195 from pylons import url
2846
620669b2a88b fixed gravatar test typo
Marcin Kuzminski <marcin@python-works.com>
parents: 2836
diff changeset
196 assert url.current() == 'https://server.com'
2836
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
197 grav = gravatar_url(email_address='test@foo.com', size=24)
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
198 assert grav == 'http://test.com/test@foo.com'
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
199
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
200 fake = fake_tmpl_context(_url='http://test.com/{email}')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
201 with mock.patch('pylons.tmpl_context', fake):
2836
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
202 grav = gravatar_url(email_address='test@foo.com', size=24)
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
203 assert grav == 'http://test.com/test@foo.com'
2753
e34a6b1eb594 added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
204
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
205 fake = fake_tmpl_context(_url='http://test.com/{md5email}')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
206 with mock.patch('pylons.tmpl_context', fake):
2836
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
207 em = 'test@foo.com'
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
208 grav = gravatar_url(email_address=em, size=24)
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
209 assert grav == 'http://test.com/%s' % (_md5(em))
2753
e34a6b1eb594 added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents: 2674
diff changeset
210
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
211 fake = fake_tmpl_context(_url='http://test.com/{md5email}/{size}')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
212 with mock.patch('pylons.tmpl_context', fake):
2836
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
213 em = 'test@foo.com'
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
214 grav = gravatar_url(email_address=em, size=24)
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
215 assert grav == 'http://test.com/%s/%s' % (_md5(em), 24)
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
216
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
217 fake = fake_tmpl_context(_url='{scheme}://{netloc}/{md5email}/{size}')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
218 with mock.patch('pylons.tmpl_context', fake):
2836
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
219 em = 'test@foo.com'
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
220 grav = gravatar_url(email_address=em, size=24)
819eb7f8a555 Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents: 2790
diff changeset
221 assert grav == 'https://server.com/%s/%s' % (_md5(em), 24)
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
222
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
223 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
224 (Repository.DEFAULT_CLONE_URI, 'group/repo1', {}, '', 'http://vps1:8000/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
225 (Repository.DEFAULT_CLONE_URI, 'group/repo1', {'user': 'marcink'}, '', 'http://marcink@vps1:8000/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
226 (Repository.DEFAULT_CLONE_URI, 'group/repo1', {}, '/rc', 'http://vps1:8000/rc/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
227 (Repository.DEFAULT_CLONE_URI, 'group/repo1', {'user': 'user'}, '/rc', 'http://user@vps1:8000/rc/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
228 (Repository.DEFAULT_CLONE_URI, 'group/repo1', {'user': 'marcink'}, '/rc', 'http://marcink@vps1:8000/rc/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
229 (Repository.DEFAULT_CLONE_URI, 'group/repo1', {'user': 'user'}, '/rc/', 'http://user@vps1:8000/rc/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
230 (Repository.DEFAULT_CLONE_URI, 'group/repo1', {'user': 'marcink'}, '/rc/', 'http://marcink@vps1:8000/rc/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
231 ('{scheme}://{user}@{netloc}/_{repoid}', 'group/repo1', {}, '', 'http://vps1:8000/_23'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
232 ('{scheme}://{user}@{netloc}/_{repoid}', 'group/repo1', {'user': 'marcink'}, '', 'http://marcink@vps1:8000/_23'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
233 ('http://{user}@{netloc}/_{repoid}', 'group/repo1', {'user': 'marcink'}, '', 'http://marcink@vps1:8000/_23'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
234 ('http://{netloc}/_{repoid}', 'group/repo1', {'user': 'marcink'}, '', 'http://vps1:8000/_23'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
235 ('https://{user}@proxy1.server.com/{repo}', 'group/repo1', {'user': 'marcink'}, '', 'https://marcink@proxy1.server.com/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
236 ('https://{user}@proxy1.server.com/{repo}', 'group/repo1', {}, '', 'https://proxy1.server.com/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
237 ('https://proxy1.server.com/{user}/{repo}', 'group/repo1', {'user': 'marcink'}, '', 'https://proxy1.server.com/marcink/group/repo1'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
238 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
239 def test_clone_url_generator(self, tmpl, repo_name, overrides, prefix, expected):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
240 from kallithea.lib.utils2 import get_clone_url
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
241 clone_url = get_clone_url(uri_tmpl=tmpl, qualifed_home_url='http://vps1:8000'+prefix,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
242 repo_name=repo_name, repo_id=23, **overrides)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
243 self.assertEqual(clone_url, expected)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
244
3405
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
245 def _quick_url(self, text, tmpl="""<a class="revision-link" href="%s">%s</a>""", url_=None):
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
246 """
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
247 Changes `some text url[foo]` => `some text <a href="/">foo</a>
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
248
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
249 :param text:
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
250 """
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
251 import re
3644
71860d0737e7 - age tests cannot be dynamic, there are cases when age calculation
Marcin Kuzminski <marcin@python-works.com>
parents: 3405
diff changeset
252 # quickly change expected url[] into a link
3405
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
253 URL_PAT = re.compile(r'(?:url\[)(.+?)(?:\])')
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
254
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
255 def url_func(match_obj):
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
256 _url = match_obj.groups()[0]
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
257 return tmpl % (url_ or '/some-url', _url)
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
258 return URL_PAT.sub(url_func, text)
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
259
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
260 @parameterized.expand([
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
261 ("",
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
262 ""),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
263 ("git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68",
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
264 "git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68"),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
265 ("from rev 000000000000",
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
266 "from rev url[000000000000]"),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
267 ("from rev 000000000000123123 also rev 000000000000",
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
268 "from rev url[000000000000123123] also rev url[000000000000]"),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
269 ("this should-000 00",
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
270 "this should-000 00"),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
271 ("longtextffffffffff rev 123123123123",
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
272 "longtextffffffffff rev url[123123123123]"),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
273 ("rev ffffffffffffffffffffffffffffffffffffffffffffffffff",
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
274 "rev ffffffffffffffffffffffffffffffffffffffffffffffffff"),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
275 ("ffffffffffff some text traalaa",
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
276 "url[ffffffffffff] some text traalaa"),
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
277 ("""Multi line
3394
fe2bb88bf7ac whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3385
diff changeset
278 123123123123
3405
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
279 some text 123123123123
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
280 sometimes !
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
281 """,
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
282 """Multi line
3394
fe2bb88bf7ac whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3385
diff changeset
283 url[123123123123]
3405
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
284 some text url[123123123123]
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
285 sometimes !
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
286 """)
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
287 ])
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
288 def test_urlify_changesets(self, sample, expected):
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
289 def fake_url(self, *args, **kwargs):
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
290 return '/some-url'
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
291
3405
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
292 expected = self._quick_url(expected)
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
293
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
294 with mock.patch('pylons.url', fake_url):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
295 from kallithea.lib.helpers import urlify_changesets
3385
d21c762f5c4b revision extraction function shouldn't be so eager, just extract commits that are
Marcin Kuzminski <marcin@python-works.com>
parents: 3261
diff changeset
296 self.assertEqual(urlify_changesets(sample, 'repo_name'), expected)
3405
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
297
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
298 @parameterized.expand([
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
299 ("",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
300 "",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
301 ""),
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
302 ("https://svn.apache.org/repos",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
303 "url[https://svn.apache.org/repos]",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
304 "https://svn.apache.org/repos"),
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
305 ("http://svn.apache.org/repos",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
306 "url[http://svn.apache.org/repos]",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
307 "http://svn.apache.org/repos"),
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
308 ("from rev a also rev http://google.com",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
309 "from rev a also rev url[http://google.com]",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
310 "http://google.com"),
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
311 ("""Multi line
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
312 https://foo.bar.com
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
313 some text lalala""",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
314 """Multi line
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
315 url[https://foo.bar.com]
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
316 some text lalala""",
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
317 "https://foo.bar.com")
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
318 ])
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
319 def test_urlify_test(self, sample, expected, url_):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
320 from kallithea.lib.helpers import urlify_text
3405
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
321 expected = self._quick_url(expected,
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
322 tmpl="""<a href="%s">%s</a>""", url_=url_)
a9adca4ba3c9 fixed urlify changesets regex + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
323 self.assertEqual(urlify_text(sample), expected)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
324
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
325 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
326 ("", None),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
327 ("/_2", '2'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
328 ("_2", '2'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
329 ("/_2/", '2'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
330 ("_2/", '2'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
331
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
332 ("/_21", '21'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
333 ("_21", '21'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
334 ("/_21/", '21'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
335 ("_21/", '21'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
336
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
337 ("/_21/foobar", '21'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
338 ("_21/121", '21'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
339 ("/_21/_12", '21'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
340 ("_21/rc/foo", '21'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
341
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
342 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
343 def test_get_repo_by_id(self, test, expected):
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
344 from kallithea.lib.utils import _extract_id_from_repo_name
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
345 _test = _extract_id_from_repo_name(test)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
346 self.assertEqual(_test, expected, msg='url:%s, got:`%s` expected: `%s`'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3913
diff changeset
347 % (test, _test, expected))