Mercurial > kallithea
comparison rhodecode/tests/functional/test_my_account.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3ยง14 and other relevant sections of GPLv3.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:03:13 -0400 |
parents | |
children | da3c57422ee6 |
comparison
equal
deleted
inserted
replaced
4115:8b7294a804a0 | 4116:ffd45b185016 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 from rhodecode.model.db import User, UserFollowing, Repository, UserApiKeys | |
4 from rhodecode.tests import * | |
5 from rhodecode.tests.fixture import Fixture | |
6 from rhodecode.lib import helpers as h | |
7 from rhodecode.model.user import UserModel | |
8 from rhodecode.model.meta import Session | |
9 | |
10 fixture = Fixture() | |
11 | |
12 | |
13 class TestMyAccountController(TestController): | |
14 test_user_1 = 'testme' | |
15 | |
16 @classmethod | |
17 def teardown_class(cls): | |
18 if User.get_by_username(cls.test_user_1): | |
19 UserModel().delete(cls.test_user_1) | |
20 Session().commit() | |
21 | |
22 def test_my_account(self): | |
23 self.log_user() | |
24 response = self.app.get(url('my_account')) | |
25 | |
26 response.mustcontain('value="test_admin') | |
27 | |
28 def test_my_account_my_repos(self): | |
29 self.log_user() | |
30 response = self.app.get(url('my_account_repos')) | |
31 cnt = Repository.query().filter(Repository.user == | |
32 User.get_by_username(TEST_USER_ADMIN_LOGIN)).count() | |
33 response.mustcontain('"totalRecords": %s' % cnt) | |
34 | |
35 def test_my_account_my_watched(self): | |
36 self.log_user() | |
37 response = self.app.get(url('my_account_watched')) | |
38 | |
39 cnt = UserFollowing.query().filter(UserFollowing.user == | |
40 User.get_by_username(TEST_USER_ADMIN_LOGIN)).count() | |
41 response.mustcontain('"totalRecords": %s' % cnt) | |
42 | |
43 def test_my_account_my_pullrequests(self): | |
44 self.log_user() | |
45 response = self.app.get(url('my_account_pullrequests')) | |
46 | |
47 response.mustcontain('Nothing here yet') | |
48 | |
49 def test_my_account_my_emails(self): | |
50 self.log_user() | |
51 response = self.app.get(url('my_account_emails')) | |
52 response.mustcontain('No additional emails specified') | |
53 | |
54 def test_my_account_my_emails_add_existing_email(self): | |
55 self.log_user() | |
56 response = self.app.get(url('my_account_emails')) | |
57 response.mustcontain('No additional emails specified') | |
58 response = self.app.post(url('my_account_emails'), | |
59 {'new_email': TEST_USER_REGULAR_EMAIL}) | |
60 self.checkSessionFlash(response, 'This e-mail address is already taken') | |
61 | |
62 def test_my_account_my_emails_add_mising_email_in_form(self): | |
63 self.log_user() | |
64 response = self.app.get(url('my_account_emails')) | |
65 response.mustcontain('No additional emails specified') | |
66 response = self.app.post(url('my_account_emails'),) | |
67 self.checkSessionFlash(response, 'Please enter an email address') | |
68 | |
69 def test_my_account_my_emails_add_remove(self): | |
70 self.log_user() | |
71 response = self.app.get(url('my_account_emails')) | |
72 response.mustcontain('No additional emails specified') | |
73 | |
74 response = self.app.post(url('my_account_emails'), | |
75 {'new_email': 'foo@barz.com'}) | |
76 | |
77 response = self.app.get(url('my_account_emails')) | |
78 | |
79 from rhodecode.model.db import UserEmailMap | |
80 email_id = UserEmailMap.query()\ | |
81 .filter(UserEmailMap.user == User.get_by_username(TEST_USER_ADMIN_LOGIN))\ | |
82 .filter(UserEmailMap.email == 'foo@barz.com').one().email_id | |
83 | |
84 response.mustcontain('foo@barz.com') | |
85 response.mustcontain('<input id="del_email_id" name="del_email_id" type="hidden" value="%s" />' % email_id) | |
86 | |
87 response = self.app.post(url('my_account_emails'), | |
88 {'del_email_id': email_id, '_method': 'delete'}) | |
89 self.checkSessionFlash(response, 'Removed email from user') | |
90 response = self.app.get(url('my_account_emails')) | |
91 response.mustcontain('No additional emails specified') | |
92 | |
93 | |
94 @parameterized.expand( | |
95 [('firstname', {'firstname': 'new_username'}), | |
96 ('lastname', {'lastname': 'new_username'}), | |
97 ('admin', {'admin': True}), | |
98 ('admin', {'admin': False}), | |
99 ('extern_type', {'extern_type': 'ldap'}), | |
100 ('extern_type', {'extern_type': None}), | |
101 #('extern_name', {'extern_name': 'test'}), | |
102 #('extern_name', {'extern_name': None}), | |
103 ('active', {'active': False}), | |
104 ('active', {'active': True}), | |
105 ('email', {'email': 'some@email.com'}), | |
106 # ('new_password', {'new_password': 'foobar123', | |
107 # 'password_confirmation': 'foobar123'}) | |
108 ]) | |
109 def test_my_account_update(self, name, attrs): | |
110 usr = fixture.create_user(self.test_user_1, password='qweqwe', | |
111 email='testme@rhodecode.org', | |
112 extern_type='rhodecode', | |
113 extern_name=self.test_user_1, | |
114 skip_if_exists=True) | |
115 params = usr.get_api_data() # current user data | |
116 user_id = usr.user_id | |
117 self.log_user(username=self.test_user_1, password='qweqwe') | |
118 | |
119 params.update({'password_confirmation': ''}) | |
120 params.update({'new_password': ''}) | |
121 params.update({'extern_type': 'rhodecode'}) | |
122 params.update({'extern_name': self.test_user_1}) | |
123 | |
124 params.update(attrs) | |
125 response = self.app.post(url('my_account'), params) | |
126 | |
127 self.checkSessionFlash(response, | |
128 'Your account was updated successfully') | |
129 | |
130 updated_user = User.get_by_username(self.test_user_1) | |
131 updated_params = updated_user.get_api_data() | |
132 updated_params.update({'password_confirmation': ''}) | |
133 updated_params.update({'new_password': ''}) | |
134 | |
135 params['last_login'] = updated_params['last_login'] | |
136 if name == 'email': | |
137 params['emails'] = [attrs['email']] | |
138 if name == 'extern_type': | |
139 #cannot update this via form, expected value is original one | |
140 params['extern_type'] = "rhodecode" | |
141 if name == 'extern_name': | |
142 #cannot update this via form, expected value is original one | |
143 params['extern_name'] = str(user_id) | |
144 if name == 'active': | |
145 #my account cannot deactivate account | |
146 params['active'] = True | |
147 if name == 'admin': | |
148 #my account cannot make you an admin ! | |
149 params['admin'] = False | |
150 | |
151 self.assertEqual(params, updated_params) | |
152 | |
153 def test_my_account_update_err_email_exists(self): | |
154 self.log_user() | |
155 | |
156 new_email = 'test_regular@mail.com' # already exisitn email | |
157 response = self.app.post(url('my_account'), | |
158 params=dict( | |
159 username='test_admin', | |
160 new_password='test12', | |
161 password_confirmation='test122', | |
162 firstname='NewName', | |
163 lastname='NewLastname', | |
164 email=new_email,) | |
165 ) | |
166 | |
167 response.mustcontain('This e-mail address is already taken') | |
168 | |
169 def test_my_account_update_err(self): | |
170 self.log_user('test_regular2', 'test12') | |
171 | |
172 new_email = 'newmail.pl' | |
173 response = self.app.post(url('my_account'), | |
174 params=dict( | |
175 username='test_admin', | |
176 new_password='test12', | |
177 password_confirmation='test122', | |
178 firstname='NewName', | |
179 lastname='NewLastname', | |
180 email=new_email,)) | |
181 | |
182 response.mustcontain('An email address must contain a single @') | |
183 from rhodecode.model import validators | |
184 msg = validators.ValidUsername(edit=False, old_data={})\ | |
185 ._messages['username_exists'] | |
186 msg = h.html_escape(msg % {'username': 'test_admin'}) | |
187 response.mustcontain(u"%s" % msg) | |
188 | |
189 def test_my_account_api_keys(self): | |
190 usr = self.log_user('test_regular2', 'test12') | |
191 user = User.get(usr['user_id']) | |
192 response = self.app.get(url('my_account_api_keys')) | |
193 response.mustcontain(user.api_key) | |
194 response.mustcontain('expires: never') | |
195 | |
196 @parameterized.expand([ | |
197 ('forever', -1), | |
198 ('5mins', 60*5), | |
199 ('30days', 60*60*24*30), | |
200 ]) | |
201 def test_my_account_add_api_keys(self, desc, lifetime): | |
202 usr = self.log_user('test_regular2', 'test12') | |
203 user = User.get(usr['user_id']) | |
204 response = self.app.post(url('my_account_api_keys'), | |
205 {'description': desc, 'lifetime': lifetime}) | |
206 self.checkSessionFlash(response, 'Api key successfully created') | |
207 try: | |
208 response = response.follow() | |
209 user = User.get(usr['user_id']) | |
210 for api_key in user.api_keys: | |
211 response.mustcontain(api_key) | |
212 finally: | |
213 for api_key in UserApiKeys.query().all(): | |
214 Session().delete(api_key) | |
215 Session().commit() | |
216 | |
217 def test_my_account_remove_api_key(self): | |
218 usr = self.log_user('test_regular2', 'test12') | |
219 user = User.get(usr['user_id']) | |
220 response = self.app.post(url('my_account_api_keys'), | |
221 {'description': 'desc', 'lifetime': -1}) | |
222 self.checkSessionFlash(response, 'Api key successfully created') | |
223 response = response.follow() | |
224 | |
225 #now delete our key | |
226 keys = UserApiKeys.query().all() | |
227 self.assertEqual(1, len(keys)) | |
228 | |
229 response = self.app.post(url('my_account_api_keys'), | |
230 {'_method': 'delete', 'del_api_key': keys[0].api_key}) | |
231 self.checkSessionFlash(response, 'Api key successfully deleted') | |
232 keys = UserApiKeys.query().all() | |
233 self.assertEqual(0, len(keys)) | |
234 | |
235 | |
236 def test_my_account_reset_main_api_key(self): | |
237 usr = self.log_user('test_regular2', 'test12') | |
238 user = User.get(usr['user_id']) | |
239 api_key = user.api_key | |
240 response = self.app.get(url('my_account_api_keys')) | |
241 response.mustcontain(api_key) | |
242 response.mustcontain('expires: never') | |
243 | |
244 response = self.app.post(url('my_account_api_keys'), | |
245 {'_method': 'delete', 'del_api_key_builtin': api_key}) | |
246 self.checkSessionFlash(response, 'Api key successfully reset') | |
247 response = response.follow() | |
248 response.mustcontain(no=[api_key]) |