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', | |
b48abba3 | 40 | }) |
c8ccd23e JK |
41 | |
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'}) | |
44 | ||
4ec5717a | 45 | assert bcrypt_check_password('123456', test_user.pw_hash) |
c8ccd23e JK |
46 | |
47 | # test that the password cannot be changed if the given old_password | |
48 | # is wrong | |
49 | # template.clear_test_template_context() | |
50 | test_app.post( | |
b48abba3 | 51 | '/edit/account/', { |
c8ccd23e JK |
52 | 'old_password': 'toast', |
53 | 'new_password': '098765', | |
b48abba3 | 54 | }) |
c8ccd23e JK |
55 | |
56 | test_user = mg_globals.database.User.one({'username': 'chris'}) | |
57 | ||
4ec5717a | 58 | assert not bcrypt_check_password('098765', test_user.pw_hash) |
c8ccd23e JK |
59 | |
60 | ||
61 | @setup_fresh_app | |
62 | def change_bio_url(test_app): | |
63 | """Test changing bio and URL""" | |
64 | # set up new user | |
9754802d | 65 | test_user = fixture_add_user() |
c8ccd23e JK |
66 | |
67 | # test changing the bio and the URL properly | |
68 | test_app.post( | |
69 | '/edit/profile/', { | |
70 | 'bio': u'I love toast!', | |
71 | 'url': u'http://dustycloud.org/'}) | |
72 | ||
73 | test_user = mg_globals.database.User.one({'username': 'chris'}) | |
74 | ||
4ec5717a E |
75 | assert test_user.bio == u'I love toast!' |
76 | assert test_user.url == u'http://dustycloud.org/' | |
c8ccd23e JK |
77 | |
78 | # test changing the bio and the URL inproperly | |
79 | too_long_bio = 150 * 'T' + 150 * 'o' + 150 * 'a' + 150 * 's' + 150* 't' | |
80 | ||
81 | test_app.post( | |
82 | '/edit/profile/', { | |
83 | # more than 500 characters | |
84 | 'bio': too_long_bio, | |
85 | 'url': 'this-is-no-url'}) | |
86 | ||
87 | test_user = mg_globals.database.User.one({'username': 'chris'}) | |
88 | ||
89 | context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/edit/edit_profile.html'] | |
90 | form = context['edit_profile_form'] | |
91 | ||
92 | assert form.bio.errors == [u'Field must be between 0 and 500 characters long.'] | |
93 | assert form.url.errors == [u'Improperly formed URL'] | |
94 | ||
95 | # test changing the url inproperly |