Mercurial > kallithea
annotate pylons_app/tests/functional/test_login.py @ 498:6aa7db1c083a celery
version bump, small readme update
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 23 Sep 2010 01:21:46 +0200 |
parents | a9e50dce3081 |
children | 53aa1ee1af86 |
rev | line source |
---|---|
188
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 from pylons_app.tests import * |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
2 from pylons_app.model.db import User |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
3 from pylons_app.lib.auth import check_password |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
4 |
188
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 class TestLoginController(TestController): |
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 def test_index(self): |
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 response = self.app.get(url(controller='login', action='index')) |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
10 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status |
188
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 # Test response... |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
12 |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
13 def test_login_admin_ok(self): |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
14 response = self.app.post(url(controller='login', action='index'), |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
15 {'username':'test_admin', |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
16 'password':'test'}) |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
17 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
18 assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user' |
462
298546182b41
more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
461
diff
changeset
|
19 response = response.follow() |
298546182b41
more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
461
diff
changeset
|
20 assert 'auto description for vcs_test' in response.body |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
21 |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
22 def test_login_regular_ok(self): |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
23 response = self.app.post(url(controller='login', action='index'), |
462
298546182b41
more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
461
diff
changeset
|
24 {'username':'test_regular', |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
25 'password':'test'}) |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
26 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
27 assert response.session['hg_app_user'].username == 'test_regular', 'wrong logged in user' |
462
298546182b41
more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
461
diff
changeset
|
28 response = response.follow() |
298546182b41
more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
461
diff
changeset
|
29 assert 'auto description for vcs_test' in response.body |
298546182b41
more test suites on login, fixed strange detached instance bug found during in tests.
Marcin Kuzminski <marcin@python-works.com>
parents:
461
diff
changeset
|
30 assert '<a title="Admin" href="/_admin">' not in response.body |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
31 |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
32 def test_login_ok_came_from(self): |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
33 test_came_from = '/_admin/users' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
34 response = self.app.post(url(controller='login', action='index', came_from=test_came_from), |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
35 {'username':'test_admin', |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
36 'password':'test'}) |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
37 assert response.status == '302 Found', 'Wrong response code from came from redirection' |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
38 response = response.follow() |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
39 |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
40 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
41 assert 'Users administration' in response.body, 'No proper title in response' |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
42 |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
43 |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
44 def test_login_wrong(self): |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
45 response = self.app.post(url(controller='login', action='index'), |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
46 {'username':'error', |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
47 'password':'test'}) |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
48 assert response.status == '200 OK', 'Wrong response from login page' |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
49 |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
50 assert 'invalid user name' in response.body, 'No error username message in response' |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
51 assert 'invalid password' in response.body, 'No error password message in response' |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
52 |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
53 |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
54 def test_register(self): |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
55 response = self.app.get(url(controller='login', action='register')) |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
56 assert 'Sign Up to hg-app' in response.body, 'wrong page for user registration' |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
57 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
58 def test_register_err_same_username(self): |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
59 response = self.app.post(url(controller='login', action='register'), |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
60 {'username':'test_admin', |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
61 'password':'test', |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
62 'email':'goodmail@domain.com', |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
63 'name':'test', |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
64 'lastname':'test'}) |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
65 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
66 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
67 assert 'This username already exists' in response.body |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
68 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
69 def test_register_err_wrong_data(self): |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
70 response = self.app.post(url(controller='login', action='register'), |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
71 {'username':'xs', |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
72 'password':'', |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
73 'email':'goodmailm', |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
74 'name':'test', |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
75 'lastname':'test'}) |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
76 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
77 assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
78 assert 'An email address must contain a single @' in response.body |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
79 assert 'Enter a value 3 characters long or more' in response.body |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
80 assert 'Please enter a value<' in response.body |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
81 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
82 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
83 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
84 def test_register_ok(self): |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
85 username = 'test_regular4' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
86 password = 'qweqwe' |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
87 email = 'marcin@test.com' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
88 name = 'testname' |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
89 lastname = 'testlastname' |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
90 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
91 response = self.app.post(url(controller='login', action='register'), |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
92 {'username':username, |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
93 'password':password, |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
94 'email':email, |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
95 'name':name, |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
96 'lastname':lastname}) |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
97 print response.body |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
98 assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
99 assert 'You have successfully registered into hg-app' in response.session['flash'][0], 'No flash message about user registration' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
100 |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
101 ret = self.sa.query(User).filter(User.username == 'test_regular4').one() |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
102 assert ret.username == username , 'field mismatch %s %s' % (ret.username, username) |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
103 assert check_password(password, ret.password) == True , 'password mismatch' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
104 assert ret.email == email , 'field mismatch %s %s' % (ret.email, email) |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
105 assert ret.name == name , 'field mismatch %s %s' % (ret.name, name) |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
106 assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname) |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
107 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
108 |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
109 def test_forgot_password_wrong_mail(self): |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
110 response = self.app.post(url(controller='login', action='password_reset'), |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
111 {'email':'marcin@wrongmail.org', }) |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
112 |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
113 assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email' |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
114 |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
115 def test_forgot_password(self): |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
116 response = self.app.get(url(controller='login', action='password_reset')) |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
117 assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
118 |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
119 username = 'test_password_reset_1' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
120 password = 'qweqwe' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
121 email = 'marcin@python-works.com' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
122 name = 'passwd' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
123 lastname = 'reset' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
124 |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
125 response = self.app.post(url(controller='login', action='register'), |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
126 {'username':username, |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
127 'password':password, |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
128 'email':email, |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
129 'name':name, |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
130 'lastname':lastname}) |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
131 #register new user for email test |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
132 response = self.app.post(url(controller='login', action='password_reset'), |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
133 {'email':email, }) |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
134 print response.session['flash'] |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
135 assert 'You have successfully registered into hg-app' in response.session['flash'][0], 'No flash message about user registration' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
136 assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
137 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
138 |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
139 |