def test_manage_disable_modules(self): from ptah.manage.manage import \ module, PtahModule, PtahManageRoute, ManageView, set_access_manager @module('test-module') class TestModule(PtahModule): """ module description """ title = 'Test module' def accessManager(id, request): return True self.init_ptah() set_access_manager(accessManager) ptah.auth_service.set_userid('test-user') cfg = ptah.get_settings(ptah.CFG_ID_PTAH, self.registry) cfg['disable_modules'] = ('test-module', ) request = DummyRequest() route = PtahManageRoute(request) view = ManageView(route, request) view.update() for mod in view.modules: self.assertFalse(isinstance(mod, TestModule))
def test_manage_view(self): from ptah.manage.manage import \ module, PtahModule, PtahManageRoute, ManageView, \ set_access_manager @module('test-module') class TestModule(PtahModule): """ module description """ title = 'Test module' def accessManager(id, request): return True self.init_ptah() set_access_manager(accessManager) ptah.auth_service.set_userid('test-user') route = PtahManageRoute(self.request) v = ManageView(route, self.request) v.update() self.assertIsInstance(v.modules[-1], TestModule)
def test_manage_view_unavailable(self): from ptah.manage.manage import \ module, PtahModule, PtahManageRoute, ManageView, \ set_access_manager @module('test-module') class TestModule(PtahModule): """ module description """ title = 'Test module' def available(self): return False def accessManager(id, request): return True self.init_ptah() set_access_manager(accessManager) ptah.auth_service.set_userid('test-user') route = PtahManageRoute(self.request) v = ManageView(route, self.request) v.update() found = False for mod in v.modules: if isinstance(mod, TestModule): # pragma: no cover found = True self.assertFalse(found)
def test_manage_enable_modules(self): from ptah.manage.manage import \ module, PtahModule, PtahManageRoute, ManageView, set_access_manager @module('test-module1') class TestModule1(PtahModule): title = 'Test module1' @module('test-module2') class TestModule2(PtahModule): title = 'Test module2' def accessManager(id, request): return True self.init_ptah() set_access_manager(accessManager) ptah.auth_service.set_userid('test-user') cfg = ptah.get_settings(ptah.CFG_ID_PTAH, self.registry) cfg['enable_modules'] = ('test-module1',) request = DummyRequest() route = PtahManageRoute(request) view = ManageView(route, request) view.update() self.assertEqual(len(view.modules), 1) self.assertTrue(isinstance(view.modules[0], TestModule1)) cfg['enable_modules'] = ('test-module2',) view = ManageView(route, request) view.update() self.assertEqual(len(view.modules), 1) self.assertTrue(isinstance(view.modules[0], TestModule2))