Mercurial > kallithea
annotate rhodecode/tests/test_validators.py @ 3206:d4bb8de7382f beta
top menu: show user menu when hovering instead of using js - like other menus
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 23 Jan 2013 20:26:34 +0100 |
parents | 74672d4bdbee |
children | b4daef4cc26d |
rev | line source |
---|---|
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 import unittest |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 import formencode |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 from rhodecode.tests import * |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 from rhodecode.model import validators as v |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 from rhodecode.model.users_group import UsersGroupModel |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 from rhodecode.model.meta import Session |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 from rhodecode.model.repos_group import ReposGroupModel |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 from rhodecode.config.routing import ADMIN_PREFIX |
2898
74672d4bdbee
fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents:
2721
diff
changeset
|
13 from rhodecode.model.db import ChangesetStatus, Repository |
2721
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
14 from rhodecode.model.changeset_status import ChangesetStatusModel |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
15 from rhodecode.model.comment import ChangesetCommentsModel |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 class TestReposGroups(unittest.TestCase): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 def setUp(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 def tearDown(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 def test_Message_extractor(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 validator = v.ValidUsername() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 self.assertRaises(formencode.Invalid, validator.to_python, 'default') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 class StateObj(object): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 validator.to_python, 'default', StateObj) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 def test_ValidUsername(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 validator = v.ValidUsername() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 self.assertRaises(formencode.Invalid, validator.to_python, 'default') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 self.assertRaises(formencode.Invalid, validator.to_python, 'new_user') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 self.assertRaises(formencode.Invalid, validator.to_python, '.,') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 self.assertRaises(formencode.Invalid, validator.to_python, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 TEST_USER_ADMIN_LOGIN) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 self.assertEqual('test', validator.to_python('test')) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 validator = v.ValidUsername(edit=True, old_data={'user_id': 1}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 def test_ValidRepoUser(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 validator = v.ValidRepoUser() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 self.assertRaises(formencode.Invalid, validator.to_python, 'nouser') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 self.assertEqual(TEST_USER_ADMIN_LOGIN, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 validator.to_python(TEST_USER_ADMIN_LOGIN)) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 def test_ValidUsersGroup(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 validator = v.ValidUsersGroup() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 self.assertRaises(formencode.Invalid, validator.to_python, 'default') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 self.assertRaises(formencode.Invalid, validator.to_python, '.,') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 gr = UsersGroupModel().create('test') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 gr2 = UsersGroupModel().create('tes2') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 Session.commit() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 self.assertRaises(formencode.Invalid, validator.to_python, 'test') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 assert gr.users_group_id != None |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 validator = v.ValidUsersGroup(edit=True, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 old_data={'users_group_id': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 gr2.users_group_id}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 self.assertRaises(formencode.Invalid, validator.to_python, 'test') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 self.assertRaises(formencode.Invalid, validator.to_python, 'TesT') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 self.assertRaises(formencode.Invalid, validator.to_python, 'TEST') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 UsersGroupModel().delete(gr) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 UsersGroupModel().delete(gr2) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 Session.commit() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 def test_ValidReposGroup(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 validator = v.ValidReposGroup() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 model = ReposGroupModel() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 self.assertRaises(formencode.Invalid, validator.to_python, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 {'group_name': HG_REPO, }) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 gr = model.create(group_name='test_gr', group_description='desc', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 parent=None, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 just_db=True) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 validator.to_python, {'group_name': gr.group_name, }) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 validator = v.ValidReposGroup(edit=True, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 old_data={'group_id': gr.group_id}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 validator.to_python, { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 'group_name': gr.group_name + 'n', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 'group_parent_id': gr.group_id |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 }) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 model.delete(gr) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 def test_ValidPassword(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 validator = v.ValidPassword() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 self.assertEqual('lol', validator.to_python('lol')) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 self.assertEqual(None, validator.to_python(None)) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 self.assertRaises(formencode.Invalid, validator.to_python, 'ąćżź') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 def test_ValidPasswordsMatch(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 validator = v.ValidPasswordsMatch() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 validator.to_python, {'password': 'pass', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 'password_confirmation': 'pass2'}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 validator.to_python, {'new_password': 'pass', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 'password_confirmation': 'pass2'}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 self.assertEqual({'new_password': 'pass', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
112 'password_confirmation': 'pass'}, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 validator.to_python({'new_password': 'pass', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 'password_confirmation': 'pass'})) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 self.assertEqual({'password': 'pass', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 'password_confirmation': 'pass'}, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 validator.to_python({'password': 'pass', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 'password_confirmation': 'pass'})) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 def test_ValidAuth(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 validator = v.ValidAuth() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 valid_creds = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 'username': TEST_USER_REGULAR2_LOGIN, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 'password': TEST_USER_REGULAR2_PASS, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 invalid_creds = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 'username': 'err', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 'password': 'err', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 self.assertEqual(valid_creds, validator.to_python(valid_creds)) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 validator.to_python, invalid_creds) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 def test_ValidAuthToken(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 validator = v.ValidAuthToken() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 # this is untestable without a threadlocal |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 # self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 # validator.to_python, 'BadToken') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 def test_ValidRepoName(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 validator = v.ValidRepoName() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 validator.to_python, {'repo_name': ''}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
149 validator.to_python, {'repo_name': HG_REPO}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 gr = ReposGroupModel().create(group_name='group_test', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 group_description='desc', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
153 parent=None,) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 validator.to_python, {'repo_name': gr.group_name}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
157 #TODO: write an error case for that ie. create a repo withinh a group |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 # self.assertRaises(formencode.Invalid, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
159 # validator.to_python, {'repo_name': 'some', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 # 'repo_group': gr.group_id}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
161 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 def test_ValidForkName(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 # this uses ValidRepoName validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 assert True |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
166 @parameterized.expand([ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
167 ('test', 'test'), ('lolz!', 'lolz'), (' aavv', 'aavv'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 ('ala ma kota', 'ala-ma-kota'), ('@nooo', 'nooo'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 ('$!haha lolz !', 'haha-lolz'), ('$$$$$', ''), ('{}OK!', 'OK'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 ('/]re po', 're-po')]) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 def test_SlugifyName(self, name, expected): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 validator = v.SlugifyName() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
173 self.assertEqual(expected, validator.to_python(name)) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
175 def test_ValidCloneUri(self): |
2557
1284b2eaade6
skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
176 #TODO: write this one |
1284b2eaade6
skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
177 pass |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
178 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 def test_ValidForkType(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 validator = v.ValidForkType(old_data={'repo_type': 'hg'}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
181 self.assertEqual('hg', validator.to_python('hg')) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 self.assertRaises(formencode.Invalid, validator.to_python, 'git') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
183 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 def test_ValidPerms(self): |
2557
1284b2eaade6
skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
185 #TODO: write this one |
1284b2eaade6
skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
186 pass |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
188 def test_ValidSettings(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 validator = v.ValidSettings() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
190 self.assertEqual({'pass': 'pass'}, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 validator.to_python(value={'user': 'test', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 'pass': 'pass'})) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 self.assertEqual({'user2': 'test', 'pass': 'pass'}, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 validator.to_python(value={'user2': 'test', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
196 'pass': 'pass'})) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 def test_ValidPath(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
199 validator = v.ValidPath() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 self.assertEqual(TESTS_TMP_PATH, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 validator.to_python(TESTS_TMP_PATH)) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 self.assertRaises(formencode.Invalid, validator.to_python, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
203 '/no_such_dir') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
205 def test_UniqSystemEmail(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 validator = v.UniqSystemEmail(old_data={}) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
207 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
208 self.assertEqual('mail@python.org', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
209 validator.to_python('MaiL@Python.org')) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
211 email = TEST_USER_REGULAR2_EMAIL |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
212 self.assertRaises(formencode.Invalid, validator.to_python, email) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
213 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 def test_ValidSystemEmail(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
215 validator = v.ValidSystemEmail() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
216 email = TEST_USER_REGULAR2_EMAIL |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
217 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 self.assertEqual(email, validator.to_python(email)) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
219 self.assertRaises(formencode.Invalid, validator.to_python, 'err') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
220 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
221 def test_LdapLibValidator(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
222 validator = v.LdapLibValidator() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
223 self.assertRaises(v.LdapImportError, validator.to_python, 'err') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
224 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
225 def test_AttrLoginValidator(self): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
226 validator = v.AttrLoginValidator() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
227 self.assertRaises(formencode.Invalid, validator.to_python, 123) |
2721
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
228 |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
229 def test_NotReviewedRevisions(self): |
2898
74672d4bdbee
fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents:
2721
diff
changeset
|
230 repo_id = Repository.get_by_repo_name(HG_REPO).repo_id |
74672d4bdbee
fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents:
2721
diff
changeset
|
231 validator = v.NotReviewedRevisions(repo_id) |
2721
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
232 rev = '0' * 40 |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
233 # add status for a rev, that should throw an error because it is already |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
234 # reviewed |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
235 new_status = ChangesetStatus() |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
236 new_status.author = ChangesetStatusModel()._get_user(TEST_USER_ADMIN_LOGIN) |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
237 new_status.repo = ChangesetStatusModel()._get_repo(HG_REPO) |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
238 new_status.status = ChangesetStatus.STATUS_APPROVED |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
239 new_status.comment = None |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
240 new_status.revision = rev |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
241 Session().add(new_status) |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
242 Session().commit() |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
243 try: |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
244 self.assertRaises(formencode.Invalid, validator.to_python, [rev]) |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
245 finally: |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
246 Session().delete(new_status) |
36915dd4544d
Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents:
2557
diff
changeset
|
247 Session().commit() |