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',
42 # test_user has to be fetched again in order to have the current values
43 test_user
= mg_globals
.database
.User
.one({'username': 'chris'})
45 assert bcrypt_check_password('123456', test_user
.pw_hash
)
47 # test that the password cannot be changed if the given old_password
49 # template.clear_test_template_context()
52 'old_password': 'toast',
53 'new_password': '098765',
56 test_user
= mg_globals
.database
.User
.one({'username': 'chris'})
58 assert not bcrypt_check_password('098765', test_user
.pw_hash
)
62 def change_bio_url(test_app
):
63 """Test changing bio and URL"""
65 test_user
= fixture_add_user()
67 # test changing the bio and the URL properly
70 'bio': u
'I love toast!',
71 'url': u
'http://dustycloud.org/'})
73 test_user
= mg_globals
.database
.User
.one({'username': 'chris'})
75 assert test_user
.bio
== u
'I love toast!'
76 assert test_user
.url
== u
'http://dustycloud.org/'
78 # test changing the bio and the URL inproperly
79 too_long_bio
= 150 * 'T' + 150 * 'o' + 150 * 'a' + 150 * 's' + 150* 't'
83 # more than 500 characters
85 'url': 'this-is-no-url'})
87 test_user
= mg_globals
.database
.User
.one({'username': 'chris'})
89 context
= template
.TEMPLATE_TEST_CONTEXT
['mediagoblin/edit/edit_profile.html']
90 form
= context
['edit_profile_form']
92 assert form
.bio
.errors
== [u
'Field must be between 0 and 500 characters long.']
93 assert form
.url
.errors
== [u
'Improperly formed URL']
95 # test changing the url inproperly