Mercurial > kallithea
comparison rhodecode/tests/functional/test_login.py @ 547:1e757ac98988
renamed project to rhodecode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 06 Oct 2010 03:18:16 +0200 |
parents | pylons_app/tests/functional/test_login.py@12c976209b2e |
children | b75b77ef649d |
comparison
equal
deleted
inserted
replaced
546:7c2f5e4d7bbf | 547:1e757ac98988 |
---|---|
1 from rhodecode.tests import * | |
2 from rhodecode.model.db import User | |
3 from rhodecode.lib.auth import check_password | |
4 | |
5 | |
6 class TestLoginController(TestController): | |
7 | |
8 def test_index(self): | |
9 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 # Test response... | |
12 | |
13 def test_login_admin_ok(self): | |
14 response = self.app.post(url(controller='login', action='index'), | |
15 {'username':'test_admin', | |
16 'password':'test12'}) | |
17 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status | |
18 assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user' | |
19 response = response.follow() | |
20 assert 'auto description for vcs_test' in response.body | |
21 | |
22 def test_login_regular_ok(self): | |
23 response = self.app.post(url(controller='login', action='index'), | |
24 {'username':'test_regular', | |
25 'password':'test12'}) | |
26 print response | |
27 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status | |
28 assert response.session['hg_app_user'].username == 'test_regular', 'wrong logged in user' | |
29 response = response.follow() | |
30 assert 'auto description for vcs_test' in response.body | |
31 assert '<a title="Admin" href="/_admin">' not in response.body | |
32 | |
33 def test_login_ok_came_from(self): | |
34 test_came_from = '/_admin/users' | |
35 response = self.app.post(url(controller='login', action='index', came_from=test_came_from), | |
36 {'username':'test_admin', | |
37 'password':'test12'}) | |
38 assert response.status == '302 Found', 'Wrong response code from came from redirection' | |
39 response = response.follow() | |
40 | |
41 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 | |
44 | |
45 def test_login_short_password(self): | |
46 response = self.app.post(url(controller='login', action='index'), | |
47 {'username':'error', | |
48 'password':'test'}) | |
49 assert response.status == '200 OK', 'Wrong response from login page' | |
50 | |
51 assert 'Enter a value 6 characters long or more' in response.body, 'No error password message in response' | |
52 | |
53 def test_login_wrong_username_password(self): | |
54 response = self.app.post(url(controller='login', action='index'), | |
55 {'username':'error', | |
56 'password':'test12'}) | |
57 assert response.status == '200 OK', 'Wrong response from login page' | |
58 | |
59 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 | |
62 | |
63 def test_register(self): | |
64 response = self.app.get(url(controller='login', action='register')) | |
65 assert 'Sign Up to hg-app' in response.body, 'wrong page for user registration' | |
66 | |
67 def test_register_err_same_username(self): | |
68 response = self.app.post(url(controller='login', action='register'), | |
69 {'username':'test_admin', | |
70 'password':'test', | |
71 'email':'goodmail@domain.com', | |
72 'name':'test', | |
73 'lastname':'test'}) | |
74 | |
75 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | |
76 assert 'This username already exists' in response.body | |
77 | |
78 def test_register_err_wrong_data(self): | |
79 response = self.app.post(url(controller='login', action='register'), | |
80 {'username':'xs', | |
81 'password':'', | |
82 'email':'goodmailm', | |
83 'name':'test', | |
84 'lastname':'test'}) | |
85 | |
86 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status | |
87 assert 'An email address must contain a single @' in response.body | |
88 assert 'Please enter a value' in response.body | |
89 | |
90 | |
91 | |
92 def test_register_ok(self): | |
93 username = 'test_regular4' | |
94 password = 'qweqwe' | |
95 email = 'marcin@test.com' | |
96 name = 'testname' | |
97 lastname = 'testlastname' | |
98 | |
99 response = self.app.post(url(controller='login', action='register'), | |
100 {'username':username, | |
101 'password':password, | |
102 'email':email, | |
103 'name':name, | |
104 'lastname':lastname}) | |
105 print response.body | |
106 assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status | |
107 assert 'You have successfully registered into hg-app' in response.session['flash'][0], 'No flash message about user registration' | |
108 | |
109 ret = self.sa.query(User).filter(User.username == 'test_regular4').one() | |
110 assert ret.username == username , 'field mismatch %s %s' % (ret.username, username) | |
111 assert check_password(password, ret.password) == True , 'password mismatch' | |
112 assert ret.email == email , 'field mismatch %s %s' % (ret.email, email) | |
113 assert ret.name == name , 'field mismatch %s %s' % (ret.name, name) | |
114 assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname) | |
115 | |
116 | |
117 def test_forgot_password_wrong_mail(self): | |
118 response = self.app.post(url(controller='login', action='password_reset'), | |
119 {'email':'marcin@wrongmail.org', }) | |
120 | |
121 assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email' | |
122 | |
123 def test_forgot_password(self): | |
124 response = self.app.get(url(controller='login', action='password_reset')) | |
125 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status | |
126 | |
127 username = 'test_password_reset_1' | |
128 password = 'qweqwe' | |
129 email = 'marcin@python-works.com' | |
130 name = 'passwd' | |
131 lastname = 'reset' | |
132 | |
133 response = self.app.post(url(controller='login', action='register'), | |
134 {'username':username, | |
135 'password':password, | |
136 'email':email, | |
137 'name':name, | |
138 'lastname':lastname}) | |
139 #register new user for email test | |
140 response = self.app.post(url(controller='login', action='password_reset'), | |
141 {'email':email, }) | |
142 print response.session['flash'] | |
143 assert 'You have successfully registered into hg-app' in response.session['flash'][0], 'No flash message about user registration' | |
144 assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset' | |
145 | |
146 | |
147 |