Mercurial > kallithea
annotate rhodecode/tests/test_libs.py @ 1514:87ec80c280bb beta
fixed issues with python2.5
added compat module to rhodecode to have one point of fetching backward incompatible libs.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 07 Oct 2011 02:51:18 +0200 |
parents | df04752daa64 |
children | 2afe9320d5e6 |
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 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :copyright: (c) 2011 by marcink. |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :license: LICENSE_NAME, see LICENSE_FILE for more details. |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 import unittest |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 from rhodecode.tests import * |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 proto = 'http' |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 TEST_URLS = [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 ('%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
|
22 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 ('%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
|
24 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 ('%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
|
26 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 ('%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
|
28 '%s://127.0.0.1:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 '%s://domain.org' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 ('%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
|
32 '8080'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 '%s://domain.org:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 ] |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 proto = 'https' |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 TEST_URLS += [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 ('%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
|
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@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://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
|
43 '%s://127.0.0.1' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 ('%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
|
45 '%s://127.0.0.1:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 ('%s://domain.org' % proto, ['%s://' % proto, 'domain.org'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 '%s://domain.org' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 ('%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
|
49 '8080'], |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 '%s://domain.org:8080' % proto), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 ] |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 class TestLibs(unittest.TestCase): |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 def test_uri_filter(self): |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 from rhodecode.lib import uri_filter |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 for url in TEST_URLS: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 self.assertEqual(uri_filter(url[0]), url[1]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 def test_credentials_filter(self): |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 from rhodecode.lib import credentials_filter |
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 for url in TEST_URLS: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 self.assertEqual(credentials_filter(url[0]), url[2]) |
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 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 def test_str2bool(self): |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 from rhodecode.lib import str2bool |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 test_cases = [ |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 ('t', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 ('true', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 ('y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 ('yes', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 ('on', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 ('1', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 ('Y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 ('yeS', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 ('Y', True), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 ('TRUE', True), |
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 ('False', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 ('F', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 ('FALSE', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 ('0', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 ('-1', False), |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 ('', False), ] |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 for case in test_cases: |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 self.assertEqual(str2bool(case[0]), case[1]) |
fced98787f40
Added tests for RhodeCode libs
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 |