Exemplo n.º 1
0
    def setUp(self):
        _BaseTestCase.setUp(self)

        self.cfg_panel_template = 'admin_accountsconfig.html'
        self.user_panel_template = 'admin_users.html'

        self.env.config.set('account-manager', 'password_store',
                            'SessionStore')
        self.admin = AccountManagerAdminPanel(self.env)
        self.bad_check = BadCheck(self.env)
        self.basic_check = BasicCheck(self.env)
        self.dummy_check = DummyCheck(self.env)
        self.store = SessionStore(self.env)
Exemplo n.º 2
0
class AccountManagerAdminPanelTestCase(_BaseTestCase):
    def setUp(self):
        _BaseTestCase.setUp(self)

        self.cfg_panel_template = 'admin_accountsconfig.html'
        self.user_panel_template = 'admin_users.html'

        self.env.config.set('account-manager', 'password_store',
                            'SessionStore')
        self.admin = AccountManagerAdminPanel(self.env)
        self.bad_check = BadCheck(self.env)
        self.basic_check = BasicCheck(self.env)
        self.dummy_check = DummyCheck(self.env)
        self.store = SessionStore(self.env)

    def test_render_cfg_admin_panel(self):
        # Default configuration - all registration checks enabled.
        self.req.args['active'] = '3'
        response = self.admin.render_admin_panel(self.req, 'accounts',
                                                 'config', '')
        # Panel must use the appropriate template.
        self.assertEqual(response[0], self.cfg_panel_template)
        self._assert_no_msg(self.req)

        # Doc-string extraction must work.
        self.env.config.set('account-manager', 'register_check', 'DummyCheck')
        response = self.admin.render_admin_panel(self.req, 'accounts',
                                                 'config', '')
        check_list = response[1].get('check_list', [])
        self.assertEqual([check['doc'] for check in check_list
                          if check['classname'] == 'DummyCheck'],
                         ['A dummy check for unit-testing the interface.'])
        self.assertEqual(response[0], self.cfg_panel_template)
        self._assert_no_msg(self.req)

        # Even using badly defined checks should not stop panel rendering.
        self.env.config.set('account-manager', 'register_check',
                            'BadCheck, DisabledCheck')
        response = self.admin.render_admin_panel(self.req, 'accounts',
                                                 'config', '')
        self.assertEqual(response[1].get('disabled_check'),
                         frozenset(['DisabledCheck']))
        self.assertEqual(response[0], self.cfg_panel_template)
        self._assert_no_msg(self.req)

        # Another custom configuration: No check at all, if you insist.
        self.env.config.set('account-manager', 'register_check', '')
        self.assertFalse(self.acctmgr.register_checks)
        response = self.admin.render_admin_panel(self.req, 'accounts',
                                                 'config', '')
        self.assertEqual(response[0], self.cfg_panel_template)
        self._assert_no_msg(self.req)

    def test_render_user_admin_panel(self):
        response = self.admin.render_admin_panel(self.req, 'accounts',
                                                 'users', '')
        # Panel must use the appropriate template.
        self.assertEqual(response[0], self.user_panel_template)
        self._assert_no_msg(self.req)

    def _assert_no_msg(self, req):
        self.assertEqual(req.chrome['notices'], [])
        self.assertEqual(req.chrome['warnings'], [])