[Zope3-checkins] CVS: Zope3/src/zope/app/http/exception/tests - __init__.py:1.1 test_unauthorized.py:1.1
Sidnei da Silva
sidnei@x3ng.com.br
Sat, 29 Mar 2003 12:04:00 -0500
Update of /cvs-repository/Zope3/src/zope/app/http/exception/tests
In directory cvs.zope.org:/tmp/cvs-serv25288/exception/tests
Added Files:
__init__.py test_unauthorized.py
Log Message:
Adding exception handler for unauthorized http exception. Should omit WWW-Authenticate headers.
=== Added File Zope3/src/zope/app/http/exception/tests/__init__.py ===
# empty __init__.py file to make this directory into a package
=== Added File Zope3/src/zope/app/http/exception/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.
#
##############################################################################
"""
Revision information:
$Id: test_unauthorized.py,v 1.1 2003/03/29 17:03:59 sidnei Exp $
"""
from unittest import TestCase, main, makeSuite
from zope.publisher.browser import TestRequest
from zope.app.interfaces.http import IHTTPException
class Test(TestCase):
def testbasicauth(self):
from zope.app.http.exception.unauthorized import Unauthorized
exception = Exception()
try:
raise exception
except:
pass
request = TestRequest('/')
u = Unauthorized(exception, request)
# Chech that we implement the right interface
self.failUnless(IHTTPException.isImplementedBy(u))
# Call the view
u()
# Make sure the response status was set
self.assertEqual(request.response.getStatus(), 401)
self.failUnless(request.response.getHeader('WWW-Authenticate', '', True).startswith('basic'))
def test_suite():
return makeSuite(Test)
if __name__=='__main__':
main(defaultTest='test_suite')