Commit | Line | Data |
---|---|---|
c8ccd23e | 1 | # GNU MediaGoblin -- federated, autonomous media hosting |
cf29e8a8 | 2 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. |
c8ccd23e JK |
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 | |
9754802d | 18 | from mediagoblin.tests.tools import setup_fresh_app, fixture_add_user |
c8ccd23e | 19 | from mediagoblin.tools import template |
9754802d | 20 | from mediagoblin.auth.lib import bcrypt_check_password |
c8ccd23e JK |
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 | |
9754802d | 27 | test_user = fixture_add_user() |
c8ccd23e JK |
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( | |
b48abba3 | 37 | '/edit/account/', { |
c8ccd23e JK |
38 | 'old_password': 'toast', |
39 | 'new_password': '123456', | |
252eaf21 | 40 | 'wants_comment_notification': 'y' |
b48abba3 | 41 | }) |
c8ccd23e JK |
42 | |
43 | # test_user has to be fetched again in order to have the current values | |
394512fb | 44 | test_user = mg_globals.database.User.one({'username': u'chris'}) |
c8ccd23e | 45 | |
4ec5717a | 46 | assert bcrypt_check_password('123456', test_user.pw_hash) |
c8ccd23e JK |
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( | |
b48abba3 | 52 | '/edit/account/', { |
c8ccd23e JK |
53 | 'old_password': 'toast', |
54 | 'new_password': '098765', | |
b48abba3 | 55 | }) |
c8ccd23e | 56 | |
394512fb | 57 | test_user = mg_globals.database.User.one({'username': u'chris'}) |
c8ccd23e | 58 | |
4ec5717a | 59 | assert not bcrypt_check_password('098765', test_user.pw_hash) |
c8ccd23e JK |
60 | |
61 | ||
62 | @setup_fresh_app | |
63 | def change_bio_url(test_app): | |
64 | """Test changing bio and URL""" | |
65 | # set up new user | |
9754802d | 66 | test_user = fixture_add_user() |
c8ccd23e JK |
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 | ||
394512fb | 74 | test_user = mg_globals.database.User.one({'username': u'chris'}) |
c8ccd23e | 75 | |
4ec5717a E |
76 | assert test_user.bio == u'I love toast!' |
77 | assert test_user.url == u'http://dustycloud.org/' | |
c8ccd23e JK |
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 | ||
394512fb | 88 | test_user = mg_globals.database.User.one({'username': u'chris'}) |
c8ccd23e JK |
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 |