Mercurial > kallithea
annotate rhodecode/tests/functional/test_login.py @ 3071:7b0c19b00629 beta
python 2.5 tests fix
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 07 Dec 2012 00:31:04 +0100 |
parents | dffb92224edf |
children | 7d3d0a96e083 |
rev | line source |
---|---|
728
f1629c0c28cc
fixed bug in forms found due to testing,
Marcin Kuzminski <marcin@python-works.com>
parents:
723
diff
changeset
|
1 # -*- coding: utf-8 -*- |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
534
diff
changeset
|
2 from rhodecode.tests import * |
1732 | 3 from rhodecode.model.db import User, Notification |
2109 | 4 from rhodecode.lib.utils2 import generate_api_key |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
534
diff
changeset
|
5 from rhodecode.lib.auth import check_password |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
6 from rhodecode.lib import helpers as h |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
7 from rhodecode.model import validators |
188
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 |
2109 | 9 |
188
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 class TestLoginController(TestController): |
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 |
1732 | 12 def tearDown(self): |
13 for n in Notification.query().all(): | |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
14 self.Session().delete(n) |
1732 | 15 |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
16 self.Session().commit() |
1732 | 17 self.assertEqual(Notification.query().all(), []) |
18 | |
188
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 def test_index(self): |
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 response = self.app.get(url(controller='login', action='index')) |
1418 | 21 self.assertEqual(response.status, '200 OK') |
188
8337dd6492a9
logins controller test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # Test response... |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
23 |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
24 def test_login_admin_ok(self): |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
25 response = self.app.post(url(controller='login', action='index'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
26 {'username': 'test_admin', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
27 'password': 'test12'}) |
1418 | 28 self.assertEqual(response.status, '302 Found') |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
29 self.assertEqual(response.session['rhodecode_user'].get('username'), |
1418 | 30 'test_admin') |
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
|
31 response = response.follow() |
1418 | 32 self.assertTrue('%s repository' % HG_REPO in response.body) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
33 |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
34 def test_login_regular_ok(self): |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
35 response = self.app.post(url(controller='login', action='index'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
36 {'username': 'test_regular', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
37 'password': 'test12'}) |
1418 | 38 |
39 self.assertEqual(response.status, '302 Found') | |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
40 self.assertEqual(response.session['rhodecode_user'].get('username'), |
1418 | 41 'test_regular') |
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
|
42 response = response.follow() |
1418 | 43 self.assertTrue('%s repository' % HG_REPO in response.body) |
44 self.assertTrue('<a title="Admin" href="/_admin">' not in response.body) | |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
45 |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
46 def test_login_ok_came_from(self): |
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
47 test_came_from = '/_admin/users' |
1418 | 48 response = self.app.post(url(controller='login', action='index', |
49 came_from=test_came_from), | |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
50 {'username': 'test_admin', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
51 'password': 'test12'}) |
1418 | 52 self.assertEqual(response.status, '302 Found') |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
53 response = response.follow() |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
54 |
1418 | 55 self.assertEqual(response.status, '200 OK') |
56 self.assertTrue('Users administration' in response.body) | |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
57 |
2679
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
58 @parameterized.expand([ |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
59 ('data:text/html,<script>window.alert("xss")</script>',), |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
60 ('mailto:test@rhodecode.org',), |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
61 ('file:///etc/passwd',), |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
62 ('ftp://some.ftp.server',), |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
63 ('http://other.domain',), |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
64 ]) |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
65 def test_login_bad_came_froms(self, url_came_from): |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
66 response = self.app.post(url(controller='login', action='index', |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
67 came_from=url_came_from), |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
68 {'username': 'test_admin', |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
69 'password': 'test12'}) |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
70 self.assertEqual(response.status, '302 Found') |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
71 self.assertEqual(response._environ['paste.testing_variables'] |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
72 ['tmpl_context'].came_from, '/') |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
73 response = response.follow() |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
74 |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
75 self.assertEqual(response.status, '200 OK') |
dffb92224edf
removed ftp from allowed schemas
Marcin Kuzminski <marcin@python-works.com>
parents:
2595
diff
changeset
|
76 |
533
53aa1ee1af86
updated tests for new version 6char password etc...
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
77 def test_login_short_password(self): |
461
e95621133eb6
made test for login page
Marcin Kuzminski <marcin@python-works.com>
parents:
188
diff
changeset
|
78 response = self.app.post(url(controller='login', action='index'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
79 {'username': 'test_admin', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
80 'password': 'as'}) |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
81 self.assertEqual(response.status, '200 OK') |
1418 | 82 |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
83 self.assertTrue('Enter 3 characters or more' in response.body) |
533
53aa1ee1af86
updated tests for new version 6char password etc...
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
84 |
53aa1ee1af86
updated tests for new version 6char password etc...
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
85 def test_login_wrong_username_password(self): |
53aa1ee1af86
updated tests for new version 6char password etc...
Marcin Kuzminski <marcin@python-works.com>
parents:
483
diff
changeset
|
86 response = self.app.post(url(controller='login', action='index'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
87 {'username': 'error', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
88 'password': 'test12'}) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
89 |
1418 | 90 self.assertTrue('invalid user name' in response.body) |
91 self.assertTrue('invalid password' in response.body) | |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
92 |
723
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
93 #========================================================================== |
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
94 # REGISTRATIONS |
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
95 #========================================================================== |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
96 def test_register(self): |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
97 response = self.app.get(url(controller='login', action='register')) |
1418 | 98 self.assertTrue('Sign Up to RhodeCode' in response.body) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
99 |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
100 def test_register_err_same_username(self): |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
101 uname = 'test_admin' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
102 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
103 {'username': uname, |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
104 'password': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
105 'password_confirmation': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
106 'email': 'goodmail@domain.com', |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
107 'firstname': 'test', |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
108 'lastname': 'test'}) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
109 |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
110 msg = validators.ValidUsername()._messages['username_exists'] |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
111 msg = h.html_escape(msg % {'username': uname}) |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
112 response.mustcontain(msg) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
113 |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
114 def test_register_err_same_email(self): |
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
115 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
116 {'username': 'test_admin_0', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
117 'password': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
118 'password_confirmation': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
119 'email': 'test_admin@mail.com', |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
120 'firstname': 'test', |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
121 'lastname': 'test'}) |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
122 |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
123 msg = validators.UniqSystemEmail()()._messages['email_taken'] |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
124 response.mustcontain(msg) |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
125 |
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
126 def test_register_err_same_email_case_sensitive(self): |
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
127 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
128 {'username': 'test_admin_1', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
129 'password': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
130 'password_confirmation': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
131 'email': 'TesT_Admin@mail.COM', |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
132 'firstname': 'test', |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
133 'lastname': 'test'}) |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
134 msg = validators.UniqSystemEmail()()._messages['email_taken'] |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
135 response.mustcontain(msg) |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
136 |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
137 def test_register_err_wrong_data(self): |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
138 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
139 {'username': 'xs', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
140 'password': 'test', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
141 'password_confirmation': 'test', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
142 'email': 'goodmailm', |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
143 'firstname': 'test', |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
144 'lastname': 'test'}) |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
145 self.assertEqual(response.status, '200 OK') |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
146 response.mustcontain('An email address must contain a single @') |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
147 response.mustcontain('Enter a value 6 characters long or more') |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
148 |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
149 def test_register_err_username(self): |
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
150 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
151 {'username': 'error user', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
152 'password': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
153 'password_confirmation': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
154 'email': 'goodmailm', |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
155 'firstname': 'test', |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
156 'lastname': 'test'}) |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
157 |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
158 response.mustcontain('An email address must contain a single @') |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
159 response.mustcontain('Username may only contain ' |
1021 | 160 'alphanumeric characters underscores, ' |
161 'periods or dashes and must begin with ' | |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
162 'alphanumeric character') |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
163 |
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
164 def test_register_err_case_sensitive(self): |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
165 usr = 'Test_Admin' |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
166 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
167 {'username': usr, |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
168 'password': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
169 'password_confirmation': 'test12', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
170 'email': 'goodmailm', |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
171 'firstname': 'test', |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
172 'lastname': 'test'}) |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
173 |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
174 response.mustcontain('An email address must contain a single @') |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
175 msg = validators.ValidUsername()._messages['username_exists'] |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
176 msg = h.html_escape(msg % {'username': usr}) |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
177 response.mustcontain(msg) |
745
c366b237c91d
added test for username and email case senstitive validators,
Marcin Kuzminski <marcin@python-works.com>
parents:
728
diff
changeset
|
178 |
723
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
179 def test_register_special_chars(self): |
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
180 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
181 {'username': 'xxxaxn', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
182 'password': 'ąćźżąśśśś', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
183 'password_confirmation': 'ąćźżąśśśś', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
184 'email': 'goodmailm@test.plx', |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
185 'firstname': 'test', |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
186 'lastname': 'test'}) |
723
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
187 |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
188 msg = validators.ValidPassword()._messages['invalid_password'] |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
189 response.mustcontain(msg) |
723
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
190 |
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
191 def test_register_password_mismatch(self): |
bf26b46e82d6
some tests update
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
192 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
193 {'username': 'xs', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
194 'password': '123qwe', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
195 'password_confirmation': 'qwe123', |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
196 'email': 'goodmailm@test.plxa', |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
197 'firstname': 'test', |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
198 'lastname': 'test'}) |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
199 msg = validators.ValidPasswordsMatch()._messages['password_mismatch'] |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
200 response.mustcontain(msg) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
201 |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
202 def test_register_ok(self): |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
203 username = 'test_regular4' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
204 password = 'qweqwe' |
483
a9e50dce3081
Removed config names from whoosh and celery,
Marcin Kuzminski <marcin@python-works.com>
parents:
473
diff
changeset
|
205 email = 'marcin@test.com' |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
206 name = 'testname' |
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
207 lastname = 'testlastname' |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
208 |
463
a03250279b15
test for register page
Marcin Kuzminski <marcin@python-works.com>
parents:
462
diff
changeset
|
209 response = self.app.post(url(controller='login', action='register'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
210 {'username': username, |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
211 'password': password, |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
212 'password_confirmation': password, |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
213 'email': email, |
2595
6c83dc0226d2
renamed some leftover name -> firstname
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
214 'firstname': name, |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
215 'lastname': lastname, |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
216 'admin': True}) # This should be overriden |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
217 self.assertEqual(response.status, '302 Found') |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
218 self.checkSessionFlash(response, 'You have successfully registered into rhodecode') |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
219 |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
220 ret = self.Session().query(User).filter(User.username == 'test_regular4').one() |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
221 self.assertEqual(ret.username, username) |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
222 self.assertEqual(check_password(password, ret.password), True) |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
223 self.assertEqual(ret.email, email) |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
224 self.assertEqual(ret.name, name) |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
225 self.assertEqual(ret.lastname, lastname) |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
226 self.assertNotEqual(ret.api_key, None) |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
227 self.assertEqual(ret.admin, False) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
228 |
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
229 def test_forgot_password_wrong_mail(self): |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
230 bad_email = 'marcin@wrongmail.org' |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
231 response = self.app.post( |
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
232 url(controller='login', action='password_reset'), |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
233 {'email': bad_email, } |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
234 ) |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
235 |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
236 msg = validators.ValidSystemEmail()._messages['non_existing_email'] |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
237 msg = h.html_escape(msg % {'email': bad_email}) |
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
238 response.mustcontain() |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
239 |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
240 def test_forgot_password(self): |
1418 | 241 response = self.app.get(url(controller='login', |
242 action='password_reset')) | |
2248
72542dc597be
fixed issue with empty APIKEYS on registration #438
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
243 self.assertEqual(response.status, '200 OK') |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
244 |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
245 username = 'test_password_reset_1' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
246 password = 'qweqwe' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
247 email = 'marcin@python-works.com' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
248 name = 'passwd' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
463
diff
changeset
|
249 lastname = 'reset' |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
250 |
1418 | 251 new = User() |
252 new.username = username | |
253 new.password = password | |
254 new.email = email | |
255 new.name = name | |
256 new.lastname = lastname | |
257 new.api_key = generate_api_key(username) | |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
258 self.Session().add(new) |
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2467
diff
changeset
|
259 self.Session().commit() |
1418 | 260 |
261 response = self.app.post(url(controller='login', | |
262 action='password_reset'), | |
2467
4419551b2915
Switched forms to new validators
Marcin Kuzminski <marcin@python-works.com>
parents:
2248
diff
changeset
|
263 {'email': email, }) |
1418 | 264 |
265 self.checkSessionFlash(response, 'Your password reset link was sent') | |
266 | |
267 response = response.follow() | |
268 | |
269 # BAD KEY | |
270 | |
271 key = "bad" | |
272 response = self.app.get(url(controller='login', | |
273 action='password_reset_confirmation', | |
274 key=key)) | |
275 self.assertEqual(response.status, '302 Found') | |
276 self.assertTrue(response.location.endswith(url('reset_password'))) | |
277 | |
278 # GOOD KEY | |
279 | |
1530
04027bdb876c
Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1481
diff
changeset
|
280 key = User.get_by_username(username).api_key |
1418 | 281 response = self.app.get(url(controller='login', |
282 action='password_reset_confirmation', | |
283 key=key)) | |
284 self.assertEqual(response.status, '302 Found') | |
285 self.assertTrue(response.location.endswith(url('login_home'))) | |
286 | |
287 self.checkSessionFlash(response, | |
288 ('Your password reset was successful, ' | |
289 'new password has been sent to your email')) | |
290 | |
291 response = response.follow() |