##// END OF EJS Templates
added test for username and email case senstitive validators,...
marcink -
r745:c366b237 beta
parent child Browse files
Show More
@@ -72,16 +72,17 b' def ValidUsername(edit, old_data):'
72 case_insensitive=True):
72 case_insensitive=True):
73 raise formencode.Invalid(_('This username already exists') ,
73 raise formencode.Invalid(_('This username already exists') ,
74 value, state)
74 value, state)
75
75
76
76
77 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-]+$', value) is None:
77 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_]+$', value) is None:
78 raise formencode.Invalid(_('Username may only contain '
78 raise formencode.Invalid(_('Username may only contain '
79 'alphanumeric characters '
79 'alphanumeric characters underscores '
80 'or dashes and cannot begin with a dash'),
80 'or dashes and must begin with '
81 'alphanumeric character'),
81 value, state)
82 value, state)
82
83
83
84
84
85
85 return _ValidUsername
86 return _ValidUsername
86
87
87 class ValidPassword(formencode.validators.FancyValidator):
88 class ValidPassword(formencode.validators.FancyValidator):
@@ -258,7 +259,6 b' def UniqSystemEmail(old_data):'
258 class _UniqSystemEmail(formencode.validators.FancyValidator):
259 class _UniqSystemEmail(formencode.validators.FancyValidator):
259 def to_python(self, value, state):
260 def to_python(self, value, state):
260 value = value.lower()
261 value = value.lower()
261 #TODO:write test for MixedCase scenarios
262 if old_data.get('email') != value:
262 if old_data.get('email') != value:
263 sa = meta.Session()
263 sa = meta.Session()
264 try:
264 try:
@@ -79,6 +79,29 b' class TestLoginController(TestController'
79 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
80 assert 'This username already exists' in response.body
80 assert 'This username already exists' in response.body
81
81
82 def test_register_err_same_email(self):
83 response = self.app.post(url(controller='login', action='register'),
84 {'username':'test_admin_0',
85 'password':'test12',
86 'password_confirmation':'test12',
87 'email':'test_admin@mail.com',
88 'name':'test',
89 'lastname':'test'})
90
91 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
92 assert 'That e-mail address is already taken' in response.body
93
94 def test_register_err_same_email_case_sensitive(self):
95 response = self.app.post(url(controller='login', action='register'),
96 {'username':'test_admin_1',
97 'password':'test12',
98 'password_confirmation':'test12',
99 'email':'TesT_Admin@mail.COM',
100 'name':'test',
101 'lastname':'test'})
102 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
103 assert 'That e-mail address is already taken' in response.body
104
82 def test_register_err_wrong_data(self):
105 def test_register_err_wrong_data(self):
83 response = self.app.post(url(controller='login', action='register'),
106 response = self.app.post(url(controller='login', action='register'),
84 {'username':'xs',
107 {'username':'xs',
@@ -92,6 +115,35 b' class TestLoginController(TestController'
92 assert 'Enter a value 6 characters long or more' in response.body
115 assert 'Enter a value 6 characters long or more' in response.body
93
116
94
117
118 def test_register_err_username(self):
119 response = self.app.post(url(controller='login', action='register'),
120 {'username':'error user',
121 'password':'test12',
122 'password_confirmation':'test12',
123 'email':'goodmailm',
124 'name':'test',
125 'lastname':'test'})
126
127 print response.body
128 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
129 assert 'An email address must contain a single @' in response.body
130 assert 'Username may only contain alphanumeric characters underscores or dashes and must begin with alphanumeric character' in response.body
131
132 def test_register_err_case_sensitive(self):
133 response = self.app.post(url(controller='login', action='register'),
134 {'username':'Test_Admin',
135 'password':'test12',
136 'password_confirmation':'test12',
137 'email':'goodmailm',
138 'name':'test',
139 'lastname':'test'})
140
141 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
142 assert 'An email address must contain a single @' in response.body
143 assert 'This username already exists' in response.body
144
145
146
95 def test_register_special_chars(self):
147 def test_register_special_chars(self):
96 response = self.app.post(url(controller='login', action='register'),
148 response = self.app.post(url(controller='login', action='register'),
97 {'username':'xxxaxn',
149 {'username':'xxxaxn',
General Comments 0
You need to be logged in to leave comments. Login now