[Zope3-checkins] CVS: Zope3/src/zope/app/exception/browser/tests - __init__.py:1.1 test_form.py:1.1 test_unauthorized.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Mar 13 23:44:53 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/exception/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv2821/src/zope/app/exception/browser/tests

Added Files:
	__init__.py test_form.py test_unauthorized.py 
Log Message:


Move exception views and interfaces to their own package zope.app.exception.




=== Added File Zope3/src/zope/app/exception/browser/tests/__init__.py ===
# empty __init__.py file to make this directory into a package


=== Added File Zope3/src/zope/app/exception/browser/tests/test_form.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""XXX short summary goes here.

$Id: test_form.py,v 1.1 2004/03/14 04:44:52 srichter Exp $
"""
import unittest
from zope.testing.doctestunit import DocTestSuite

def test_suite():
    return unittest.TestSuite((
        DocTestSuite('zope.app.exception.browser.form'),
        ))

if __name__ == '__main__': unittest.main()


=== Added File Zope3/src/zope/app/exception/browser/tests/test_unauthorized.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test Unauthorized Exception Views

$Id: test_unauthorized.py,v 1.1 2004/03/14 04:44:52 srichter Exp $
"""
from unittest import TestCase, main, makeSuite
from zope.interface import implements
from zope.publisher.browser import TestRequest
from zope.app.security.interfaces import IAuthenticationService, IPrincipal
from zope.app.container.contained import contained
from zope.app.exception.browser.unauthorized import Unauthorized
from zope.app.event.tests.placelesssetup import PlacelessSetup

class Unauthorized(Unauthorized):
    """Unusually done by ZCML."""

    def __init__(self, context, request):
        self.context = context
        self.request = request


class DummyPrincipal:
    implements(IPrincipal)  # this is a lie

    def __init__(self, id):
        self.id = id

    def getId(self):
        return self.id

class DummyAuthService:
    implements(IAuthenticationService)  # this is a lie

    def unauthorized(self, principal_id, request):
        self.principal_id = principal_id
        self.request = request

class DummyPrincipalSource:
    pass

class Test(TestCase, PlacelessSetup):

    def test(self):
        exception = Exception()
        try:
            raise exception
        except:
            pass
        request = TestRequest('/')
        authservice = DummyAuthService()
        request.setUser(contained(DummyPrincipal(23), authservice))
        u = Unauthorized(exception, request)
        u.issueChallenge()

        # Make sure the response status was set
        self.assertEqual(request.response.getStatus(), 403)

        # Make sure the auth service was called
        self.failUnless(authservice.request is request)
        self.assertEqual(authservice.principal_id, 23)

    def testPluggableAuthService(self):
        exception = Exception()
        try:
            raise exception
        except:
            pass
        request = TestRequest('/')
        authservice = DummyAuthService()
        psrc = DummyPrincipalSource()
        psrc = contained(psrc, authservice)
        request.setUser(contained(DummyPrincipal(23), psrc))
        u = Unauthorized(exception, request)
        u.issueChallenge()

        # Make sure the response status was set
        self.assertEqual(request.response.getStatus(), 403)

        # Make sure the auth service was called
        self.failUnless(authservice.request is request)
        self.assertEqual(authservice.principal_id, 23)

def test_suite():
    return makeSuite(Test)

if __name__=='__main__':
    main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list