Esempio n. 1
0
    def test_manage_pyramid_directive(self):
        from pyramid.config import Configurator

        config = Configurator(autocommit=True)
        config.include("ptah")

        def access_manager():
            """ """

        config.ptah_init_manage(
            "test-manage",
            access_manager=access_manager,
            managers=("manager",),
            manager_role="Manager",
            disable_modules=("module",),
            enable_modules=("module2",),
        )

        cfg = config.ptah_get_settings(ptah.CFG_ID_PTAH)

        self.assertEqual(cfg["manage"], "test-manage")
        self.assertEqual(cfg["managers"], ("manager",))
        self.assertEqual(cfg["manager_role"], "Manager")
        self.assertEqual(cfg["disable_modules"], ("module",))
        self.assertEqual(cfg["enable_modules"], ("module2",))
        self.assertIs(cfg["access_manager"], access_manager)

        iface = config.registry.getUtility(IRouteRequest, "ptah-manage")
        self.assertIsNotNone(iface)
Esempio n. 2
0
    def test_manage_pyramid_directive(self):
        from pyramid.config import Configurator

        config = Configurator(autocommit=True)
        config.include('ptah')

        def access_manager():
            """ """

        config.ptah_init_manage(
            'test-manage',
            access_manager=access_manager,
            managers = ('manager',),
            manager_role = 'Manager',
            disable_modules = ('module',),
            enable_modules = ('module2',))

        cfg = config.ptah_get_settings(ptah.CFG_ID_PTAH)

        self.assertEqual(cfg['manage'], 'test-manage')
        self.assertEqual(cfg['managers'], ('manager',))
        self.assertEqual(cfg['manager_role'], 'Manager')
        self.assertEqual(cfg['disable_modules'], ('module',))
        self.assertEqual(cfg['enable_modules'], ('module2',))
        self.assertIs(cfg['access_manager'], access_manager)

        iface = config.registry.getUtility(IRouteRequest, 'ptah-manage')
        self.assertIsNotNone(iface)
Esempio n. 3
0
    def test_manage_pyramid_directive_default(self):
        from pyramid.config import Configurator
        from ptah.manage.manage import PtahAccessManager

        config = Configurator(autocommit=True)
        config.include("ptah")

        config.ptah_init_manage("test-manage")

        cfg = config.ptah_get_settings(ptah.CFG_ID_PTAH)
        self.assertIsInstance(cfg["access_manager"], PtahAccessManager)
Esempio n. 4
0
    def test_manage_pyramid_directive_default(self):
        from pyramid.config import Configurator
        from ptah.manage.manage import PtahAccessManager

        config = Configurator(autocommit=True)
        config.include('ptah')

        config.ptah_init_manage('test-manage')

        cfg = config.ptah_get_settings(ptah.CFG_ID_PTAH)
        self.assertIsInstance(cfg['access_manager'], PtahAccessManager)
Esempio n. 5
0
    def test_uri_resolver_pyramid(self):
        import ptah

        def resolver1(uri):
            return 'Resolved-pyramid'

        config = testing.setUp()
        config.include('ptah')
        config.ptah_uri_resolver('test1', resolver1)
        config.commit()

        self.assertEqual(ptah.resolve('test1:uri'), 'Resolved-pyramid')
Esempio n. 6
0
    def test_password_changer_pyramid(self):
        import ptah

        def changer(schema):
            """ """

        config = testing.setUp()
        config.include('ptah')
        config.ptah_password_changer('test-schema', changer)

        p = Principal('test-schema:numbers_numbers', 'name', 'login')
        self.assertTrue(ptah.pwd_tool.can_change_password(p))
Esempio n. 7
0
    def test_uri_resolver_pyramid(self):
        import ptah

        def resolver1(uri):
            return 'Resolved-pyramid'

        config = testing.setUp()
        config.include('ptah')
        config.ptah_uri_resolver('test1', resolver1)
        config.commit()

        self.assertEqual(ptah.resolve('test1:uri'), 'Resolved-pyramid')
Esempio n. 8
0
    def test_principal_searcher_pyramid(self):
        import ptah

        principal = Principal('1', 'user', 'user')
        def search(term=''):
            if term == 'user':
                yield principal

        config = testing.setUp()
        config.include('ptah')
        config.ptah_principal_searcher('test-provider', search)

        self.assertEqual(list(ptah.search_principals('user')), [principal])
Esempio n. 9
0
    def test_snippet_register_pyramid(self):
        from pyramid.config import Configurator

        class TestSnippet(view.View):
            def __call__(self):
                return 'test'

        config = Configurator(autocommit=True)
        config.include('ptah')
        config.ptah_snippet('pt', view=TestSnippet)

        res = config.registry.getMultiAdapter(
            (Context(), self.request), view.ISnippet, 'pt')
        self.assertEqual(res, 'test')
Esempio n. 10
0
    def test_auth_provider_pyramid(self):
        import ptah

        class Provider(object):
            def authenticate(self, creds):
                if creds['login'] == 'user':
                    return Principal('1', 'user', 'user')

        config = testing.setUp()
        config.include('ptah')

        self.assertTrue(getattr(config, 'ptah_auth_provider'))

        config.ptah_auth_provider('test-provider', Provider())
        config.commit()

        info = ptah.auth_service.authenticate(
            {'login': '******', 'password': '******'})

        self.assertTrue(info.status)
        self.assertEqual(info.__uri__, '1')
Esempio n. 11
0
    def test_auth_checker_pyramid(self):
        import ptah

        principal = Principal('1', 'user', 'user')

        class Provider(object):
            def authenticate(self, creds):
                if creds['login'] == 'user':
                    return Principal('1', 'user', 'user')

        config = testing.setUp()
        config.include('ptah')

        def checker(info):
            info.message = 'Suspended'
            info.arguments['additional'] = 'test'
            return False

        config.ptah_auth_checker(checker)
        config.ptah_auth_provider('test-provider', Provider())

        info = ptah.auth_service.authenticate(
            {'login': '******', 'password': '******'})

        self.assertFalse(info.status)
        self.assertEqual(info.__uri__, '1')
        self.assertEqual(info.message, 'Suspended')
        self.assertEqual(info.arguments, {'additional': 'test'})

        principal = Principal('1', 'user', 'user')

        info = ptah.auth_service.authenticate_principal(principal)
        self.assertFalse(info.status)
        self.assertEqual(info.__uri__, '1')
        self.assertEqual(info.message, 'Suspended')
        self.assertEqual(info.arguments, {'additional': 'test'})