These are changes for issue #405, add email comment notification.
[mediagoblin.git] / mediagoblin / tests / test_edit.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
3 #
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.
8 #
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.
13 #
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/>.
16
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
21
22
23 @setup_fresh_app
24 def test_change_password(test_app):
25 """Test changing password correctly and incorrectly"""
26 # set up new user
27 test_user = fixture_add_user()
28
29 test_app.post(
30 '/auth/login/', {
31 'username': u'chris',
32 'password': 'toast'})
33
34 # test that the password can be changed
35 # template.clear_test_template_context()
36 test_app.post(
37 '/edit/account/', {
38 'old_password': 'toast',
39 'new_password': '123456',
40 'wants_comment_notification': 'y'
41 })
42
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'})
45
46 assert bcrypt_check_password('123456', test_user.pw_hash)
47
48 # test that the password cannot be changed if the given old_password
49 # is wrong
50 # template.clear_test_template_context()
51 test_app.post(
52 '/edit/account/', {
53 'old_password': 'toast',
54 'new_password': '098765',
55 })
56
57 test_user = mg_globals.database.User.one({'username': 'chris'})
58
59 assert not bcrypt_check_password('098765', test_user.pw_hash)
60
61
62 @setup_fresh_app
63 def change_bio_url(test_app):
64 """Test changing bio and URL"""
65 # set up new user
66 test_user = fixture_add_user()
67
68 # test changing the bio and the URL properly
69 test_app.post(
70 '/edit/profile/', {
71 'bio': u'I love toast!',
72 'url': u'http://dustycloud.org/'})
73
74 test_user = mg_globals.database.User.one({'username': 'chris'})
75
76 assert test_user.bio == u'I love toast!'
77 assert test_user.url == u'http://dustycloud.org/'
78
79 # test changing the bio and the URL inproperly
80 too_long_bio = 150 * 'T' + 150 * 'o' + 150 * 'a' + 150 * 's' + 150* 't'
81
82 test_app.post(
83 '/edit/profile/', {
84 # more than 500 characters
85 'bio': too_long_bio,
86 'url': 'this-is-no-url'})
87
88 test_user = mg_globals.database.User.one({'username': 'chris'})
89
90 context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/edit/edit_profile.html']
91 form = context['edit_profile_form']
92
93 assert form.bio.errors == [u'Field must be between 0 and 500 characters long.']
94 assert form.url.errors == [u'Improperly formed URL']
95
96 # test changing the url inproperly