Ejemplo n.º 1
0
    def test_forbidden_default_root(self):
        from ptah.exc import Forbidden
        from pyramid.interfaces import IRootFactory

        class Root(object):
            """ """
            def __init__(self, request):
                self.request = request

        request = DummyRequest()
        request.url = u'http://example.com'
        request.application_url = u'http://example.com'

        config.registry.registerUtility(Root, IRootFactory)

        excview = Forbidden(HTTPForbidden(), request)
        excview.update()

        self.assertIs(excview.__parent__, request.root)
        self.assertIsInstance(request.root, Root)
Ejemplo n.º 2
0
    def test_forbidden_custom_login(self):
        from ptah.exc import Forbidden

        class Context(object):
            """ """

        request = DummyRequest()
        request.url = u'http://example.com'
        request.root = Context()
        ptah.PTAH_CONFIG.login = '******'

        excview = Forbidden(HTTPForbidden(), request)
        excview.update()

        res = request.response

        self.assertIs(excview.__parent__, request.root)
        self.assertEqual(res.status, '302 Found')
        self.assertEqual(
            res.headers['location'],
            'http://example.com/custom-login.html?came_from=http%3A%2F%2Fexample.com')
Ejemplo n.º 3
0
    def test_forbidden_user(self):
        from ptah.exc import Forbidden
        self._init_ptah()
        config.start(self.p_config)

        class Context(object):
            """ """
            __name__ = 'test'

        request = DummyRequest()
        request.root = Context()
        ptah.authService.set_userid('user')

        res = Forbidden.__renderer__(HTTPForbidden(), request)
        self.assertEqual(res.status, '403 Forbidden')