##// END OF EJS Templates
Fixes tests
marcink -
r1418:b097c4e3 beta
parent child Browse files
Show More
@@ -27,7 +27,8 b' log = logging.getLogger(__name__)'
27 27 import pylons.test
28 28
29 29 __all__ = ['environ', 'url', 'TestController', 'TESTS_TMP_PATH', 'HG_REPO',
30 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK', ]
30 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK',
31 'TEST_ADMIN_USER', 'TEST_ADMIN_PASS' ]
31 32
32 33 # Invoke websetup with the current config file
33 34 #SetupCommand('setup-app').run([config_file])
@@ -49,6 +50,9 b" NEW_GIT_REPO = 'vcs_test_git_new'"
49 50 HG_FORK = 'vcs_test_hg_fork'
50 51 GIT_FORK = 'vcs_test_git_fork'
51 52
53 TEST_ADMIN_USER = 'test_admin'
54 TEST_ADMIN_PASS = 'test12'
55
52 56 class TestController(TestCase):
53 57
54 58 def __init__(self, *args, **kwargs):
@@ -61,7 +65,7 b' class TestController(TestCase):'
61 65 self.index_location = config['app_conf']['index_dir']
62 66 TestCase.__init__(self, *args, **kwargs)
63 67
64 def log_user(self, username='test_admin', password='test12'):
68 def log_user(self, username=TEST_ADMIN_USER, password=TEST_ADMIN_PASS):
65 69 response = self.app.post(url(controller='login', action='index'),
66 70 {'username':username,
67 71 'password':password})
@@ -76,6 +80,7 b' class TestController(TestCase):'
76 80
77 81
78 82 def checkSessionFlash(self, response, msg):
83 print response
79 84 self.assertTrue('flash' in response.session)
80 85 self.assertTrue(msg in response.session['flash'][0][1])
81 86
@@ -1,6 +1,7 b''
1 1 # -*- coding: utf-8 -*-
2 2 from rhodecode.tests import *
3 3 from rhodecode.model.db import User
4 from rhodecode.lib import generate_api_key
4 5 from rhodecode.lib.auth import check_password
5 6
6 7
@@ -8,39 +9,42 b' class TestLoginController(TestController'
8 9
9 10 def test_index(self):
10 11 response = self.app.get(url(controller='login', action='index'))
11 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
12 self.assertEqual(response.status, '200 OK')
12 13 # Test response...
13 14
14 15 def test_login_admin_ok(self):
15 16 response = self.app.post(url(controller='login', action='index'),
16 17 {'username':'test_admin',
17 18 'password':'test12'})
18 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
19 assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user'
19 self.assertEqual(response.status, '302 Found')
20 self.assertEqual(response.session['rhodecode_user'].username ,
21 'test_admin')
20 22 response = response.follow()
21 assert '%s repository' % HG_REPO in response.body
23 self.assertTrue('%s repository' % HG_REPO in response.body)
22 24
23 25 def test_login_regular_ok(self):
24 26 response = self.app.post(url(controller='login', action='index'),
25 27 {'username':'test_regular',
26 28 'password':'test12'})
27 print response
28 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
29 assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user'
29
30 self.assertEqual(response.status, '302 Found')
31 self.assertEqual(response.session['rhodecode_user'].username ,
32 'test_regular')
30 33 response = response.follow()
31 assert '%s repository' % HG_REPO in response.body
32 assert '<a title="Admin" href="/_admin">' not in response.body
34 self.assertTrue('%s repository' % HG_REPO in response.body)
35 self.assertTrue('<a title="Admin" href="/_admin">' not in response.body)
33 36
34 37 def test_login_ok_came_from(self):
35 38 test_came_from = '/_admin/users'
36 response = self.app.post(url(controller='login', action='index', came_from=test_came_from),
39 response = self.app.post(url(controller='login', action='index',
40 came_from=test_came_from),
37 41 {'username':'test_admin',
38 42 'password':'test12'})
39 assert response.status == '302 Found', 'Wrong response code from came from redirection'
43 self.assertEqual(response.status, '302 Found')
40 44 response = response.follow()
41 45
42 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
43 assert 'Users administration' in response.body, 'No proper title in response'
46 self.assertEqual(response.status, '200 OK')
47 self.assertTrue('Users administration' in response.body)
44 48
45 49
46 50 def test_login_short_password(self):
@@ -48,24 +52,24 b' class TestLoginController(TestController'
48 52 {'username':'test_admin',
49 53 'password':'as'})
50 54 self.assertEqual(response.status, '200 OK')
51 print response.body
55
52 56 self.assertTrue('Enter 3 characters or more' in response.body)
53 57
54 58 def test_login_wrong_username_password(self):
55 59 response = self.app.post(url(controller='login', action='index'),
56 60 {'username':'error',
57 61 'password':'test12'})
58 assert response.status == '200 OK', 'Wrong response from login page'
62 self.assertEqual(response.status , '200 OK')
59 63
60 assert 'invalid user name' in response.body, 'No error username message in response'
61 assert 'invalid password' in response.body, 'No error password message in response'
64 self.assertTrue('invalid user name' in response.body)
65 self.assertTrue('invalid password' in response.body)
62 66
63 67 #==========================================================================
64 68 # REGISTRATIONS
65 69 #==========================================================================
66 70 def test_register(self):
67 71 response = self.app.get(url(controller='login', action='register'))
68 assert 'Sign Up to RhodeCode' in response.body, 'wrong page for user registration'
72 self.assertTrue('Sign Up to RhodeCode' in response.body)
69 73
70 74 def test_register_err_same_username(self):
71 75 response = self.app.post(url(controller='login', action='register'),
@@ -76,8 +80,8 b' class TestLoginController(TestController'
76 80 'name':'test',
77 81 'lastname':'test'})
78 82
79 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
80 assert 'This username already exists' in response.body
83 self.assertEqual(response.status , '200 OK')
84 self.assertTrue('This username already exists' in response.body)
81 85
82 86 def test_register_err_same_email(self):
83 87 response = self.app.post(url(controller='login', action='register'),
@@ -88,7 +92,7 b' class TestLoginController(TestController'
88 92 'name':'test',
89 93 'lastname':'test'})
90 94
91 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
95 self.assertEqual(response.status , '200 OK')
92 96 assert 'This e-mail address is already taken' in response.body
93 97
94 98 def test_register_err_same_email_case_sensitive(self):
@@ -99,7 +103,7 b' class TestLoginController(TestController'
99 103 'email':'TesT_Admin@mail.COM',
100 104 'name':'test',
101 105 'lastname':'test'})
102 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
106 self.assertEqual(response.status , '200 OK')
103 107 assert 'This e-mail address is already taken' in response.body
104 108
105 109 def test_register_err_wrong_data(self):
@@ -110,7 +114,7 b' class TestLoginController(TestController'
110 114 'email':'goodmailm',
111 115 'name':'test',
112 116 'lastname':'test'})
113 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
117 self.assertEqual(response.status , '200 OK')
114 118 assert 'An email address must contain a single @' in response.body
115 119 assert 'Enter a value 6 characters long or more' in response.body
116 120
@@ -124,8 +128,7 b' class TestLoginController(TestController'
124 128 'name':'test',
125 129 'lastname':'test'})
126 130
127 print response.body
128 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
131 self.assertEqual(response.status , '200 OK')
129 132 assert 'An email address must contain a single @' in response.body
130 133 assert ('Username may only contain '
131 134 'alphanumeric characters underscores, '
@@ -141,7 +144,7 b' class TestLoginController(TestController'
141 144 'name':'test',
142 145 'lastname':'test'})
143 146
144 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
147 self.assertEqual(response.status , '200 OK')
145 148 assert 'An email address must contain a single @' in response.body
146 149 assert 'This username already exists' in response.body
147 150
@@ -156,8 +159,7 b' class TestLoginController(TestController'
156 159 'name':'test',
157 160 'lastname':'test'})
158 161
159 print response.body
160 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
162 self.assertEqual(response.status , '200 OK')
161 163 assert 'Invalid characters in password' in response.body
162 164
163 165
@@ -170,8 +172,7 b' class TestLoginController(TestController'
170 172 'name':'test',
171 173 'lastname':'test'})
172 174
173 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
174 print response.body
175 self.assertEqual(response.status , '200 OK')
175 176 assert 'Password do not match' in response.body
176 177
177 178 def test_register_ok(self):
@@ -188,7 +189,7 b' class TestLoginController(TestController'
188 189 'email':email,
189 190 'name':name,
190 191 'lastname':lastname})
191 assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status
192 self.assertEqual(response.status , '302 Found')
192 193 assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
193 194
194 195 ret = self.sa.query(User).filter(User.username == 'test_regular4').one()
@@ -206,8 +207,9 b' class TestLoginController(TestController'
206 207 assert "This e-mail address doesn't exist" in response.body, 'Missing error message about wrong email'
207 208
208 209 def test_forgot_password(self):
209 response = self.app.get(url(controller='login', action='password_reset'))
210 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
210 response = self.app.get(url(controller='login',
211 action='password_reset'))
212 self.assertEqual(response.status , '200 OK')
211 213
212 214 username = 'test_password_reset_1'
213 215 password = 'qweqwe'
@@ -215,16 +217,45 b' class TestLoginController(TestController'
215 217 name = 'passwd'
216 218 lastname = 'reset'
217 219
218 response = self.app.post(url(controller='login', action='register'),
219 {'username':username,
220 'password':password,
221 'password_confirmation':password,
222 'email':email,
223 'name':name,
224 'lastname':lastname})
225 #register new user for email test
226 response = self.app.post(url(controller='login', action='password_reset'),
227 {'email':email, })
228 print response.session['flash']
229 assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
230 assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset'
220 new = User()
221 new.username = username
222 new.password = password
223 new.email = email
224 new.name = name
225 new.lastname = lastname
226 new.api_key = generate_api_key(username)
227 self.sa.add(new)
228 self.sa.commit()
229
230 response = self.app.post(url(controller='login',
231 action='password_reset'),
232 {'email':email, })
233
234 self.checkSessionFlash(response, 'Your password reset link was sent')
235
236 response = response.follow()
237
238 # BAD KEY
239
240 key = "bad"
241 response = self.app.get(url(controller='login',
242 action='password_reset_confirmation',
243 key=key))
244 self.assertEqual(response.status, '302 Found')
245 self.assertTrue(response.location.endswith(url('reset_password')))
246
247 # GOOD KEY
248
249 key = User.by_username(username).api_key
250
251 response = self.app.get(url(controller='login',
252 action='password_reset_confirmation',
253 key=key))
254 self.assertEqual(response.status, '302 Found')
255 self.assertTrue(response.location.endswith(url('login_home')))
256
257 self.checkSessionFlash(response,
258 ('Your password reset was successful, '
259 'new password has been sent to your email'))
260
261 response = response.follow()
@@ -10,6 +10,7 b' verbose=True'
10 10 verbosity=2
11 11 with-pylons=test.ini
12 12 detailed-errors=1
13 nologcapture=1
13 14
14 15 # Babel configuration
15 16 [compile_catalog]
General Comments 0
You need to be logged in to leave comments. Login now