##// END OF EJS Templates
fixed bug in forms found due to testing,...
marcink -
r728:f1629c0c beta
parent child Browse files
Show More
@@ -1,430 +1,438 b''
1 """ this is forms validation classes
1 """ this is forms validation classes
2 http://formencode.org/module-formencode.validators.html
2 http://formencode.org/module-formencode.validators.html
3 for list off all availible validators
3 for list off all availible validators
4
4
5 we can create our own validators
5 we can create our own validators
6
6
7 The table below outlines the options which can be used in a schema in addition to the validators themselves
7 The table below outlines the options which can be used in a schema in addition to the validators themselves
8 pre_validators [] These validators will be applied before the schema
8 pre_validators [] These validators will be applied before the schema
9 chained_validators [] These validators will be applied after the schema
9 chained_validators [] These validators will be applied after the schema
10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
12 if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value.
12 if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value.
13 ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already
13 ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already
14
14
15
15
16 <name> = formencode.validators.<name of validator>
16 <name> = formencode.validators.<name of validator>
17 <name> must equal form name
17 <name> must equal form name
18 list=[1,2,3,4,5]
18 list=[1,2,3,4,5]
19 for SELECT use formencode.All(OneOf(list), Int())
19 for SELECT use formencode.All(OneOf(list), Int())
20
20
21 """
21 """
22 from formencode import All
22 from formencode import All
23 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \
23 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \
24 Email, Bool, StringBoolean
24 Email, Bool, StringBoolean
25 from pylons import session
25 from pylons import session
26 from pylons.i18n.translation import _
26 from pylons.i18n.translation import _
27 from rhodecode.lib.auth import authfunc, get_crypt_password
27 from rhodecode.lib.auth import authfunc, get_crypt_password
28 from rhodecode.lib.exceptions import LdapImportError
28 from rhodecode.lib.exceptions import LdapImportError
29 from rhodecode.model import meta
29 from rhodecode.model import meta
30 from rhodecode.model.user import UserModel
30 from rhodecode.model.user import UserModel
31 from rhodecode.model.repo import RepoModel
31 from rhodecode.model.repo import RepoModel
32 from rhodecode.model.db import User
32 from rhodecode.model.db import User
33 from webhelpers.pylonslib.secure_form import authentication_token
33 from webhelpers.pylonslib.secure_form import authentication_token
34 from rhodecode import BACKENDS
34 from rhodecode import BACKENDS
35 import formencode
35 import formencode
36 import logging
36 import logging
37 import os
37 import os
38 import rhodecode.lib.helpers as h
38 import rhodecode.lib.helpers as h
39
39
40 log = logging.getLogger(__name__)
40 log = logging.getLogger(__name__)
41
41
42 #this is needed to translate the messages using _() in validators
42 #this is needed to translate the messages using _() in validators
43 class State_obj(object):
43 class State_obj(object):
44 _ = staticmethod(_)
44 _ = staticmethod(_)
45
45
46 #===============================================================================
46 #===============================================================================
47 # VALIDATORS
47 # VALIDATORS
48 #===============================================================================
48 #===============================================================================
49 class ValidAuthToken(formencode.validators.FancyValidator):
49 class ValidAuthToken(formencode.validators.FancyValidator):
50 messages = {'invalid_token':_('Token mismatch')}
50 messages = {'invalid_token':_('Token mismatch')}
51
51
52 def validate_python(self, value, state):
52 def validate_python(self, value, state):
53
53
54 if value != authentication_token():
54 if value != authentication_token():
55 raise formencode.Invalid(self.message('invalid_token', state,
55 raise formencode.Invalid(self.message('invalid_token', state,
56 search_number=value), value, state)
56 search_number=value), value, state)
57
57
58 def ValidUsername(edit, old_data):
58 def ValidUsername(edit, old_data):
59 class _ValidUsername(formencode.validators.FancyValidator):
59 class _ValidUsername(formencode.validators.FancyValidator):
60
60
61 def validate_python(self, value, state):
61 def validate_python(self, value, state):
62 if value in ['default', 'new_user']:
62 if value in ['default', 'new_user']:
63 raise formencode.Invalid(_('Invalid username'), value, state)
63 raise formencode.Invalid(_('Invalid username'), value, state)
64 #check if user is unique
64 #check if user is unique
65 old_un = None
65 old_un = None
66 if edit:
66 if edit:
67 old_un = UserModel().get(old_data.get('user_id')).username
67 old_un = UserModel().get(old_data.get('user_id')).username
68
68
69 if old_un != value or not edit:
69 if old_un != value or not edit:
70 if UserModel().get_by_username(value, cache=False):
70 if UserModel().get_by_username(value, cache=False):
71 raise formencode.Invalid(_('This username already exists') ,
71 raise formencode.Invalid(_('This username already exists') ,
72 value, state)
72 value, state)
73
73
74 return _ValidUsername
74 return _ValidUsername
75
75
76 class ValidPassword(formencode.validators.FancyValidator):
76 class ValidPassword(formencode.validators.FancyValidator):
77
77
78 def to_python(self, value, state):
78 def to_python(self, value, state):
79
79
80 if value:
80 if value:
81
81
82 if value.get('password'):
82 if value.get('password'):
83 try:
83 try:
84 value['password'] = get_crypt_password(value['password'])
84 value['password'] = get_crypt_password(value['password'])
85 except UnicodeEncodeError:
85 except UnicodeEncodeError:
86 e_dict = {'password':_('Invalid characters in password')}
86 e_dict = {'password':_('Invalid characters in password')}
87 raise formencode.Invalid('', value, state, error_dict=e_dict)
87 raise formencode.Invalid('', value, state, error_dict=e_dict)
88
88
89 if value.get('password_confirmation'):
89 if value.get('password_confirmation'):
90 try:
90 try:
91 value['password_confirmation'] = \
91 value['password_confirmation'] = \
92 get_crypt_password(value['password_confirmation'])
92 get_crypt_password(value['password_confirmation'])
93 except UnicodeEncodeError:
93 except UnicodeEncodeError:
94 e_dict = {'password_confirmation':_('Invalid characters in password')}
94 e_dict = {'password_confirmation':_('Invalid characters in password')}
95 raise formencode.Invalid('', value, state, error_dict=e_dict)
95 raise formencode.Invalid('', value, state, error_dict=e_dict)
96
96
97 if value.get('new_password'):
98 try:
99 value['new_password'] = \
100 get_crypt_password(value['new_password'])
101 except UnicodeEncodeError:
102 e_dict = {'new_password':_('Invalid characters in password')}
103 raise formencode.Invalid('', value, state, error_dict=e_dict)
104
97 return value
105 return value
98
106
99 class ValidPasswordsMatch(formencode.validators.FancyValidator):
107 class ValidPasswordsMatch(formencode.validators.FancyValidator):
100
108
101 def validate_python(self, value, state):
109 def validate_python(self, value, state):
102
110
103 if value['password'] != value['password_confirmation']:
111 if value['password'] != value['password_confirmation']:
104 e_dict = {'password_confirmation':
112 e_dict = {'password_confirmation':
105 _('Password do not match')}
113 _('Password do not match')}
106 raise formencode.Invalid('', value, state, error_dict=e_dict)
114 raise formencode.Invalid('', value, state, error_dict=e_dict)
107
115
108 class ValidAuth(formencode.validators.FancyValidator):
116 class ValidAuth(formencode.validators.FancyValidator):
109 messages = {
117 messages = {
110 'invalid_password':_('invalid password'),
118 'invalid_password':_('invalid password'),
111 'invalid_login':_('invalid user name'),
119 'invalid_login':_('invalid user name'),
112 'disabled_account':_('Your account is disabled')
120 'disabled_account':_('Your account is disabled')
113
121
114 }
122 }
115 #error mapping
123 #error mapping
116 e_dict = {'username':messages['invalid_login'],
124 e_dict = {'username':messages['invalid_login'],
117 'password':messages['invalid_password']}
125 'password':messages['invalid_password']}
118 e_dict_disable = {'username':messages['disabled_account']}
126 e_dict_disable = {'username':messages['disabled_account']}
119
127
120 def validate_python(self, value, state):
128 def validate_python(self, value, state):
121 password = value['password']
129 password = value['password']
122 username = value['username']
130 username = value['username']
123 user = UserModel().get_by_username(username)
131 user = UserModel().get_by_username(username)
124
132
125 if authfunc(None, username, password):
133 if authfunc(None, username, password):
126 return value
134 return value
127 else:
135 else:
128 if user and user.active is False:
136 if user and user.active is False:
129 log.warning('user %s is disabled', username)
137 log.warning('user %s is disabled', username)
130 raise formencode.Invalid(self.message('disabled_account',
138 raise formencode.Invalid(self.message('disabled_account',
131 state=State_obj),
139 state=State_obj),
132 value, state,
140 value, state,
133 error_dict=self.e_dict_disable)
141 error_dict=self.e_dict_disable)
134 else:
142 else:
135 log.warning('user %s not authenticated', username)
143 log.warning('user %s not authenticated', username)
136 raise formencode.Invalid(self.message('invalid_password',
144 raise formencode.Invalid(self.message('invalid_password',
137 state=State_obj), value, state,
145 state=State_obj), value, state,
138 error_dict=self.e_dict)
146 error_dict=self.e_dict)
139
147
140 class ValidRepoUser(formencode.validators.FancyValidator):
148 class ValidRepoUser(formencode.validators.FancyValidator):
141
149
142 def to_python(self, value, state):
150 def to_python(self, value, state):
143 sa = meta.Session()
151 sa = meta.Session()
144 try:
152 try:
145 self.user_db = sa.query(User)\
153 self.user_db = sa.query(User)\
146 .filter(User.active == True)\
154 .filter(User.active == True)\
147 .filter(User.username == value).one()
155 .filter(User.username == value).one()
148 except Exception:
156 except Exception:
149 raise formencode.Invalid(_('This username is not valid'),
157 raise formencode.Invalid(_('This username is not valid'),
150 value, state)
158 value, state)
151 finally:
159 finally:
152 meta.Session.remove()
160 meta.Session.remove()
153
161
154 return self.user_db.user_id
162 return self.user_db.user_id
155
163
156 def ValidRepoName(edit, old_data):
164 def ValidRepoName(edit, old_data):
157 class _ValidRepoName(formencode.validators.FancyValidator):
165 class _ValidRepoName(formencode.validators.FancyValidator):
158
166
159 def to_python(self, value, state):
167 def to_python(self, value, state):
160 slug = h.repo_name_slug(value)
168 slug = h.repo_name_slug(value)
161 if slug in ['_admin']:
169 if slug in ['_admin']:
162 raise formencode.Invalid(_('This repository name is disallowed'),
170 raise formencode.Invalid(_('This repository name is disallowed'),
163 value, state)
171 value, state)
164 if old_data.get('repo_name') != value or not edit:
172 if old_data.get('repo_name') != value or not edit:
165 if RepoModel().get(slug, cache=False):
173 if RepoModel().get(slug, cache=False):
166 raise formencode.Invalid(_('This repository already exists') ,
174 raise formencode.Invalid(_('This repository already exists') ,
167 value, state)
175 value, state)
168 return slug
176 return slug
169
177
170
178
171 return _ValidRepoName
179 return _ValidRepoName
172
180
173 def ValidForkType(old_data):
181 def ValidForkType(old_data):
174 class _ValidForkType(formencode.validators.FancyValidator):
182 class _ValidForkType(formencode.validators.FancyValidator):
175
183
176 def to_python(self, value, state):
184 def to_python(self, value, state):
177 if old_data['repo_type'] != value:
185 if old_data['repo_type'] != value:
178 raise formencode.Invalid(_('Fork have to be the same type as original'), value, state)
186 raise formencode.Invalid(_('Fork have to be the same type as original'), value, state)
179 return value
187 return value
180 return _ValidForkType
188 return _ValidForkType
181
189
182 class ValidPerms(formencode.validators.FancyValidator):
190 class ValidPerms(formencode.validators.FancyValidator):
183 messages = {'perm_new_user_name':_('This username is not valid')}
191 messages = {'perm_new_user_name':_('This username is not valid')}
184
192
185 def to_python(self, value, state):
193 def to_python(self, value, state):
186 perms_update = []
194 perms_update = []
187 perms_new = []
195 perms_new = []
188 #build a list of permission to update and new permission to create
196 #build a list of permission to update and new permission to create
189 for k, v in value.items():
197 for k, v in value.items():
190 if k.startswith('perm_'):
198 if k.startswith('perm_'):
191 if k.startswith('perm_new_user'):
199 if k.startswith('perm_new_user'):
192 new_perm = value.get('perm_new_user', False)
200 new_perm = value.get('perm_new_user', False)
193 new_user = value.get('perm_new_user_name', False)
201 new_user = value.get('perm_new_user_name', False)
194 if new_user and new_perm:
202 if new_user and new_perm:
195 if (new_user, new_perm) not in perms_new:
203 if (new_user, new_perm) not in perms_new:
196 perms_new.append((new_user, new_perm))
204 perms_new.append((new_user, new_perm))
197 else:
205 else:
198 usr = k[5:]
206 usr = k[5:]
199 if usr == 'default':
207 if usr == 'default':
200 if value['private']:
208 if value['private']:
201 #set none for default when updating to private repo
209 #set none for default when updating to private repo
202 v = 'repository.none'
210 v = 'repository.none'
203 perms_update.append((usr, v))
211 perms_update.append((usr, v))
204 value['perms_updates'] = perms_update
212 value['perms_updates'] = perms_update
205 value['perms_new'] = perms_new
213 value['perms_new'] = perms_new
206 sa = meta.Session
214 sa = meta.Session
207 for k, v in perms_new:
215 for k, v in perms_new:
208 try:
216 try:
209 self.user_db = sa.query(User)\
217 self.user_db = sa.query(User)\
210 .filter(User.active == True)\
218 .filter(User.active == True)\
211 .filter(User.username == k).one()
219 .filter(User.username == k).one()
212 except Exception:
220 except Exception:
213 msg = self.message('perm_new_user_name',
221 msg = self.message('perm_new_user_name',
214 state=State_obj)
222 state=State_obj)
215 raise formencode.Invalid(msg, value, state, error_dict={'perm_new_user_name':msg})
223 raise formencode.Invalid(msg, value, state, error_dict={'perm_new_user_name':msg})
216 return value
224 return value
217
225
218 class ValidSettings(formencode.validators.FancyValidator):
226 class ValidSettings(formencode.validators.FancyValidator):
219
227
220 def to_python(self, value, state):
228 def to_python(self, value, state):
221 #settings form can't edit user
229 #settings form can't edit user
222 if value.has_key('user'):
230 if value.has_key('user'):
223 del['value']['user']
231 del['value']['user']
224
232
225 return value
233 return value
226
234
227 class ValidPath(formencode.validators.FancyValidator):
235 class ValidPath(formencode.validators.FancyValidator):
228 def to_python(self, value, state):
236 def to_python(self, value, state):
229
237
230 if not os.path.isdir(value):
238 if not os.path.isdir(value):
231 msg = _('This is not a valid path')
239 msg = _('This is not a valid path')
232 raise formencode.Invalid(msg, value, state,
240 raise formencode.Invalid(msg, value, state,
233 error_dict={'paths_root_path':msg})
241 error_dict={'paths_root_path':msg})
234 return value
242 return value
235
243
236 def UniqSystemEmail(old_data):
244 def UniqSystemEmail(old_data):
237 class _UniqSystemEmail(formencode.validators.FancyValidator):
245 class _UniqSystemEmail(formencode.validators.FancyValidator):
238 def to_python(self, value, state):
246 def to_python(self, value, state):
239 if old_data.get('email') != value:
247 if old_data.get('email') != value:
240 sa = meta.Session()
248 sa = meta.Session()
241 try:
249 try:
242 user = sa.query(User).filter(User.email == value).scalar()
250 user = sa.query(User).filter(User.email == value).scalar()
243 if user:
251 if user:
244 raise formencode.Invalid(_("That e-mail address is already taken") ,
252 raise formencode.Invalid(_("That e-mail address is already taken") ,
245 value, state)
253 value, state)
246 finally:
254 finally:
247 meta.Session.remove()
255 meta.Session.remove()
248
256
249 return value
257 return value
250
258
251 return _UniqSystemEmail
259 return _UniqSystemEmail
252
260
253 class ValidSystemEmail(formencode.validators.FancyValidator):
261 class ValidSystemEmail(formencode.validators.FancyValidator):
254 def to_python(self, value, state):
262 def to_python(self, value, state):
255 sa = meta.Session
263 sa = meta.Session
256 try:
264 try:
257 user = sa.query(User).filter(User.email == value).scalar()
265 user = sa.query(User).filter(User.email == value).scalar()
258 if user is None:
266 if user is None:
259 raise formencode.Invalid(_("That e-mail address doesn't exist.") ,
267 raise formencode.Invalid(_("That e-mail address doesn't exist.") ,
260 value, state)
268 value, state)
261 finally:
269 finally:
262 meta.Session.remove()
270 meta.Session.remove()
263
271
264 return value
272 return value
265
273
266 class LdapLibValidator(formencode.validators.FancyValidator):
274 class LdapLibValidator(formencode.validators.FancyValidator):
267
275
268 def to_python(self, value, state):
276 def to_python(self, value, state):
269
277
270 try:
278 try:
271 import ldap
279 import ldap
272 except ImportError:
280 except ImportError:
273 raise LdapImportError
281 raise LdapImportError
274 return value
282 return value
275
283
276 #===============================================================================
284 #===============================================================================
277 # FORMS
285 # FORMS
278 #===============================================================================
286 #===============================================================================
279 class LoginForm(formencode.Schema):
287 class LoginForm(formencode.Schema):
280 allow_extra_fields = True
288 allow_extra_fields = True
281 filter_extra_fields = True
289 filter_extra_fields = True
282 username = UnicodeString(
290 username = UnicodeString(
283 strip=True,
291 strip=True,
284 min=1,
292 min=1,
285 not_empty=True,
293 not_empty=True,
286 messages={
294 messages={
287 'empty':_('Please enter a login'),
295 'empty':_('Please enter a login'),
288 'tooShort':_('Enter a value %(min)i characters long or more')}
296 'tooShort':_('Enter a value %(min)i characters long or more')}
289 )
297 )
290
298
291 password = UnicodeString(
299 password = UnicodeString(
292 strip=True,
300 strip=True,
293 min=6,
301 min=6,
294 not_empty=True,
302 not_empty=True,
295 messages={
303 messages={
296 'empty':_('Please enter a password'),
304 'empty':_('Please enter a password'),
297 'tooShort':_('Enter %(min)i characters or more')}
305 'tooShort':_('Enter %(min)i characters or more')}
298 )
306 )
299
307
300
308
301 #chained validators have access to all data
309 #chained validators have access to all data
302 chained_validators = [ValidAuth]
310 chained_validators = [ValidAuth]
303
311
304 def UserForm(edit=False, old_data={}):
312 def UserForm(edit=False, old_data={}):
305 class _UserForm(formencode.Schema):
313 class _UserForm(formencode.Schema):
306 allow_extra_fields = True
314 allow_extra_fields = True
307 filter_extra_fields = True
315 filter_extra_fields = True
308 username = All(UnicodeString(strip=True, min=1, not_empty=True), ValidUsername(edit, old_data))
316 username = All(UnicodeString(strip=True, min=1, not_empty=True), ValidUsername(edit, old_data))
309 if edit:
317 if edit:
310 new_password = All(UnicodeString(strip=True, min=6, not_empty=False))
318 new_password = All(UnicodeString(strip=True, min=6, not_empty=False))
311 admin = StringBoolean(if_missing=False)
319 admin = StringBoolean(if_missing=False)
312 else:
320 else:
313 password = All(UnicodeString(strip=True, min=6, not_empty=True))
321 password = All(UnicodeString(strip=True, min=6, not_empty=True))
314 active = StringBoolean(if_missing=False)
322 active = StringBoolean(if_missing=False)
315 name = UnicodeString(strip=True, min=1, not_empty=True)
323 name = UnicodeString(strip=True, min=1, not_empty=True)
316 lastname = UnicodeString(strip=True, min=1, not_empty=True)
324 lastname = UnicodeString(strip=True, min=1, not_empty=True)
317 email = All(Email(not_empty=True), UniqSystemEmail(old_data))
325 email = All(Email(not_empty=True), UniqSystemEmail(old_data))
318
326
319 chained_validators = [ValidPassword]
327 chained_validators = [ValidPassword]
320
328
321 return _UserForm
329 return _UserForm
322
330
323 def RegisterForm(edit=False, old_data={}):
331 def RegisterForm(edit=False, old_data={}):
324 class _RegisterForm(formencode.Schema):
332 class _RegisterForm(formencode.Schema):
325 allow_extra_fields = True
333 allow_extra_fields = True
326 filter_extra_fields = True
334 filter_extra_fields = True
327 username = All(ValidUsername(edit, old_data), UnicodeString(strip=True, min=1, not_empty=True))
335 username = All(ValidUsername(edit, old_data), UnicodeString(strip=True, min=1, not_empty=True))
328 password = All(UnicodeString(strip=True, min=6, not_empty=True))
336 password = All(UnicodeString(strip=True, min=6, not_empty=True))
329 password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=True))
337 password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=True))
330 active = StringBoolean(if_missing=False)
338 active = StringBoolean(if_missing=False)
331 name = UnicodeString(strip=True, min=1, not_empty=True)
339 name = UnicodeString(strip=True, min=1, not_empty=True)
332 lastname = UnicodeString(strip=True, min=1, not_empty=True)
340 lastname = UnicodeString(strip=True, min=1, not_empty=True)
333 email = All(Email(not_empty=True), UniqSystemEmail(old_data))
341 email = All(Email(not_empty=True), UniqSystemEmail(old_data))
334
342
335 chained_validators = [ValidPasswordsMatch, ValidPassword]
343 chained_validators = [ValidPasswordsMatch, ValidPassword]
336
344
337 return _RegisterForm
345 return _RegisterForm
338
346
339 def PasswordResetForm():
347 def PasswordResetForm():
340 class _PasswordResetForm(formencode.Schema):
348 class _PasswordResetForm(formencode.Schema):
341 allow_extra_fields = True
349 allow_extra_fields = True
342 filter_extra_fields = True
350 filter_extra_fields = True
343 email = All(ValidSystemEmail(), Email(not_empty=True))
351 email = All(ValidSystemEmail(), Email(not_empty=True))
344 return _PasswordResetForm
352 return _PasswordResetForm
345
353
346 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
354 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
347 class _RepoForm(formencode.Schema):
355 class _RepoForm(formencode.Schema):
348 allow_extra_fields = True
356 allow_extra_fields = True
349 filter_extra_fields = False
357 filter_extra_fields = False
350 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
358 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
351 description = UnicodeString(strip=True, min=1, not_empty=True)
359 description = UnicodeString(strip=True, min=1, not_empty=True)
352 private = StringBoolean(if_missing=False)
360 private = StringBoolean(if_missing=False)
353 repo_type = OneOf(supported_backends)
361 repo_type = OneOf(supported_backends)
354 if edit:
362 if edit:
355 user = All(Int(not_empty=True), ValidRepoUser)
363 user = All(Int(not_empty=True), ValidRepoUser)
356
364
357 chained_validators = [ValidPerms]
365 chained_validators = [ValidPerms]
358 return _RepoForm
366 return _RepoForm
359
367
360 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
368 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
361 class _RepoForkForm(formencode.Schema):
369 class _RepoForkForm(formencode.Schema):
362 allow_extra_fields = True
370 allow_extra_fields = True
363 filter_extra_fields = False
371 filter_extra_fields = False
364 fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
372 fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
365 description = UnicodeString(strip=True, min=1, not_empty=True)
373 description = UnicodeString(strip=True, min=1, not_empty=True)
366 private = StringBoolean(if_missing=False)
374 private = StringBoolean(if_missing=False)
367 repo_type = All(ValidForkType(old_data), OneOf(supported_backends))
375 repo_type = All(ValidForkType(old_data), OneOf(supported_backends))
368 return _RepoForkForm
376 return _RepoForkForm
369
377
370 def RepoSettingsForm(edit=False, old_data={}):
378 def RepoSettingsForm(edit=False, old_data={}):
371 class _RepoForm(formencode.Schema):
379 class _RepoForm(formencode.Schema):
372 allow_extra_fields = True
380 allow_extra_fields = True
373 filter_extra_fields = False
381 filter_extra_fields = False
374 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
382 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
375 description = UnicodeString(strip=True, min=1, not_empty=True)
383 description = UnicodeString(strip=True, min=1, not_empty=True)
376 private = StringBoolean(if_missing=False)
384 private = StringBoolean(if_missing=False)
377
385
378 chained_validators = [ValidPerms, ValidSettings]
386 chained_validators = [ValidPerms, ValidSettings]
379 return _RepoForm
387 return _RepoForm
380
388
381
389
382 def ApplicationSettingsForm():
390 def ApplicationSettingsForm():
383 class _ApplicationSettingsForm(formencode.Schema):
391 class _ApplicationSettingsForm(formencode.Schema):
384 allow_extra_fields = True
392 allow_extra_fields = True
385 filter_extra_fields = False
393 filter_extra_fields = False
386 rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True)
394 rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True)
387 rhodecode_realm = UnicodeString(strip=True, min=1, not_empty=True)
395 rhodecode_realm = UnicodeString(strip=True, min=1, not_empty=True)
388
396
389 return _ApplicationSettingsForm
397 return _ApplicationSettingsForm
390
398
391 def ApplicationUiSettingsForm():
399 def ApplicationUiSettingsForm():
392 class _ApplicationUiSettingsForm(formencode.Schema):
400 class _ApplicationUiSettingsForm(formencode.Schema):
393 allow_extra_fields = True
401 allow_extra_fields = True
394 filter_extra_fields = False
402 filter_extra_fields = False
395 web_push_ssl = OneOf(['true', 'false'], if_missing='false')
403 web_push_ssl = OneOf(['true', 'false'], if_missing='false')
396 paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=1, not_empty=True))
404 paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=1, not_empty=True))
397 hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False)
405 hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False)
398 hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False)
406 hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False)
399 hooks_pretxnchangegroup_push_logger = OneOf(['True', 'False'], if_missing=False)
407 hooks_pretxnchangegroup_push_logger = OneOf(['True', 'False'], if_missing=False)
400 hooks_preoutgoing_pull_logger = OneOf(['True', 'False'], if_missing=False)
408 hooks_preoutgoing_pull_logger = OneOf(['True', 'False'], if_missing=False)
401
409
402 return _ApplicationUiSettingsForm
410 return _ApplicationUiSettingsForm
403
411
404 def DefaultPermissionsForm(perms_choices, register_choices, create_choices):
412 def DefaultPermissionsForm(perms_choices, register_choices, create_choices):
405 class _DefaultPermissionsForm(formencode.Schema):
413 class _DefaultPermissionsForm(formencode.Schema):
406 allow_extra_fields = True
414 allow_extra_fields = True
407 filter_extra_fields = True
415 filter_extra_fields = True
408 overwrite_default = StringBoolean(if_missing=False)
416 overwrite_default = StringBoolean(if_missing=False)
409 anonymous = OneOf(['True', 'False'], if_missing=False)
417 anonymous = OneOf(['True', 'False'], if_missing=False)
410 default_perm = OneOf(perms_choices)
418 default_perm = OneOf(perms_choices)
411 default_register = OneOf(register_choices)
419 default_register = OneOf(register_choices)
412 default_create = OneOf(create_choices)
420 default_create = OneOf(create_choices)
413
421
414 return _DefaultPermissionsForm
422 return _DefaultPermissionsForm
415
423
416
424
417 def LdapSettingsForm():
425 def LdapSettingsForm():
418 class _LdapSettingsForm(formencode.Schema):
426 class _LdapSettingsForm(formencode.Schema):
419 allow_extra_fields = True
427 allow_extra_fields = True
420 filter_extra_fields = True
428 filter_extra_fields = True
421 pre_validators = [LdapLibValidator]
429 pre_validators = [LdapLibValidator]
422 ldap_active = StringBoolean(if_missing=False)
430 ldap_active = StringBoolean(if_missing=False)
423 ldap_host = UnicodeString(strip=True,)
431 ldap_host = UnicodeString(strip=True,)
424 ldap_port = Number(strip=True,)
432 ldap_port = Number(strip=True,)
425 ldap_ldaps = StringBoolean(if_missing=False)
433 ldap_ldaps = StringBoolean(if_missing=False)
426 ldap_dn_user = UnicodeString(strip=True,)
434 ldap_dn_user = UnicodeString(strip=True,)
427 ldap_dn_pass = UnicodeString(strip=True,)
435 ldap_dn_pass = UnicodeString(strip=True,)
428 ldap_base_dn = UnicodeString(strip=True,)
436 ldap_base_dn = UnicodeString(strip=True,)
429
437
430 return _LdapSettingsForm
438 return _LdapSettingsForm
@@ -1,130 +1,131 b''
1 from rhodecode.model.db import Repository
1 from rhodecode.model.db import Repository
2 from rhodecode.tests import *
2 from rhodecode.tests import *
3
3
4 class TestAdminReposController(TestController):
4 class TestAdminReposController(TestController):
5
5
6 def test_index(self):
6 def test_index(self):
7 self.log_user()
7 self.log_user()
8 response = self.app.get(url('repos'))
8 response = self.app.get(url('repos'))
9 # Test response...
9 # Test response...
10
10
11 def test_index_as_xml(self):
11 def test_index_as_xml(self):
12 response = self.app.get(url('formatted_repos', format='xml'))
12 response = self.app.get(url('formatted_repos', format='xml'))
13
13
14 def test_create_hg(self):
14 def test_create_hg(self):
15 self.log_user()
15 self.log_user()
16 repo_name = NEW_HG_REPO
16 repo_name = NEW_HG_REPO
17 description = 'description for newly created repo'
17 description = 'description for newly created repo'
18 private = False
18 private = False
19 response = self.app.post(url('repos'), {'repo_name':repo_name,
19 response = self.app.post(url('repos'), {'repo_name':repo_name,
20 'repo_type':'hg',
20 'repo_type':'hg',
21 'description':description,
21 'description':description,
22 'private':private})
22 'private':private})
23
23
24
24
25 #test if we have a message for that repository
25 #test if we have a message for that repository
26 assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo'
26 assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo'
27
27
28 #test if the fork was created in the database
28 #test if the fork was created in the database
29 new_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).one()
29 new_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).one()
30
30
31 assert new_repo.repo_name == repo_name, 'wrong name of repo name in db'
31 assert new_repo.repo_name == repo_name, 'wrong name of repo name in db'
32 assert new_repo.description == description, 'wrong description'
32 assert new_repo.description == description, 'wrong description'
33
33
34 #test if repository is visible in the list ?
34 #test if repository is visible in the list ?
35 response = response.follow()
35 response = response.follow()
36
36
37 assert repo_name in response.body, 'missing new repo from the main repos list'
37 assert repo_name in response.body, 'missing new repo from the main repos list'
38
38
39 def test_create_git(self):
39 def test_create_git(self):
40 return
40 self.log_user()
41 self.log_user()
41 repo_name = NEW_GIT_REPO
42 repo_name = NEW_GIT_REPO
42 description = 'description for newly created repo'
43 description = 'description for newly created repo'
43 private = False
44 private = False
44 response = self.app.post(url('repos'), {'repo_name':repo_name,
45 response = self.app.post(url('repos'), {'repo_name':repo_name,
45 'repo_type':'git',
46 'repo_type':'git',
46 'description':description,
47 'description':description,
47 'private':private})
48 'private':private})
48
49
49
50
50 #test if we have a message for that repository
51 #test if we have a message for that repository
51 assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo'
52 assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo'
52
53
53 #test if the fork was created in the database
54 #test if the fork was created in the database
54 new_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).one()
55 new_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).one()
55
56
56 assert new_repo.repo_name == repo_name, 'wrong name of repo name in db'
57 assert new_repo.repo_name == repo_name, 'wrong name of repo name in db'
57 assert new_repo.description == description, 'wrong description'
58 assert new_repo.description == description, 'wrong description'
58
59
59 #test if repository is visible in the list ?
60 #test if repository is visible in the list ?
60 response = response.follow()
61 response = response.follow()
61
62
62 assert repo_name in response.body, 'missing new repo from the main repos list'
63 assert repo_name in response.body, 'missing new repo from the main repos list'
63
64
64
65
65 def test_new(self):
66 def test_new(self):
66 self.log_user()
67 self.log_user()
67 response = self.app.get(url('new_repo'))
68 response = self.app.get(url('new_repo'))
68
69
69 def test_new_as_xml(self):
70 def test_new_as_xml(self):
70 response = self.app.get(url('formatted_new_repo', format='xml'))
71 response = self.app.get(url('formatted_new_repo', format='xml'))
71
72
72 def test_update(self):
73 def test_update(self):
73 response = self.app.put(url('repo', repo_name=HG_REPO))
74 response = self.app.put(url('repo', repo_name=HG_REPO))
74
75
75 def test_update_browser_fakeout(self):
76 def test_update_browser_fakeout(self):
76 response = self.app.post(url('repo', repo_name=HG_REPO), params=dict(_method='put'))
77 response = self.app.post(url('repo', repo_name=HG_REPO), params=dict(_method='put'))
77
78
78 def test_delete(self):
79 def test_delete(self):
79 self.log_user()
80 self.log_user()
80 repo_name = 'vcs_test_new_to_delete'
81 repo_name = 'vcs_test_new_to_delete'
81 description = 'description for newly created repo'
82 description = 'description for newly created repo'
82 private = False
83 private = False
83 response = self.app.post(url('repos'), {'repo_name':repo_name,
84 response = self.app.post(url('repos'), {'repo_name':repo_name,
84 'repo_type':'hg',
85 'repo_type':'hg',
85 'description':description,
86 'description':description,
86 'private':private})
87 'private':private})
87
88
88
89
89 #test if we have a message for that repository
90 #test if we have a message for that repository
90 assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo'
91 assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo'
91
92
92 #test if the repo was created in the database
93 #test if the repo was created in the database
93 new_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).one()
94 new_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).one()
94
95
95 assert new_repo.repo_name == repo_name, 'wrong name of repo name in db'
96 assert new_repo.repo_name == repo_name, 'wrong name of repo name in db'
96 assert new_repo.description == description, 'wrong description'
97 assert new_repo.description == description, 'wrong description'
97
98
98 #test if repository is visible in the list ?
99 #test if repository is visible in the list ?
99 response = response.follow()
100 response = response.follow()
100
101
101 assert repo_name in response.body, 'missing new repo from the main repos list'
102 assert repo_name in response.body, 'missing new repo from the main repos list'
102
103
103
104
104 response = self.app.delete(url('repo', repo_name=repo_name))
105 response = self.app.delete(url('repo', repo_name=repo_name))
105
106
106 assert '''deleted repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about delete repo'
107 assert '''deleted repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about delete repo'
107
108
108 response.follow()
109 response.follow()
109
110
110 #check if repo was deleted from db
111 #check if repo was deleted from db
111 deleted_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).scalar()
112 deleted_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).scalar()
112
113
113 assert deleted_repo is None, 'Deleted repository was found in db'
114 assert deleted_repo is None, 'Deleted repository was found in db'
114
115
115
116
116 def test_delete_browser_fakeout(self):
117 def test_delete_browser_fakeout(self):
117 response = self.app.post(url('repo', repo_name=HG_REPO), params=dict(_method='delete'))
118 response = self.app.post(url('repo', repo_name=HG_REPO), params=dict(_method='delete'))
118
119
119 def test_show(self):
120 def test_show(self):
120 self.log_user()
121 self.log_user()
121 response = self.app.get(url('repo', repo_name=HG_REPO))
122 response = self.app.get(url('repo', repo_name=HG_REPO))
122
123
123 def test_show_as_xml(self):
124 def test_show_as_xml(self):
124 response = self.app.get(url('formatted_repo', repo_name=HG_REPO, format='xml'))
125 response = self.app.get(url('formatted_repo', repo_name=HG_REPO, format='xml'))
125
126
126 def test_edit(self):
127 def test_edit(self):
127 response = self.app.get(url('edit_repo', repo_name=HG_REPO))
128 response = self.app.get(url('edit_repo', repo_name=HG_REPO))
128
129
129 def test_edit_as_xml(self):
130 def test_edit_as_xml(self):
130 response = self.app.get(url('formatted_edit_repo', repo_name=HG_REPO, format='xml'))
131 response = self.app.get(url('formatted_edit_repo', repo_name=HG_REPO, format='xml'))
@@ -1,175 +1,178 b''
1 # -*- coding: utf-8 -*-
1 from rhodecode.tests import *
2 from rhodecode.tests import *
2 from rhodecode.model.db import User
3 from rhodecode.model.db import User
3 from rhodecode.lib.auth import check_password
4 from rhodecode.lib.auth import check_password
4
5
5
6
6 class TestLoginController(TestController):
7 class TestLoginController(TestController):
7
8
8 def test_index(self):
9 def test_index(self):
9 response = self.app.get(url(controller='login', action='index'))
10 response = self.app.get(url(controller='login', action='index'))
10 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
11 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
11 # Test response...
12 # Test response...
12
13
13 def test_login_admin_ok(self):
14 def test_login_admin_ok(self):
14 response = self.app.post(url(controller='login', action='index'),
15 response = self.app.post(url(controller='login', action='index'),
15 {'username':'test_admin',
16 {'username':'test_admin',
16 'password':'test12'})
17 'password':'test12'})
17 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
18 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
18 assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user'
19 assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user'
19 response = response.follow()
20 response = response.follow()
20 assert '%s repository' % HG_REPO in response.body
21 assert '%s repository' % HG_REPO in response.body
21
22
22 def test_login_regular_ok(self):
23 def test_login_regular_ok(self):
23 response = self.app.post(url(controller='login', action='index'),
24 response = self.app.post(url(controller='login', action='index'),
24 {'username':'test_regular',
25 {'username':'test_regular',
25 'password':'test12'})
26 'password':'test12'})
26 print response
27 print response
27 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
28 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
28 assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user'
29 assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user'
29 response = response.follow()
30 response = response.follow()
30 assert '%s repository' % HG_REPO in response.body
31 assert '%s repository' % HG_REPO in response.body
31 assert '<a title="Admin" href="/_admin">' not in response.body
32 assert '<a title="Admin" href="/_admin">' not in response.body
32
33
33 def test_login_ok_came_from(self):
34 def test_login_ok_came_from(self):
34 test_came_from = '/_admin/users'
35 test_came_from = '/_admin/users'
35 response = self.app.post(url(controller='login', action='index', came_from=test_came_from),
36 response = self.app.post(url(controller='login', action='index', came_from=test_came_from),
36 {'username':'test_admin',
37 {'username':'test_admin',
37 'password':'test12'})
38 'password':'test12'})
38 assert response.status == '302 Found', 'Wrong response code from came from redirection'
39 assert response.status == '302 Found', 'Wrong response code from came from redirection'
39 response = response.follow()
40 response = response.follow()
40
41
41 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
42 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
42 assert 'Users administration' in response.body, 'No proper title in response'
43 assert 'Users administration' in response.body, 'No proper title in response'
43
44
44
45
45 def test_login_short_password(self):
46 def test_login_short_password(self):
46 response = self.app.post(url(controller='login', action='index'),
47 response = self.app.post(url(controller='login', action='index'),
47 {'username':'error',
48 {'username':'error',
48 'password':'test'})
49 'password':'test'})
49 assert response.status == '200 OK', 'Wrong response from login page'
50 assert response.status == '200 OK', 'Wrong response from login page'
50 print response.body
51 print response.body
51 assert 'Enter 6 characters or more' in response.body, 'No error password message in response'
52 assert 'Enter 6 characters or more' in response.body, 'No error password message in response'
52
53
53 def test_login_wrong_username_password(self):
54 def test_login_wrong_username_password(self):
54 response = self.app.post(url(controller='login', action='index'),
55 response = self.app.post(url(controller='login', action='index'),
55 {'username':'error',
56 {'username':'error',
56 'password':'test12'})
57 'password':'test12'})
57 assert response.status == '200 OK', 'Wrong response from login page'
58 assert response.status == '200 OK', 'Wrong response from login page'
58
59
59 assert 'invalid user name' in response.body, 'No error username message in response'
60 assert 'invalid user name' in response.body, 'No error username message in response'
60 assert 'invalid password' in response.body, 'No error password message in response'
61 assert 'invalid password' in response.body, 'No error password message in response'
61
62
62 #==========================================================================
63 #==========================================================================
63 # REGISTRATIONS
64 # REGISTRATIONS
64 #==========================================================================
65 #==========================================================================
65 def test_register(self):
66 def test_register(self):
66 response = self.app.get(url(controller='login', action='register'))
67 response = self.app.get(url(controller='login', action='register'))
67 assert 'Sign Up to rhodecode' in response.body, 'wrong page for user registration'
68 assert 'Sign Up to RhodeCode' in response.body, 'wrong page for user registration'
68
69
69 def test_register_err_same_username(self):
70 def test_register_err_same_username(self):
70 response = self.app.post(url(controller='login', action='register'),
71 response = self.app.post(url(controller='login', action='register'),
71 {'username':'test_admin',
72 {'username':'test_admin',
72 'password':'test12',
73 'password':'test12',
73 'password_confirmation':'test12',
74 'password_confirmation':'test12',
74 'email':'goodmail@domain.com',
75 'email':'goodmail@domain.com',
75 'name':'test',
76 'name':'test',
76 'lastname':'test'})
77 'lastname':'test'})
77
78
78 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
79 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
79 assert 'This username already exists' in response.body
80 assert 'This username already exists' in response.body
80
81
81 def test_register_err_wrong_data(self):
82 def test_register_err_wrong_data(self):
82 response = self.app.post(url(controller='login', action='register'),
83 response = self.app.post(url(controller='login', action='register'),
83 {'username':'xs',
84 {'username':'xs',
84 'password':'test',
85 'password':'test',
85 'password_confirmation':'test',
86 'password_confirmation':'test',
86 'email':'goodmailm',
87 'email':'goodmailm',
87 'name':'test',
88 'name':'test',
88 'lastname':'test'})
89 'lastname':'test'})
89
90 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
90 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
91 assert 'An email address must contain a single @' in response.body
91 assert 'An email address must contain a single @' in response.body
92 assert 'Please enter a value' in response.body
92 assert 'Enter a value 6 characters long or more' in response.body
93
93
94
94
95 def test_register_special_chars(self):
95 def test_register_special_chars(self):
96 response = self.app.post(url(controller='login', action='register'),
96 response = self.app.post(url(controller='login', action='register'),
97 {'username':'xxxaxn',
97 {'username':'xxxaxn',
98 'password':'Δ…Δ‡ΕΊΕΌΔ…Ε›Ε›Ε›Ε›',
98 'password':'Δ…Δ‡ΕΊΕΌΔ…Ε›Ε›Ε›Ε›',
99 'password_confirmation':'Δ…Δ‡ΕΊΕΌΔ…Ε›Ε›Ε›Ε›',
99 'password_confirmation':'Δ…Δ‡ΕΊΕΌΔ…Ε›Ε›Ε›Ε›',
100 'email':'goodmailm',
100 'email':'goodmailm@test.plx',
101 'name':'test',
101 'name':'test',
102 'lastname':'test@test.plx'})
102 'lastname':'test'})
103
103
104 print response.body
104 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
105 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
105 assert 'Invalid characters in password' in response.body
106 assert 'Invalid characters in password' in response.body
106
107
107
108
108 def test_register_password_mismatch(self):
109 def test_register_password_mismatch(self):
109 response = self.app.post(url(controller='login', action='register'),
110 response = self.app.post(url(controller='login', action='register'),
110 {'username':'xs',
111 {'username':'xs',
111 'password':'123qwe',
112 'password':'123qwe',
112 'password_confirmation':'qwe123',
113 'password_confirmation':'qwe123',
113 'email':'goodmailm',
114 'email':'goodmailm@test.plxa',
114 'name':'test',
115 'name':'test',
115 'lastname':'test@test.plxa'})
116 'lastname':'test'})
116
117
117 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
118 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
119 print response.body
118 assert 'Password do not match' in response.body
120 assert 'Password do not match' in response.body
119
121
120 def test_register_ok(self):
122 def test_register_ok(self):
121 username = 'test_regular4'
123 username = 'test_regular4'
122 password = 'qweqwe'
124 password = 'qweqwe'
123 email = 'marcin@test.com'
125 email = 'marcin@test.com'
124 name = 'testname'
126 name = 'testname'
125 lastname = 'testlastname'
127 lastname = 'testlastname'
126
128
127 response = self.app.post(url(controller='login', action='register'),
129 response = self.app.post(url(controller='login', action='register'),
128 {'username':username,
130 {'username':username,
129 'password':password,
131 'password':password,
130 'password_confirmation':password,
132 'password_confirmation':password,
131 'email':email,
133 'email':email,
132 'name':name,
134 'name':name,
133 'lastname':lastname})
135 'lastname':lastname})
134 assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status
136 assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status
135 assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
137 assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
136
138
137 ret = self.sa.query(User).filter(User.username == 'test_regular4').one()
139 ret = self.sa.query(User).filter(User.username == 'test_regular4').one()
138 assert ret.username == username , 'field mismatch %s %s' % (ret.username, username)
140 assert ret.username == username , 'field mismatch %s %s' % (ret.username, username)
139 assert check_password(password, ret.password) == True , 'password mismatch'
141 assert check_password(password, ret.password) == True , 'password mismatch'
140 assert ret.email == email , 'field mismatch %s %s' % (ret.email, email)
142 assert ret.email == email , 'field mismatch %s %s' % (ret.email, email)
141 assert ret.name == name , 'field mismatch %s %s' % (ret.name, name)
143 assert ret.name == name , 'field mismatch %s %s' % (ret.name, name)
142 assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname)
144 assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname)
143
145
144
146
145 def test_forgot_password_wrong_mail(self):
147 def test_forgot_password_wrong_mail(self):
146 response = self.app.post(url(controller='login', action='password_reset'),
148 response = self.app.post(url(controller='login', action='password_reset'),
147 {'email':'marcin@wrongmail.org', })
149 {'email':'marcin@wrongmail.org', })
148
150
149 assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email'
151 assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email'
150
152
151 def test_forgot_password(self):
153 def test_forgot_password(self):
152 response = self.app.get(url(controller='login', action='password_reset'))
154 response = self.app.get(url(controller='login', action='password_reset'))
153 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
155 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
154
156
155 username = 'test_password_reset_1'
157 username = 'test_password_reset_1'
156 password = 'qweqwe'
158 password = 'qweqwe'
157 email = 'marcin@python-works.com'
159 email = 'marcin@python-works.com'
158 name = 'passwd'
160 name = 'passwd'
159 lastname = 'reset'
161 lastname = 'reset'
160
162
161 response = self.app.post(url(controller='login', action='register'),
163 response = self.app.post(url(controller='login', action='register'),
162 {'username':username,
164 {'username':username,
163 'password':password,
165 'password':password,
166 'password_confirmation':password,
164 'email':email,
167 'email':email,
165 'name':name,
168 'name':name,
166 'lastname':lastname})
169 'lastname':lastname})
167 #register new user for email test
170 #register new user for email test
168 response = self.app.post(url(controller='login', action='password_reset'),
171 response = self.app.post(url(controller='login', action='password_reset'),
169 {'email':email, })
172 {'email':email, })
170 print response.session['flash']
173 print response.session['flash']
171 assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
174 assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
172 assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset'
175 assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset'
173
176
174
177
175
178
@@ -1,50 +1,50 b''
1 from rhodecode.model.db import Repository
1 from rhodecode.model.db import Repository
2 from rhodecode.tests import *
2 from rhodecode.tests import *
3
3
4 class TestSettingsController(TestController):
4 class TestSettingsController(TestController):
5
5
6 def test_index(self):
6 def test_index(self):
7 self.log_user()
7 self.log_user()
8 response = self.app.get(url(controller='settings', action='index',
8 response = self.app.get(url(controller='settings', action='index',
9 repo_name=HG_REPO))
9 repo_name=HG_REPO))
10 # Test response...
10 # Test response...
11
11
12 def test_fork(self):
12 def test_fork(self):
13 self.log_user()
13 self.log_user()
14 response = self.app.get(url(controller='settings', action='fork',
14 response = self.app.get(url(controller='settings', action='fork',
15 repo_name=HG_REPO))
15 repo_name=HG_REPO))
16
16
17
17
18 def test_fork_create(self):
18 def test_fork_create(self):
19 self.log_user()
19 self.log_user()
20 fork_name = HG_FORK
20 fork_name = HG_FORK
21 description = 'fork of vcs test'
21 description = 'fork of vcs test'
22 repo_name = HG_REPO
22 repo_name = HG_REPO
23 response = self.app.post(url(controller='settings', action='fork_create',
23 response = self.app.post(url(controller='settings', action='fork_create',
24 repo_name=repo_name),
24 repo_name=repo_name),
25 {'fork_name':fork_name,
25 {'fork_name':fork_name,
26 'repo_type':'hg',
26 'repo_type':'hg',
27 'description':description,
27 'description':description,
28 'private':'False'})
28 'private':'False'})
29
29
30 #test if we have a message that fork is ok
30 #test if we have a message that fork is ok
31 assert 'fork %s repository as %s task added' \
31 assert 'forked %s repository as %s' \
32 % (repo_name, fork_name) in response.session['flash'][0], 'No flash message about fork'
32 % (repo_name, fork_name) in response.session['flash'][0], 'No flash message about fork'
33
33
34 #test if the fork was created in the database
34 #test if the fork was created in the database
35 fork_repo = self.sa.query(Repository).filter(Repository.repo_name == fork_name).one()
35 fork_repo = self.sa.query(Repository).filter(Repository.repo_name == fork_name).one()
36
36
37 assert fork_repo.repo_name == fork_name, 'wrong name of repo name in new db fork repo'
37 assert fork_repo.repo_name == fork_name, 'wrong name of repo name in new db fork repo'
38 assert fork_repo.fork.repo_name == repo_name, 'wrong fork parrent'
38 assert fork_repo.fork.repo_name == repo_name, 'wrong fork parrent'
39
39
40
40
41 #test if fork is visible in the list ?
41 #test if fork is visible in the list ?
42 response = response.follow()
42 response = response.follow()
43
43
44
44
45 #check if fork is marked as fork
45 #check if fork is marked as fork
46 response = self.app.get(url(controller='summary', action='index',
46 response = self.app.get(url(controller='summary', action='index',
47 repo_name=fork_name))
47 repo_name=fork_name))
48
48
49 assert 'Fork of %s' % repo_name in response.body, 'no message about that this repo is a fork'
49 assert 'Fork of %s' % repo_name in response.body, 'no message about that this repo is a fork'
50
50
General Comments 0
You need to be logged in to leave comments. Login now