##// END OF EJS Templates
settings: fixed found problem on new admin pyramid views, and made all test pass for them.
marcink -
r1313:8df63e5b default
parent child Browse files
Show More
@@ -90,7 +90,7 b' class AdminSessionSettingsView(AdminSett'
90 90 self.request.session.flash(
91 91 _('Cleaned up old sessions'), queue='success')
92 92 except user_sessions.CleanupCommand as msg:
93 self.request.session.flash(msg, category='warning')
93 self.request.session.flash(msg.message, queue='warning')
94 94 except Exception as e:
95 95 log.exception('Failed session cleanup')
96 96 self.request.session.flash(
@@ -63,7 +63,7 b' class AdminSystemInfoSettingsView(AdminS'
63 63 @view_config(
64 64 route_name='admin_settings_system', request_method='GET',
65 65 renderer='rhodecode:templates/admin/settings/settings.mako')
66 def settings_sessions(self):
66 def settings_system_info(self):
67 67 _ = self.request.translate
68 68
69 69 c.active = 'system'
@@ -169,7 +169,7 b' class AdminSystemInfoSettingsView(AdminS'
169 169 @view_config(
170 170 route_name='admin_settings_system_update', request_method='GET',
171 171 renderer='rhodecode:templates/admin/settings/settings_system_update.mako')
172 def settings_sessions_cleanup(self):
172 def settings_system_info_check_update(self):
173 173 _ = self.request.translate
174 174
175 175 update_url = self.get_update_url()
@@ -179,9 +179,11 b' class AdminSystemInfoSettingsView(AdminS'
179 179 data = self.get_update_data(update_url)
180 180 except urllib2.URLError as e:
181 181 log.exception("Exception contacting upgrade server")
182 self.request.override_renderer = 'string'
182 183 return _err('Failed to contact upgrade server: %r' % e)
183 184 except ValueError as e:
184 185 log.exception("Bad data sent from update server")
186 self.request.override_renderer = 'string'
185 187 return _err('Bad data sent from update server')
186 188
187 189 latest = data['versions'][0]
@@ -32,11 +32,11 b' from rhodecode.tests.utils import Assert'
32 32
33 33
34 34 UPDATE_DATA_QUALNAME = (
35 'rhodecode.controllers.admin.settings.SettingsController.get_update_data')
35 'rhodecode.admin.views.system_info.AdminSystemInfoSettingsView.get_update_data')
36 36
37 37
38 38 @pytest.mark.usefixtures('autologin_user', 'app')
39 class TestAdminSettingsController:
39 class TestAdminSettingsController(object):
40 40
41 41 @pytest.mark.parametrize('urlname', [
42 42 'admin_settings_vcs',
@@ -46,7 +46,6 b' class TestAdminSettingsController:'
46 46 'admin_settings_email',
47 47 'admin_settings_hooks',
48 48 'admin_settings_search',
49 'admin_settings_system',
50 49 ])
51 50 def test_simple_get(self, urlname, app):
52 51 app.get(url(urlname))
@@ -85,46 +84,9 b' class TestAdminSettingsController:'
85 84 response.mustcontain(no=['test_hooks_2'])
86 85 response.mustcontain(no=['cd /tmp2'])
87 86
88 def test_system_update_new_version(self):
89 update_data = {
90 'versions': [
91 {
92 'version': '100.3.1415926535',
93 'general': 'The latest version we are ever going to ship'
94 },
95 {
96 'version': '0.0.0',
97 'general': 'The first version we ever shipped'
98 }
99 ]
100 }
101 with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
102 response = self.app.get(url('admin_settings_system_update'))
103 response.mustcontain('A <b>new version</b> is available')
104
105 def test_system_update_nothing_new(self):
106 update_data = {
107 'versions': [
108 {
109 'version': '0.0.0',
110 'general': 'The first version we ever shipped'
111 }
112 ]
113 }
114 with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
115 response = self.app.get(url('admin_settings_system_update'))
116 response.mustcontain(
117 'You already have the <b>latest</b> stable version.')
118
119 def test_system_update_bad_response(self):
120 with mock.patch(UPDATE_DATA_QUALNAME, side_effect=ValueError('foo')):
121 response = self.app.get(url('admin_settings_system_update'))
122 response.mustcontain(
123 'Bad data sent from update server')
124
125 87
126 88 @pytest.mark.usefixtures('autologin_user', 'app')
127 class TestAdminSettingsGlobal:
89 class TestAdminSettingsGlobal(object):
128 90
129 91 def test_pre_post_code_code_active(self, csrf_token):
130 92 pre_code = 'rc-pre-code-187652122'
@@ -211,7 +173,7 b' class TestAdminSettingsGlobal:'
211 173
212 174
213 175 @pytest.mark.usefixtures('autologin_user', 'app')
214 class TestAdminSettingsVcs:
176 class TestAdminSettingsVcs(object):
215 177
216 178 def test_contains_svn_default_patterns(self, app):
217 179 response = app.get(url('admin_settings_vcs'))
@@ -463,7 +425,7 b' class TestOpenSourceLicenses(object):'
463 425 }
464 426 }
465 427 read_licenses_patch = mock.patch(
466 'rhodecode.admin.views.read_opensource_licenses',
428 'rhodecode.admin.views.open_source_licenses.read_opensource_licenses',
467 429 return_value=sample_licenses)
468 430 with read_licenses_patch:
469 431 response = self.app.get(self._get_url(), status=200)
@@ -486,8 +448,90 b' class TestOpenSourceLicenses(object):'
486 448 self.app.get(self._get_url(), status=403)
487 449
488 450
451 @pytest.mark.usefixtures('app')
452 class TestUserSessions(object):
453
454 def _get_url(self, name='admin_settings_sessions'):
455 return {
456 'admin_settings_sessions': ADMIN_PREFIX + '/settings/sessions',
457 'admin_settings_sessions_cleanup': ADMIN_PREFIX + '/settings/sessions/cleanup'
458 }[name]
459
460 def test_forbidden_when_normal_user(self, autologin_regular_user):
461 self.app.get(self._get_url(), status=403)
462
463 def test_show_sessions_page(self, autologin_user):
464 response = self.app.get(self._get_url(), status=200)
465 response.mustcontain('file')
466
467 def test_cleanup_old_sessions(self, autologin_user, csrf_token):
468
469 post_data = {
470 'csrf_token': csrf_token,
471 'expire_days': '60'
472 }
473 response = self.app.post(
474 self._get_url('admin_settings_sessions_cleanup'), params=post_data,
475 status=302)
476 assert_session_flash(response, 'Please execute this command')
477
478
479 @pytest.mark.usefixtures('app')
480 class TestAdminSystemInfo(object):
481 def _get_url(self, name='admin_settings_system'):
482 return {
483 'admin_settings_system': ADMIN_PREFIX + '/settings/system',
484 'admin_settings_system_update': ADMIN_PREFIX + '/settings/system/updates',
485 }[name]
486
487 def test_forbidden_when_normal_user(self, autologin_regular_user):
488 self.app.get(self._get_url(), status=403)
489
490 def test_system_info_page(self, autologin_user):
491 response = self.app.get(self._get_url())
492 response.mustcontain('RhodeCode Community Edition, version {}'.format(
493 rhodecode.__version__))
494
495 def test_system_update_new_version(self, autologin_user):
496 update_data = {
497 'versions': [
498 {
499 'version': '100.3.1415926535',
500 'general': 'The latest version we are ever going to ship'
501 },
502 {
503 'version': '0.0.0',
504 'general': 'The first version we ever shipped'
505 }
506 ]
507 }
508 with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
509 response = self.app.get(self._get_url('admin_settings_system_update'))
510 response.mustcontain('A <b>new version</b> is available')
511
512 def test_system_update_nothing_new(self, autologin_user):
513 update_data = {
514 'versions': [
515 {
516 'version': '0.0.0',
517 'general': 'The first version we ever shipped'
518 }
519 ]
520 }
521 with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
522 response = self.app.get(self._get_url('admin_settings_system_update'))
523 response.mustcontain(
524 'You already have the <b>latest</b> stable version.')
525
526 def test_system_update_bad_response(self, autologin_user):
527 with mock.patch(UPDATE_DATA_QUALNAME, side_effect=ValueError('foo')):
528 response = self.app.get(self._get_url('admin_settings_system_update'))
529 response.mustcontain(
530 'Bad data sent from update server')
531
532
489 533 @pytest.mark.usefixtures("app")
490 class TestAdminSettingsIssueTracker:
534 class TestAdminSettingsIssueTracker(object):
491 535 RC_PREFIX = 'rhodecode_'
492 536 SHORT_PATTERN_KEY = 'issuetracker_pat_'
493 537 PATTERN_KEY = RC_PREFIX + SHORT_PATTERN_KEY
General Comments 0
You need to be logged in to leave comments. Login now