Mercurial > kallithea
annotate rhodecode/tests/test_libs.py @ 3229:aad51f79d040 beta
added a flag for generating pull-request comments, and force display on pull-requests
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 26 Jan 2013 21:21:11 +0100 |
parents | 5ba6249a7afe |
children | 54a439edaf99 |
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/>. |
2790
3c0ae44557c4
more py2.5 compatibility patches
Marcin Kuzminski <marcin@python-works.com>
parents:
2753
diff
changeset
|
25 from __future__ import with_statement |
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 |
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 |
2317
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
30 from rhodecode.tests import * |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 proto = 'http' |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 TEST_URLS = [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 ('%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
|
35 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 ('%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
|
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: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
|
39 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 ('%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
|
41 '%s://127.0.0.1:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 '%s://domain.org' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 ('%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
|
45 '8080'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 '%s://domain.org:8080' % proto), |
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 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 proto = 'https' |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 TEST_URLS += [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 ('%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
|
52 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 ('%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
|
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: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
|
56 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 ('%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
|
58 '%s://127.0.0.1:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 '%s://domain.org' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 ('%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
|
62 '8080'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 '%s://domain.org:8080' % proto), |
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 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 class TestLibs(unittest.TestCase): |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 def test_uri_filter(self): |
2109 | 70 from rhodecode.lib.utils2 import uri_filter |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 for url in TEST_URLS: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 self.assertEqual(uri_filter(url[0]), url[1]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 def test_credentials_filter(self): |
2109 | 76 from rhodecode.lib.utils2 import credentials_filter |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 for url in TEST_URLS: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 self.assertEqual(credentials_filter(url[0]), url[2]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 def test_str2bool(self): |
2109 | 82 from rhodecode.lib.utils2 import str2bool |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 test_cases = [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 ('t', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 ('true', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 ('y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 ('yes', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 ('on', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 ('1', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 ('Y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 ('yeS', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 ('Y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 ('TRUE', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 ('T', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 ('False', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 ('F', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 ('FALSE', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 ('0', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 ('-1', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 ('', False), ] |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 for case in test_cases: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 self.assertEqual(str2bool(case[0]), case[1]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1532
diff
changeset
|
105 def test_mention_extractor(self): |
2109 | 106 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
|
107 sample = ( |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
108 "@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
|
109 "@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
|
110 "@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
|
111 "@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
|
112 "user.dot hej ! not-needed maril@domain.org" |
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 |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
115 s = sorted([ |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
116 'first', 'marcink', 'lukaszb', 'one_more22', 'MARCIN', 'maRCiN', 'john', |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
117 'marian.user', 'marco-polo', 'marco_polo' |
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
118 ], key=lambda k: k.lower()) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1532
diff
changeset
|
119 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
|
120 |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
121 def test_age(self): |
2371
a05e01144a2c
fixed stupid test condition
Marcin Kuzminski <marcin@python-works.com>
parents:
2317
diff
changeset
|
122 import calendar |
2317
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
123 from rhodecode.lib.utils2 import age |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
124 n = datetime.datetime.now() |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
125 delt = lambda *args, **kwargs: datetime.timedelta(*args, **kwargs) |
3132
5ba6249a7afe
fixed bad date calculations
Marcin Kuzminski <marcin@python-works.com>
parents:
2994
diff
changeset
|
126 prev_month = n.month - 1 if n.month != 1 else n.month - 2 |
2317
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
127 self.assertEqual(age(n), u'just now') |
c4d8ed624728
Fixed tests for new i18n changes
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 self.assertEqual(age(n - delt(hours=24 * 5)), u'5 days ago') |
3132
5ba6249a7afe
fixed bad date calculations
Marcin Kuzminski <marcin@python-works.com>
parents:
2994
diff
changeset
|
133 self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[prev_month]))), |
2994
af0d7d8acb22
fixed bad age tests
Marcin Kuzminski <marcin@python-works.com>
parents:
2907
diff
changeset
|
134 u'1 month ago') |
3132
5ba6249a7afe
fixed bad date calculations
Marcin Kuzminski <marcin@python-works.com>
parents:
2994
diff
changeset
|
135 self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[prev_month] + 2))), |
2371
a05e01144a2c
fixed stupid test condition
Marcin Kuzminski <marcin@python-works.com>
parents:
2317
diff
changeset
|
136 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
|
137 self.assertEqual(age(n - delt(hours=24 * 400)), u'1 year and 1 month ago') |
2674
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2371
diff
changeset
|
138 |
2902
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
139 def test_age_in_future(self): |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
140 import calendar |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
141 from rhodecode.lib.utils2 import age |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
142 n = datetime.datetime.now() |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
143 delt = lambda *args, **kwargs: datetime.timedelta(*args, **kwargs) |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
144 self.assertEqual(age(n), u'just now') |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
145 self.assertEqual(age(n + delt(seconds=1)), u'in 1 second') |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
146 self.assertEqual(age(n + delt(seconds=60 * 2)), u'in 2 minutes') |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
147 self.assertEqual(age(n + delt(hours=1)), u'in 1 hour') |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
148 self.assertEqual(age(n + delt(hours=24)), u'in 1 day') |
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
149 self.assertEqual(age(n + delt(hours=24 * 5)), u'in 5 days') |
2994
af0d7d8acb22
fixed bad age tests
Marcin Kuzminski <marcin@python-works.com>
parents:
2907
diff
changeset
|
150 self.assertEqual(age(n + delt(hours=24 * (calendar.mdays[n.month]))), |
af0d7d8acb22
fixed bad age tests
Marcin Kuzminski <marcin@python-works.com>
parents:
2907
diff
changeset
|
151 u'in 1 month') |
af0d7d8acb22
fixed bad age tests
Marcin Kuzminski <marcin@python-works.com>
parents:
2907
diff
changeset
|
152 self.assertEqual(age(n + delt(hours=24 * (calendar.mdays[n.month] + 1))), |
2905
28b85b1b46cf
fixed typo in lib tests
Marcin Kuzminski <marcin@python-works.com>
parents:
2902
diff
changeset
|
153 u'in 1 month and 1 day') |
2902
e2b2791d1e7c
fixed #597 commits in future get negative age.
Marcin Kuzminski <marcin@python-works.com>
parents:
2846
diff
changeset
|
154 self.assertEqual(age(n + delt(hours=24 * 400)), u'in 1 year and 1 month') |
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 ) |
a221706dab50
merged + fixed pull request #62: Implemented metatags and visualisation options.
Marcin Kuzminski <marcin@python-works.com>
parents:
2371
diff
changeset
|
163 from rhodecode.lib.helpers import desc_stylize |
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 => <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): |
e34a6b1eb594
added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
173 from rhodecode.lib.helpers import gravatar_url |
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 |
e34a6b1eb594
added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
176 def fake_conf(**kwargs): |
e34a6b1eb594
added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
177 from pylons import config |
e34a6b1eb594
added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
178 config['app_conf'] = {} |
e34a6b1eb594
added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
179 config['app_conf']['use_gravatar'] = True |
e34a6b1eb594
added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
180 config['app_conf'].update(kwargs) |
e34a6b1eb594
added test for alternative gravatar
Marcin Kuzminski <marcin@python-works.com>
parents:
2674
diff
changeset
|
181 return config |
2836
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
182 |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
183 class fake_url(): |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
184 @classmethod |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
185 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
|
186 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
|
187 |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
188 with mock.patch('pylons.url', fake_url): |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
189 fake = fake_conf(alternative_gravatar_url='http://test.com/{email}') |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
190 with mock.patch('pylons.config', fake): |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
191 from pylons import url |
2846
620669b2a88b
fixed gravatar test typo
Marcin Kuzminski <marcin@python-works.com>
parents:
2836
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
196 fake = fake_conf(alternative_gravatar_url='http://test.com/{email}') |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
197 with mock.patch('pylons.config', fake): |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
198 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
|
199 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
|
200 |
2836
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
201 fake = fake_conf(alternative_gravatar_url='http://test.com/{md5email}') |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
202 with mock.patch('pylons.config', fake): |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 |
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 fake = fake_conf(alternative_gravatar_url='http://test.com/{md5email}/{size}') |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
208 with mock.patch('pylons.config', fake): |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
213 fake = fake_conf(alternative_gravatar_url='{scheme}://{netloc}/{md5email}/{size}') |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
214 with mock.patch('pylons.config', fake): |
819eb7f8a555
Implemented patch from andrewsh ref #565 Add support for {netloc} and {scheme}
Marcin Kuzminski <marcin@python-works.com>
parents:
2790
diff
changeset
|
215 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
|
216 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
|
217 assert grav == 'https://server.com/%s/%s' % (_md5(em), 24) |