##// END OF EJS Templates
apps: base app fixes for python3
apps: base app fixes for python3

File last commit:

r5053:8da271d0 default
r5086:62af941a default
Show More
test_password_reset.py
117 lines | 4.4 KiB | text/x-python | PythonLexer
/ rhodecode / apps / login / tests / test_password_reset.py
global-permissions: ported controller to pyramid view....
r1941
code: update copyrights to 2020
r4306 # Copyright (C) 2010-2020 RhodeCode GmbH
global-permissions: ported controller to pyramid view....
r1941 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import pytest
from rhodecode.lib import helpers as h
from rhodecode.tests import (
caches: use dogpile for sql_cache_short region.
r2883 TestController, clear_cache_regions,
global-permissions: ported controller to pyramid view....
r1941 TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS)
from rhodecode.tests.fixture import Fixture
from rhodecode.tests.utils import AssertResponse
fixture = Fixture()
def route_path(name, params=None, **kwargs):
python3: fix urllib usage
r4914 import urllib.request, urllib.parse, urllib.error
global-permissions: ported controller to pyramid view....
r1941 from rhodecode.apps._base import ADMIN_PREFIX
base_url = {
'login': ADMIN_PREFIX + '/login',
'logout': ADMIN_PREFIX + '/logout',
'register': ADMIN_PREFIX + '/register',
'reset_password':
ADMIN_PREFIX + '/password_reset',
'reset_password_confirmation':
ADMIN_PREFIX + '/password_reset_confirmation',
'admin_permissions_application':
ADMIN_PREFIX + '/permissions/application',
'admin_permissions_application_update':
ADMIN_PREFIX + '/permissions/application/update',
}[name].format(**kwargs)
if params:
python3: fix urllib usage
r4914 base_url = '{}?{}'.format(base_url, urllib.parse.urlencode(params))
global-permissions: ported controller to pyramid view....
r1941 return base_url
class TestPasswordReset(TestController):
@pytest.mark.parametrize(
'pwd_reset_setting, show_link, show_reset', [
('hg.password_reset.enabled', True, True),
('hg.password_reset.hidden', False, True),
('hg.password_reset.disabled', False, False),
])
def test_password_reset_settings(
self, pwd_reset_setting, show_link, show_reset):
caches: use dogpile for sql_cache_short region.
r2883 clear_cache_regions()
global-permissions: ported controller to pyramid view....
r1941 self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS)
params = {
'csrf_token': self.csrf_token,
'anonymous': 'True',
'default_register': 'hg.register.auto_activate',
'default_register_message': '',
'default_password_reset': pwd_reset_setting,
'default_extern_activate': 'hg.extern_activate.auto',
}
auth: login/registration changes for upcomming new rules for login using external identities....
r3386 resp = self.app.post(
route_path('admin_permissions_application_update'), params=params)
global-permissions: ported controller to pyramid view....
r1941 self.logout_user()
login_page = self.app.get(route_path('login'))
asr_login = AssertResponse(login_page)
if show_link:
asr_login.one_element_exists('a.pwd_reset')
else:
asr_login.no_element_exists('a.pwd_reset')
response = self.app.get(route_path('reset_password'))
tests: stabilize tests for mysql/postgres.
r3981 assert_response = response.assert_response()
global-permissions: ported controller to pyramid view....
r1941 if show_reset:
response.mustcontain('Send password reset email')
assert_response.one_element_exists('#email')
assert_response.one_element_exists('#send')
else:
response.mustcontain('Password reset is disabled.')
assert_response.no_element_exists('#email')
assert_response.no_element_exists('#send')
def test_password_form_disabled(self):
self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS)
params = {
'csrf_token': self.csrf_token,
'anonymous': 'True',
'default_register': 'hg.register.auto_activate',
'default_register_message': '',
'default_password_reset': 'hg.password_reset.disabled',
'default_extern_activate': 'hg.extern_activate.auto',
}
self.app.post(route_path('admin_permissions_application_update'), params=params)
self.logout_user()
response = self.app.post(
route_path('reset_password'), {'email': 'lisa@rhodecode.com',}
)
response = response.follow()
response.mustcontain('Password reset is disabled.')