Back to index

plone3  3.1.7
test_doctests.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # PlonePAS - Adapt PluggableAuthService for use in Plone
00004 # Copyright (C) 2005 Enfold Systems, Kapil Thangavelu, et al
00005 #
00006 # This software is subject to the provisions of the Zope Public License,
00007 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this
00008 # distribution.
00009 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00010 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00011 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00012 # FOR A PARTICULAR PURPOSE.
00013 #
00014 ##############################################################################
00015 """
00016 """
00017 
00018 # Load fixture
00019 import unittest
00020 from Testing import ZopeTestCase
00021 from Products.PloneTestCase.PloneTestCase import FunctionalTestCase
00022 from Products.PloneTestCase.PloneTestCase import setupPloneSite
00023 
00024 from Products.CMFCore.utils import getToolByName
00025 
00026 from zExceptions.ExceptionFormatter import format_exception
00027 from ZPublisher.HTTPResponse import HTTPResponse
00028 
00029 setupPloneSite()
00030 
00031 # Silence Plone's handling of exceptions
00032 orig_exception = HTTPResponse.exception
00033 def exception(self, **kw):
00034     def tag_search(*args):
00035         return False
00036     kw['tag_search'] = tag_search
00037     return orig_exception(self, **kw)
00038 
00039 orig_setBody = HTTPResponse.setBody
00040 def setBody(self, *args, **kw):
00041     kw['is_error'] = 0
00042     if len(args[0]) == 2:
00043         title, body = args[0]
00044         args = (body,) + args[1:]
00045     return orig_setBody(self, *args, **kw)
00046 
00047 def _traceback(self, t, v, tb, as_html=1):
00048     return ''.join(format_exception(t, v, tb, as_html=as_html))
00049 
00050 HTTPResponse._error_format = 'text/plain'
00051 HTTPResponse._traceback = _traceback
00052 HTTPResponse.exception = exception
00053 HTTPResponse.setBody = setBody
00054 
00055 def test_suite():
00056     suite = unittest.TestSuite()
00057     DocFileSuite = ZopeTestCase.FunctionalDocFileSuite
00058     tests = (
00059         ('cookie_auth.txt', FunctionalTestCase),
00060         )
00061 
00062     for fname, klass in tests:
00063         t = DocFileSuite(fname,
00064                          test_class=klass,
00065                          package='Products.PlonePAS.tests')
00066         suite.addTest(t)
00067     return suite
00068