Mercurial > kallithea
annotate rhodecode/tests/test_libs.py @ 2501:044c31d67ccc beta
make get_action always return action
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 21 Jun 2012 17:51:01 +0200 |
parents | a05e01144a2c |
children | a221706dab50 |
rev | line source |
---|---|
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.tests.test_libs |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 |
1416
df04752daa64
test env update
Marcin Kuzminski <marcin@python-works.com>
parents:
1372
diff
changeset
|
7 Package for testing various lib/helper functions in rhodecode |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
8 |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :created_on: Jun 9, 2011 |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
10 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
1532
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
1532
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
13 # 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
|
14 # 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
|
15 # the Free Software Foundation, either version 3 of the License, or |
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
16 # (at your option) any later version. |
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
17 # |
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
18 # 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
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
21 # GNU General Public License for more details. |
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
22 # |
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
23 # 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
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
2317
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
26 import unittest |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
27 import datetime |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
28 from rhodecode.tests import * |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 proto = 'http' |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 TEST_URLS = [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 ('%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
|
34 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 ('%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
|
36 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 ('%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
|
38 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 ('%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
|
40 '%s://127.0.0.1:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 '%s://domain.org' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 ('%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
|
44 '8080'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 '%s://domain.org:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 ] |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 proto = 'https' |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 TEST_URLS += [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 ('%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
|
51 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 ('%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
|
53 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 ('%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
|
55 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 ('%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
|
57 '%s://127.0.0.1:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 '%s://domain.org' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 ('%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
|
61 '8080'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 '%s://domain.org:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 ] |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 class TestLibs(unittest.TestCase): |
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 def test_uri_filter(self): |
2109 | 69 from rhodecode.lib.utils2 import uri_filter |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 for url in TEST_URLS: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 self.assertEqual(uri_filter(url[0]), url[1]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 def test_credentials_filter(self): |
2109 | 75 from rhodecode.lib.utils2 import credentials_filter |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 for url in TEST_URLS: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 self.assertEqual(credentials_filter(url[0]), url[2]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 def test_str2bool(self): |
2109 | 81 from rhodecode.lib.utils2 import str2bool |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 test_cases = [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 ('t', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 ('true', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 ('y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 ('yes', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 ('on', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 ('1', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 ('Y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 ('yeS', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 ('Y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 ('TRUE', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 ('T', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 ('False', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 ('F', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 ('FALSE', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 ('0', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 ('-1', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 ('', False), ] |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 for case in test_cases: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 self.assertEqual(str2bool(case[0]), case[1]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1532
diff
changeset
|
104 def test_mention_extractor(self): |
2109 | 105 from rhodecode.lib.utils2 import extract_mentioned_users |
2201
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
106 sample = ( |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
107 "@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
|
108 "@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
|
109 "@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
|
110 "@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
|
111 "user.dot hej ! not-needed maril@domain.org" |
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 |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
114 s = sorted([ |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
115 'first', 'marcink', 'lukaszb', 'one_more22', 'MARCIN', 'maRCiN', 'john', |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
116 'marian.user', 'marco-polo', 'marco_polo' |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
117 ], key=lambda k: k.lower()) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1532
diff
changeset
|
118 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
|
119 |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
120 def test_age(self): |
2371
a05e01144a2c
fixed stupid test condition
Marcin Kuzminski <marcin@python-works.com>
parents:
2317
diff
changeset
|
121 import calendar |
2317
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
122 from rhodecode.lib.utils2 import age |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
123 n = datetime.datetime.now() |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
124 delt = lambda *args, **kwargs: datetime.timedelta(*args, **kwargs) |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
125 self.assertEqual(age(n), u'just now') |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
126 self.assertEqual(age(n - delt(seconds=1)), u'1 second ago') |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
127 self.assertEqual(age(n - delt(seconds=60 * 2)), u'2 minutes ago') |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
128 self.assertEqual(age(n - delt(hours=1)), u'1 hour ago') |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
129 self.assertEqual(age(n - delt(hours=24)), u'1 day ago') |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
130 self.assertEqual(age(n - delt(hours=24 * 5)), u'5 days ago') |
2371
a05e01144a2c
fixed stupid test condition
Marcin Kuzminski <marcin@python-works.com>
parents:
2317
diff
changeset
|
131 self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[n.month-1] + 2))), |
a05e01144a2c
fixed stupid test condition
Marcin Kuzminski <marcin@python-works.com>
parents:
2317
diff
changeset
|
132 u'1 month and 2 days ago') |
2317
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
133 self.assertEqual(age(n - delt(hours=24 * 400)), u'1 year and 1 month ago') |