Mercurial > kallithea
annotate rhodecode/tests/test_libs.py @ 1566:5539b0eb2cfc beta
webob for beta should not use 1.1.1
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 17 Oct 2011 01:08:29 +0200 |
parents | 2afe9320d5e6 |
children | 54687aa00724 |
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 |
1372
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :created_on: Jun 9, 2011 |
1532
2afe9320d5e6
updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
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 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import unittest |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 from rhodecode.tests import * |
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 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 def test_uri_filter(self): |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 from rhodecode.lib import uri_filter |
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): |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 from rhodecode.lib import credentials_filter |
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 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 def test_str2bool(self): |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 from rhodecode.lib import str2bool |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 test_cases = [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 ('t', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 ('true', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 ('y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 ('yes', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 ('on', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 ('1', 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 ('yeS', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 ('Y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 ('TRUE', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 ('T', True), |
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 ('F', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 ('FALSE', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 ('0', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 ('-1', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 ('', False), ] |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 for case in test_cases: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 self.assertEqual(str2bool(case[0]), case[1]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 |