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