예제 #1
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)
예제 #2
0
    def test_manage_disable_modules_traverse(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

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

        self._init_ptah()

        ptah.PTAH_CONFIG['disable_modules'] = ('test-module',)

        request = DummyRequest()
        route = PtahManageRoute(request)

        self.assertRaises(KeyError, route.__getitem__, 'test-module')
예제 #3
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))
예제 #4
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))
예제 #5
0
파일: test_manage.py 프로젝트: runyaga/ptah
    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)
예제 #6
0
파일: test_manage.py 프로젝트: runyaga/ptah
    def test_manage_disable_modules_traverse(self):
        from ptah.manage.manage import \
            module, PtahModule, PtahManageRoute, 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)

        self.assertRaises(KeyError, route.__getitem__, 'test-module')
예제 #7
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)
예제 #8
0
    def test_manage_disable_modules_traverse(self):
        from ptah.manage.manage import CONFIG, module, PtahModule, PtahManageRoute, 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)

        self.assertRaises(KeyError, route.__getitem__, "test-module")
예제 #9
0
    def test_manage_disable_modules(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

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

        self._init_ptah()

        ptah.PTAH_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))
예제 #10
0
    def test_manage_enable_modules_traverse(self):
        from ptah.manage.manage import module, PtahModule, PtahManageRoute, 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)

        self.assertIsNotNone(route["test-module1"])
        self.assertRaises(KeyError, route.__getitem__, "test-module2")
예제 #11
0
    def test_manage_disable_modules_traverse(self):
        from ptah.manage.manage import \
            module, PtahModule, PtahManageRoute, 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)

        self.assertRaises(KeyError, route.__getitem__, 'test-module')
예제 #12
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)
예제 #13
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

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

        self._init_ptah()

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

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

        self.assertIsInstance(view.modules[-1], TestModule)
예제 #14
0
    def test_manage_module(self):
        from ptah.manage.manage import (
            module,
            MANAGE_ID,
            PtahModule,
            PtahManageRoute,
            PtahAccessManager,
            set_access_manager,
        )

        global TestModule

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

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

        self._init_ptah()

        set_access_manager(PtahAccessManager)

        MODULES = config.get_cfg_storage(MANAGE_ID)
        self.assertIn("test-module", MODULES)

        request = self._makeRequest()

        self.assertRaises(HTTPForbidden, PtahManageRoute, request)

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

        self.assertRaises(HTTPForbidden, PtahManageRoute, request)

        def accessManager(id):
            return True

        set_access_manager(accessManager)

        route = PtahManageRoute(request)
        mod = route["test-module"]
        self.assertIsInstance(mod, TestModule)
        self.assertTrue(mod.available())
        self.assertEqual(mod.__name__, "test-module")
        self.assertEqual(mod.url(), "/ptah-manage/test-module")

        self.assertRaises(KeyError, route.__getitem__, "unknown")
예제 #15
0
    def test_manage_traverse(self):
        from ptah.manage.manage import module, PtahModule, PtahManageRoute, 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)

        mod = route["test-module"]
        self.assertIsInstance(mod, TestModule)
예제 #16
0
    def test_manage_module(self):
        from ptah.manage.manage import \
           module, MANAGE_ID, PtahModule, PtahManageRoute,\
           PtahAccessManager, set_access_manager

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

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

        set_access_manager(PtahAccessManager)

        self._init_ptah()

        MODULES = config.registry.storage[MANAGE_ID]
        self.assertIn('test-module', MODULES)

        request = self._makeRequest()

        self.assertRaises(HTTPForbidden, PtahManageRoute, request)

        ptah.authService.set_userid('test-user')

        self.assertRaises(HTTPForbidden, PtahManageRoute, request)

        def accessManager(id):
            return True

        set_access_manager(accessManager)

        route = PtahManageRoute(request)
        mod = route['test-module']
        self.assertIsInstance(mod, TestModule)
        self.assertTrue(mod.available())
        self.assertEqual(mod.__name__, 'test-module')
        self.assertEqual(mod.url(), 'test-module/')

        self.assertRaises(KeyError, route.__getitem__, 'unknown')
예제 #17
0
파일: test_manage.py 프로젝트: sidloki/ptah
    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))
예제 #18
0
    def test_manage_traverse(self):
        from ptah.manage.manage import \
            module, PtahModule, PtahManageRoute, 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)

        mod = route['test-module']
        self.assertIsInstance(mod, TestModule)
예제 #19
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))
예제 #20
0
    def test_manage_module(self):
        from ptah.manage.manage import \
           module, MANAGE_ID, PtahModule, PtahManageRoute,\
           PtahAccessManager, set_access_manager

        @module('test-module')
        class TestModule(PtahModule):
            """ module description """

            title = 'Test module'

        self.init_ptah()

        set_access_manager(PtahAccessManager())

        MODULES = config.get_cfg_storage(MANAGE_ID)
        self.assertIn('test-module', MODULES)

        self.assertRaises(HTTPForbidden, PtahManageRoute, self.request)

        ptah.auth_service.set_userid('test-user')

        self.assertRaises(HTTPForbidden, PtahManageRoute, self.request)

        def accessManager(id, request):
            return True

        set_access_manager(accessManager)

        route = PtahManageRoute(self.request)
        mod = route['test-module']
        self.assertIsInstance(mod, TestModule)
        self.assertTrue(mod.available())
        self.assertEqual(mod.__name__, 'test-module')
        self.assertEqual(mod.url(),
                         'http://example.com/ptah-manage/test-module')

        self.assertRaises(KeyError, route.__getitem__, 'unknown')
예제 #21
0
파일: test_manage.py 프로젝트: runyaga/ptah
    def test_manage_module(self):
        from ptah.manage.manage import \
           module, MANAGE_ID, PtahModule, PtahManageRoute,\
           PtahAccessManager, set_access_manager

        @module('test-module')
        class TestModule(PtahModule):
            """ module description """

            title = 'Test module'

        self.init_ptah()

        set_access_manager(PtahAccessManager())

        MODULES = config.get_cfg_storage(MANAGE_ID)
        self.assertIn('test-module', MODULES)

        self.assertRaises(HTTPForbidden, PtahManageRoute, self.request)

        ptah.auth_service.set_userid('test-user')

        self.assertRaises(HTTPForbidden, PtahManageRoute, self.request)

        def accessManager(id, request):
            return True

        set_access_manager(accessManager)

        route = PtahManageRoute(self.request)
        mod = route['test-module']
        self.assertIsInstance(mod, TestModule)
        self.assertTrue(mod.available())
        self.assertEqual(mod.__name__, 'test-module')
        self.assertEqual(mod.url(), 'http://example.com/ptah-manage/test-module')

        self.assertRaises(KeyError, route.__getitem__, 'unknown')