settings: fixed found problem on new admin pyramid views, and made all test pass for them.
This commit is contained in:
parent
17e7992166
commit
e9a7b71fcc
3 changed files with 93 additions and 47 deletions
|
|
@ -90,7 +90,7 @@ class AdminSessionSettingsView(AdminSettingsView):
|
|||
self.request.session.flash(
|
||||
_('Cleaned up old sessions'), queue='success')
|
||||
except user_sessions.CleanupCommand as msg:
|
||||
self.request.session.flash(msg, category='warning')
|
||||
self.request.session.flash(msg.message, queue='warning')
|
||||
except Exception as e:
|
||||
log.exception('Failed session cleanup')
|
||||
self.request.session.flash(
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class AdminSystemInfoSettingsView(AdminSettingsView):
|
|||
@view_config(
|
||||
route_name='admin_settings_system', request_method='GET',
|
||||
renderer='rhodecode:templates/admin/settings/settings.mako')
|
||||
def settings_sessions(self):
|
||||
def settings_system_info(self):
|
||||
_ = self.request.translate
|
||||
|
||||
c.active = 'system'
|
||||
|
|
@ -169,7 +169,7 @@ class AdminSystemInfoSettingsView(AdminSettingsView):
|
|||
@view_config(
|
||||
route_name='admin_settings_system_update', request_method='GET',
|
||||
renderer='rhodecode:templates/admin/settings/settings_system_update.mako')
|
||||
def settings_sessions_cleanup(self):
|
||||
def settings_system_info_check_update(self):
|
||||
_ = self.request.translate
|
||||
|
||||
update_url = self.get_update_url()
|
||||
|
|
@ -179,9 +179,11 @@ class AdminSystemInfoSettingsView(AdminSettingsView):
|
|||
data = self.get_update_data(update_url)
|
||||
except urllib2.URLError as e:
|
||||
log.exception("Exception contacting upgrade server")
|
||||
self.request.override_renderer = 'string'
|
||||
return _err('Failed to contact upgrade server: %r' % e)
|
||||
except ValueError as e:
|
||||
log.exception("Bad data sent from update server")
|
||||
self.request.override_renderer = 'string'
|
||||
return _err('Bad data sent from update server')
|
||||
|
||||
latest = data['versions'][0]
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ from rhodecode.tests.utils import AssertResponse
|
|||
|
||||
|
||||
UPDATE_DATA_QUALNAME = (
|
||||
'rhodecode.controllers.admin.settings.SettingsController.get_update_data')
|
||||
'rhodecode.admin.views.system_info.AdminSystemInfoSettingsView.get_update_data')
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('autologin_user', 'app')
|
||||
class TestAdminSettingsController:
|
||||
class TestAdminSettingsController(object):
|
||||
|
||||
@pytest.mark.parametrize('urlname', [
|
||||
'admin_settings_vcs',
|
||||
|
|
@ -46,7 +46,6 @@ class TestAdminSettingsController:
|
|||
'admin_settings_email',
|
||||
'admin_settings_hooks',
|
||||
'admin_settings_search',
|
||||
'admin_settings_system',
|
||||
])
|
||||
def test_simple_get(self, urlname, app):
|
||||
app.get(url(urlname))
|
||||
|
|
@ -85,46 +84,9 @@ class TestAdminSettingsController:
|
|||
response.mustcontain(no=['test_hooks_2'])
|
||||
response.mustcontain(no=['cd /tmp2'])
|
||||
|
||||
def test_system_update_new_version(self):
|
||||
update_data = {
|
||||
'versions': [
|
||||
{
|
||||
'version': '100.3.1415926535',
|
||||
'general': 'The latest version we are ever going to ship'
|
||||
},
|
||||
{
|
||||
'version': '0.0.0',
|
||||
'general': 'The first version we ever shipped'
|
||||
}
|
||||
]
|
||||
}
|
||||
with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
|
||||
response = self.app.get(url('admin_settings_system_update'))
|
||||
response.mustcontain('A <b>new version</b> is available')
|
||||
|
||||
def test_system_update_nothing_new(self):
|
||||
update_data = {
|
||||
'versions': [
|
||||
{
|
||||
'version': '0.0.0',
|
||||
'general': 'The first version we ever shipped'
|
||||
}
|
||||
]
|
||||
}
|
||||
with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
|
||||
response = self.app.get(url('admin_settings_system_update'))
|
||||
response.mustcontain(
|
||||
'You already have the <b>latest</b> stable version.')
|
||||
|
||||
def test_system_update_bad_response(self):
|
||||
with mock.patch(UPDATE_DATA_QUALNAME, side_effect=ValueError('foo')):
|
||||
response = self.app.get(url('admin_settings_system_update'))
|
||||
response.mustcontain(
|
||||
'Bad data sent from update server')
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('autologin_user', 'app')
|
||||
class TestAdminSettingsGlobal:
|
||||
class TestAdminSettingsGlobal(object):
|
||||
|
||||
def test_pre_post_code_code_active(self, csrf_token):
|
||||
pre_code = 'rc-pre-code-187652122'
|
||||
|
|
@ -211,7 +173,7 @@ class TestAdminSettingsGlobal:
|
|||
|
||||
|
||||
@pytest.mark.usefixtures('autologin_user', 'app')
|
||||
class TestAdminSettingsVcs:
|
||||
class TestAdminSettingsVcs(object):
|
||||
|
||||
def test_contains_svn_default_patterns(self, app):
|
||||
response = app.get(url('admin_settings_vcs'))
|
||||
|
|
@ -463,7 +425,7 @@ class TestOpenSourceLicenses(object):
|
|||
}
|
||||
}
|
||||
read_licenses_patch = mock.patch(
|
||||
'rhodecode.admin.views.read_opensource_licenses',
|
||||
'rhodecode.admin.views.open_source_licenses.read_opensource_licenses',
|
||||
return_value=sample_licenses)
|
||||
with read_licenses_patch:
|
||||
response = self.app.get(self._get_url(), status=200)
|
||||
|
|
@ -486,8 +448,90 @@ class TestOpenSourceLicenses(object):
|
|||
self.app.get(self._get_url(), status=403)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('app')
|
||||
class TestUserSessions(object):
|
||||
|
||||
def _get_url(self, name='admin_settings_sessions'):
|
||||
return {
|
||||
'admin_settings_sessions': ADMIN_PREFIX + '/settings/sessions',
|
||||
'admin_settings_sessions_cleanup': ADMIN_PREFIX + '/settings/sessions/cleanup'
|
||||
}[name]
|
||||
|
||||
def test_forbidden_when_normal_user(self, autologin_regular_user):
|
||||
self.app.get(self._get_url(), status=403)
|
||||
|
||||
def test_show_sessions_page(self, autologin_user):
|
||||
response = self.app.get(self._get_url(), status=200)
|
||||
response.mustcontain('file')
|
||||
|
||||
def test_cleanup_old_sessions(self, autologin_user, csrf_token):
|
||||
|
||||
post_data = {
|
||||
'csrf_token': csrf_token,
|
||||
'expire_days': '60'
|
||||
}
|
||||
response = self.app.post(
|
||||
self._get_url('admin_settings_sessions_cleanup'), params=post_data,
|
||||
status=302)
|
||||
assert_session_flash(response, 'Please execute this command')
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('app')
|
||||
class TestAdminSystemInfo(object):
|
||||
def _get_url(self, name='admin_settings_system'):
|
||||
return {
|
||||
'admin_settings_system': ADMIN_PREFIX + '/settings/system',
|
||||
'admin_settings_system_update': ADMIN_PREFIX + '/settings/system/updates',
|
||||
}[name]
|
||||
|
||||
def test_forbidden_when_normal_user(self, autologin_regular_user):
|
||||
self.app.get(self._get_url(), status=403)
|
||||
|
||||
def test_system_info_page(self, autologin_user):
|
||||
response = self.app.get(self._get_url())
|
||||
response.mustcontain('RhodeCode Community Edition, version {}'.format(
|
||||
rhodecode.__version__))
|
||||
|
||||
def test_system_update_new_version(self, autologin_user):
|
||||
update_data = {
|
||||
'versions': [
|
||||
{
|
||||
'version': '100.3.1415926535',
|
||||
'general': 'The latest version we are ever going to ship'
|
||||
},
|
||||
{
|
||||
'version': '0.0.0',
|
||||
'general': 'The first version we ever shipped'
|
||||
}
|
||||
]
|
||||
}
|
||||
with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
|
||||
response = self.app.get(self._get_url('admin_settings_system_update'))
|
||||
response.mustcontain('A <b>new version</b> is available')
|
||||
|
||||
def test_system_update_nothing_new(self, autologin_user):
|
||||
update_data = {
|
||||
'versions': [
|
||||
{
|
||||
'version': '0.0.0',
|
||||
'general': 'The first version we ever shipped'
|
||||
}
|
||||
]
|
||||
}
|
||||
with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
|
||||
response = self.app.get(self._get_url('admin_settings_system_update'))
|
||||
response.mustcontain(
|
||||
'You already have the <b>latest</b> stable version.')
|
||||
|
||||
def test_system_update_bad_response(self, autologin_user):
|
||||
with mock.patch(UPDATE_DATA_QUALNAME, side_effect=ValueError('foo')):
|
||||
response = self.app.get(self._get_url('admin_settings_system_update'))
|
||||
response.mustcontain(
|
||||
'Bad data sent from update server')
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("app")
|
||||
class TestAdminSettingsIssueTracker:
|
||||
class TestAdminSettingsIssueTracker(object):
|
||||
RC_PREFIX = 'rhodecode_'
|
||||
SHORT_PATTERN_KEY = 'issuetracker_pat_'
|
||||
PATTERN_KEY = RC_PREFIX + SHORT_PATTERN_KEY
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue