Show More
@@ -1,222 +1,224 | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | import unittest |
|
3 | 3 | import formencode |
|
4 | 4 | |
|
5 | 5 | from rhodecode.tests import * |
|
6 | 6 | |
|
7 | 7 | from rhodecode.model import validators as v |
|
8 | 8 | from rhodecode.model.users_group import UsersGroupModel |
|
9 | 9 | |
|
10 | 10 | from rhodecode.model.meta import Session |
|
11 | 11 | from rhodecode.model.repos_group import ReposGroupModel |
|
12 | 12 | from rhodecode.config.routing import ADMIN_PREFIX |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | class TestReposGroups(unittest.TestCase): |
|
16 | 16 | |
|
17 | 17 | def setUp(self): |
|
18 | 18 | pass |
|
19 | 19 | |
|
20 | 20 | def tearDown(self): |
|
21 | 21 | pass |
|
22 | 22 | |
|
23 | 23 | def test_Message_extractor(self): |
|
24 | 24 | validator = v.ValidUsername() |
|
25 | 25 | self.assertRaises(formencode.Invalid, validator.to_python, 'default') |
|
26 | 26 | |
|
27 | 27 | class StateObj(object): |
|
28 | 28 | pass |
|
29 | 29 | |
|
30 | 30 | self.assertRaises(formencode.Invalid, |
|
31 | 31 | validator.to_python, 'default', StateObj) |
|
32 | 32 | |
|
33 | 33 | def test_ValidUsername(self): |
|
34 | 34 | validator = v.ValidUsername() |
|
35 | 35 | |
|
36 | 36 | self.assertRaises(formencode.Invalid, validator.to_python, 'default') |
|
37 | 37 | self.assertRaises(formencode.Invalid, validator.to_python, 'new_user') |
|
38 | 38 | self.assertRaises(formencode.Invalid, validator.to_python, '.,') |
|
39 | 39 | self.assertRaises(formencode.Invalid, validator.to_python, |
|
40 | 40 | TEST_USER_ADMIN_LOGIN) |
|
41 | 41 | self.assertEqual('test', validator.to_python('test')) |
|
42 | 42 | |
|
43 | 43 | validator = v.ValidUsername(edit=True, old_data={'user_id': 1}) |
|
44 | 44 | |
|
45 | 45 | def test_ValidRepoUser(self): |
|
46 | 46 | validator = v.ValidRepoUser() |
|
47 | 47 | self.assertRaises(formencode.Invalid, validator.to_python, 'nouser') |
|
48 | 48 | self.assertEqual(TEST_USER_ADMIN_LOGIN, |
|
49 | 49 | validator.to_python(TEST_USER_ADMIN_LOGIN)) |
|
50 | 50 | |
|
51 | 51 | def test_ValidUsersGroup(self): |
|
52 | 52 | validator = v.ValidUsersGroup() |
|
53 | 53 | self.assertRaises(formencode.Invalid, validator.to_python, 'default') |
|
54 | 54 | self.assertRaises(formencode.Invalid, validator.to_python, '.,') |
|
55 | 55 | |
|
56 | 56 | gr = UsersGroupModel().create('test') |
|
57 | 57 | gr2 = UsersGroupModel().create('tes2') |
|
58 | 58 | Session.commit() |
|
59 | 59 | self.assertRaises(formencode.Invalid, validator.to_python, 'test') |
|
60 | 60 | assert gr.users_group_id != None |
|
61 | 61 | validator = v.ValidUsersGroup(edit=True, |
|
62 | 62 | old_data={'users_group_id': |
|
63 | 63 | gr2.users_group_id}) |
|
64 | 64 | |
|
65 | 65 | self.assertRaises(formencode.Invalid, validator.to_python, 'test') |
|
66 | 66 | self.assertRaises(formencode.Invalid, validator.to_python, 'TesT') |
|
67 | 67 | self.assertRaises(formencode.Invalid, validator.to_python, 'TEST') |
|
68 | 68 | UsersGroupModel().delete(gr) |
|
69 | 69 | UsersGroupModel().delete(gr2) |
|
70 | 70 | Session.commit() |
|
71 | 71 | |
|
72 | 72 | def test_ValidReposGroup(self): |
|
73 | 73 | validator = v.ValidReposGroup() |
|
74 | 74 | model = ReposGroupModel() |
|
75 | 75 | self.assertRaises(formencode.Invalid, validator.to_python, |
|
76 | 76 | {'group_name': HG_REPO, }) |
|
77 | 77 | gr = model.create(group_name='test_gr', group_description='desc', |
|
78 | 78 | parent=None, |
|
79 | 79 | just_db=True) |
|
80 | 80 | self.assertRaises(formencode.Invalid, |
|
81 | 81 | validator.to_python, {'group_name': gr.group_name, }) |
|
82 | 82 | |
|
83 | 83 | validator = v.ValidReposGroup(edit=True, |
|
84 | 84 | old_data={'group_id': gr.group_id}) |
|
85 | 85 | self.assertRaises(formencode.Invalid, |
|
86 | 86 | validator.to_python, { |
|
87 | 87 | 'group_name': gr.group_name + 'n', |
|
88 | 88 | 'group_parent_id': gr.group_id |
|
89 | 89 | }) |
|
90 | 90 | model.delete(gr) |
|
91 | 91 | |
|
92 | 92 | def test_ValidPassword(self): |
|
93 | 93 | validator = v.ValidPassword() |
|
94 | 94 | self.assertEqual('lol', validator.to_python('lol')) |
|
95 | 95 | self.assertEqual(None, validator.to_python(None)) |
|
96 | 96 | self.assertRaises(formencode.Invalid, validator.to_python, 'Δ ΔΕΌΕΊ') |
|
97 | 97 | |
|
98 | 98 | def test_ValidPasswordsMatch(self): |
|
99 | 99 | validator = v.ValidPasswordsMatch() |
|
100 | 100 | self.assertRaises(formencode.Invalid, |
|
101 | 101 | validator.to_python, {'password': 'pass', |
|
102 | 102 | 'password_confirmation': 'pass2'}) |
|
103 | 103 | |
|
104 | 104 | self.assertRaises(formencode.Invalid, |
|
105 | 105 | validator.to_python, {'new_password': 'pass', |
|
106 | 106 | 'password_confirmation': 'pass2'}) |
|
107 | 107 | |
|
108 | 108 | self.assertEqual({'new_password': 'pass', |
|
109 | 109 | 'password_confirmation': 'pass'}, |
|
110 | 110 | validator.to_python({'new_password': 'pass', |
|
111 | 111 | 'password_confirmation': 'pass'})) |
|
112 | 112 | |
|
113 | 113 | self.assertEqual({'password': 'pass', |
|
114 | 114 | 'password_confirmation': 'pass'}, |
|
115 | 115 | validator.to_python({'password': 'pass', |
|
116 | 116 | 'password_confirmation': 'pass'})) |
|
117 | 117 | |
|
118 | 118 | def test_ValidAuth(self): |
|
119 | 119 | validator = v.ValidAuth() |
|
120 | 120 | valid_creds = { |
|
121 | 121 | 'username': TEST_USER_REGULAR2_LOGIN, |
|
122 | 122 | 'password': TEST_USER_REGULAR2_PASS, |
|
123 | 123 | } |
|
124 | 124 | invalid_creds = { |
|
125 | 125 | 'username': 'err', |
|
126 | 126 | 'password': 'err', |
|
127 | 127 | } |
|
128 | 128 | self.assertEqual(valid_creds, validator.to_python(valid_creds)) |
|
129 | 129 | self.assertRaises(formencode.Invalid, |
|
130 | 130 | validator.to_python, invalid_creds) |
|
131 | 131 | |
|
132 | 132 | def test_ValidAuthToken(self): |
|
133 | 133 | validator = v.ValidAuthToken() |
|
134 | 134 | # this is untestable without a threadlocal |
|
135 | 135 | # self.assertRaises(formencode.Invalid, |
|
136 | 136 | # validator.to_python, 'BadToken') |
|
137 | 137 | validator |
|
138 | 138 | |
|
139 | 139 | def test_ValidRepoName(self): |
|
140 | 140 | validator = v.ValidRepoName() |
|
141 | 141 | |
|
142 | 142 | self.assertRaises(formencode.Invalid, |
|
143 | 143 | validator.to_python, {'repo_name': ''}) |
|
144 | 144 | |
|
145 | 145 | self.assertRaises(formencode.Invalid, |
|
146 | 146 | validator.to_python, {'repo_name': HG_REPO}) |
|
147 | 147 | |
|
148 | 148 | gr = ReposGroupModel().create(group_name='group_test', |
|
149 | 149 | group_description='desc', |
|
150 | 150 | parent=None,) |
|
151 | 151 | self.assertRaises(formencode.Invalid, |
|
152 | 152 | validator.to_python, {'repo_name': gr.group_name}) |
|
153 | 153 | |
|
154 | 154 | #TODO: write an error case for that ie. create a repo withinh a group |
|
155 | 155 | # self.assertRaises(formencode.Invalid, |
|
156 | 156 | # validator.to_python, {'repo_name': 'some', |
|
157 | 157 | # 'repo_group': gr.group_id}) |
|
158 | 158 | |
|
159 | 159 | def test_ValidForkName(self): |
|
160 | 160 | # this uses ValidRepoName validator |
|
161 | 161 | assert True |
|
162 | 162 | |
|
163 | 163 | @parameterized.expand([ |
|
164 | 164 | ('test', 'test'), ('lolz!', 'lolz'), (' aavv', 'aavv'), |
|
165 | 165 | ('ala ma kota', 'ala-ma-kota'), ('@nooo', 'nooo'), |
|
166 | 166 | ('$!haha lolz !', 'haha-lolz'), ('$$$$$', ''), ('{}OK!', 'OK'), |
|
167 | 167 | ('/]re po', 're-po')]) |
|
168 | 168 | def test_SlugifyName(self, name, expected): |
|
169 | 169 | validator = v.SlugifyName() |
|
170 | 170 | self.assertEqual(expected, validator.to_python(name)) |
|
171 | 171 | |
|
172 | 172 | def test_ValidCloneUri(self): |
|
173 | self.fail('TODO:') | |
|
173 | #TODO: write this one | |
|
174 | pass | |
|
174 | 175 | |
|
175 | 176 | def test_ValidForkType(self): |
|
176 | 177 | validator = v.ValidForkType(old_data={'repo_type': 'hg'}) |
|
177 | 178 | self.assertEqual('hg', validator.to_python('hg')) |
|
178 | 179 | self.assertRaises(formencode.Invalid, validator.to_python, 'git') |
|
179 | 180 | |
|
180 | 181 | def test_ValidPerms(self): |
|
181 | self.fail('TODO:') | |
|
182 | #TODO: write this one | |
|
183 | pass | |
|
182 | 184 | |
|
183 | 185 | def test_ValidSettings(self): |
|
184 | 186 | validator = v.ValidSettings() |
|
185 | 187 | self.assertEqual({'pass': 'pass'}, |
|
186 | 188 | validator.to_python(value={'user': 'test', |
|
187 | 189 | 'pass': 'pass'})) |
|
188 | 190 | |
|
189 | 191 | self.assertEqual({'user2': 'test', 'pass': 'pass'}, |
|
190 | 192 | validator.to_python(value={'user2': 'test', |
|
191 | 193 | 'pass': 'pass'})) |
|
192 | 194 | |
|
193 | 195 | def test_ValidPath(self): |
|
194 | 196 | validator = v.ValidPath() |
|
195 | 197 | self.assertEqual(TESTS_TMP_PATH, |
|
196 | 198 | validator.to_python(TESTS_TMP_PATH)) |
|
197 | 199 | self.assertRaises(formencode.Invalid, validator.to_python, |
|
198 | 200 | '/no_such_dir') |
|
199 | 201 | |
|
200 | 202 | def test_UniqSystemEmail(self): |
|
201 | 203 | validator = v.UniqSystemEmail(old_data={}) |
|
202 | 204 | |
|
203 | 205 | self.assertEqual('mail@python.org', |
|
204 | 206 | validator.to_python('MaiL@Python.org')) |
|
205 | 207 | |
|
206 | 208 | email = TEST_USER_REGULAR2_EMAIL |
|
207 | 209 | self.assertRaises(formencode.Invalid, validator.to_python, email) |
|
208 | 210 | |
|
209 | 211 | def test_ValidSystemEmail(self): |
|
210 | 212 | validator = v.ValidSystemEmail() |
|
211 | 213 | email = TEST_USER_REGULAR2_EMAIL |
|
212 | 214 | |
|
213 | 215 | self.assertEqual(email, validator.to_python(email)) |
|
214 | 216 | self.assertRaises(formencode.Invalid, validator.to_python, 'err') |
|
215 | 217 | |
|
216 | 218 | def test_LdapLibValidator(self): |
|
217 | 219 | validator = v.LdapLibValidator() |
|
218 | 220 | self.assertRaises(v.LdapImportError, validator.to_python, 'err') |
|
219 | 221 | |
|
220 | 222 | def test_AttrLoginValidator(self): |
|
221 | 223 | validator = v.AttrLoginValidator() |
|
222 | 224 | self.assertRaises(formencode.Invalid, validator.to_python, 123) |
General Comments 0
You need to be logged in to leave comments.
Login now