1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from mediagoblin
import mg_globals
18 from mediagoblin
.tests
.tools
import setup_fresh_app
, fixture_add_user
19 from mediagoblin
.tools
import template
20 from mediagoblin
.auth
.lib
import bcrypt_check_password
24 def test_change_password(test_app
):
25 """Test changing password correctly and incorrectly"""
27 test_user
= fixture_add_user()
34 # test that the password can be changed
35 # template.clear_test_template_context()
38 'old_password': 'toast',
39 'new_password': '123456',
40 'wants_comment_notification': 'y'
43 # test_user has to be fetched again in order to have the current values
44 test_user
= mg_globals
.database
.User
.one({'username': 'chris'})
46 assert bcrypt_check_password('123456', test_user
.pw_hash
)
48 # test that the password cannot be changed if the given old_password
50 # template.clear_test_template_context()
53 'old_password': 'toast',
54 'new_password': '098765',
57 test_user
= mg_globals
.database
.User
.one({'username': 'chris'})
59 assert not bcrypt_check_password('098765', test_user
.pw_hash
)
63 def change_bio_url(test_app
):
64 """Test changing bio and URL"""
66 test_user
= fixture_add_user()
68 # test changing the bio and the URL properly
71 'bio': u
'I love toast!',
72 'url': u
'http://dustycloud.org/'})
74 test_user
= mg_globals
.database
.User
.one({'username': 'chris'})
76 assert test_user
.bio
== u
'I love toast!'
77 assert test_user
.url
== u
'http://dustycloud.org/'
79 # test changing the bio and the URL inproperly
80 too_long_bio
= 150 * 'T' + 150 * 'o' + 150 * 'a' + 150 * 's' + 150* 't'
84 # more than 500 characters
86 'url': 'this-is-no-url'})
88 test_user
= mg_globals
.database
.User
.one({'username': 'chris'})
90 context
= template
.TEMPLATE_TEST_CONTEXT
['mediagoblin/edit/edit_profile.html']
91 form
= context
['edit_profile_form']
93 assert form
.bio
.errors
== [u
'Field must be between 0 and 500 characters long.']
94 assert form
.url
.errors
== [u
'Improperly formed URL']
96 # test changing the url inproperly