Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def test_manage_view(self):
        from ptah.manage.manage import module, PtahModule, PtahManageRoute, ManageView, set_access_manager

        global TestModule

        class TestModule(PtahModule):
            """ module description """

            title = "Test module"
            module("test-module")

        def accessManager(id):
            return True

        self._init_ptah()

        set_access_manager(accessManager)
        ptah.authService.set_userid("test-user")

        request = self._makeRequest()
        route = PtahManageRoute(request)

        v = ManageView(route, request)
        v.update()

        self.assertIsInstance(v.modules[-1], TestModule)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def test_manage_disable_modules(self):
        from ptah.manage.manage import CONFIG, module, PtahModule, PtahManageRoute, ManageView, set_access_manager

        global TestModule

        class TestModule(PtahModule):
            """ module description """

            title = "Test module"
            module("test-module")

        def accessManager(id):
            return True

        self._init_ptah()

        set_access_manager(accessManager)
        ptah.authService.set_userid("test-user")

        CONFIG["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))
Ejemplo n.º 6
0
    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))
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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))
Ejemplo n.º 10
0
    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))