Exemplo n.º 1
0
 def setUp(self):
     ZODB.tests.util.TestCase.setUp(self)
     from ZODB.Connection import Connection
     self.db = db = databaseFromString("<zodb>\n<mappingstorage/>\n</zodb>")
     self.datamgr = self.db.open()
     self.object = StubObject()
     self.datamgr.add(self.object)
     transaction.commit()
     self.handler = loggingsupport.InstalledHandler("ZODB")
Exemplo n.º 2
0
    def test_log(self):
        class Task(object):
            class channel(object):
                username = '******'
                cwd = '/'
                addr = ('localhost', )

            m_name = 'head'

        handler = loggingsupport.InstalledHandler("accesslog")
        self.addCleanup(handler.uninstall)

        cal = logger.CommonFTPActivityLogger()
        cal.log(Task)

        self.assertEqual(1, len(handler.records))
        self.assertIn('localhost', str(handler))
        self.assertIn('user', str(handler))
Exemplo n.º 3
0
def sectionsSetUp(test):
    setUp(test)

    from collective.transmogrifier.transmogrifier import Transmogrifier
    test.globs['transmogrifier'] = Transmogrifier(test.globs['plone'])

    import collective.transmogrifier.sections
    zcml.load_config('testing.zcml', collective.transmogrifier.sections)

    provideUtility(
        SampleSource,
        name=u'collective.transmogrifier.sections.tests.samplesource')
    provideUtility(
        RangeSource,
        name=u'collective.transmogrifier.sections.tests.rangesource')

    import logging
    from zope.testing import loggingsupport
    test.globs['handler'] = loggingsupport.InstalledHandler('logger',
                                                            level=logging.INFO)
Exemplo n.º 4
0
    def test_log_request(self):
        import time
        from zope.testing import loggingsupport
        handler = loggingsupport.InstalledHandler("accesslog")
        self.addCleanup(handler.uninstall)

        class Resolver(object):
            def resolve_ptr(self, ip, then):
                then('host', None, None)

        class Task(object):
            channel = request_data = property(lambda s: s)
            headers = {}
            auth_user_name = None
            addr = ('localhost', )
            first_line = 'GET / HTTP/1.0'
            status = '200 OK'
            bytes_written = 10

        orig_t = time.time

        def t():
            return 123456789

        orig_dl = time.daylight
        orig_az = time.altzone
        time.daylight = True
        time.altzone = -3600
        time.time = t
        try:
            cal = CommonAccessLogger(resolver=Resolver())
            cal.log(Task())
        finally:
            time.daylight = orig_dl
            time.altzone = orig_az
            time.time = orig_t

        self.assertEqual(1, len(handler.records))
        self.assertEqual(
            'host - anonymous [29/Nov/1973:21:33:09 +0100] "GET / HTTP/1.0" 200 OK 10 "" ""',
            handler.records[0].getMessage())
    def testHandlingSystemErrors(self):

        # Generally, when there is a view for an excepton, we assume
        # it is a user error, not a system error and we don't log it.

        from zope.testing import loggingsupport
        handler = loggingsupport.InstalledHandler('SiteError')

        self.testViewOnException()

        self.assertEqual(
            str(handler), 'SiteError ERROR\n'
            '  Error while reporting an error to the Error Reporting utility')

        # Here we got a single log record, because we haven't
        # installed an error reporting utility.  That's OK.

        handler.uninstall()
        handler = loggingsupport.InstalledHandler('SiteError')

        # Now, we'll register an exception view that indicates that we
        # have a system error.

        from zope.interface import Interface, implements

        class E2(Exception):
            pass

        support.setDefaultViewName(E2,
                                   'name',
                                   layer=self.presentation_type,
                                   type=self.presentation_type)
        view_text = 'You had a conflict error'

        from zope.browser.interfaces import ISystemErrorView

        class MyView:
            implements(ISystemErrorView)

            def __init__(self, context, request):
                pass

            def isSystemError(self):
                return True

            def __call__(self):
                return view_text

        component.provideAdapter(MyView, (E2, self.presentation_type),
                                 Interface,
                                 name='name')

        try:
            raise E2
        except:
            self.publication.handleException(self.object,
                                             self.request,
                                             sys.exc_info(),
                                             retry_allowed=False)

        # Now, since the view was a system error view, we should have
        # a log entry for the E2 error (as well as the missing
        # error reporting utility).
        self.assertEqual(
            str(handler), 'SiteError ERROR\n'
            '  Error while reporting an error to the Error Reporting utility\n'
            'SiteError ERROR\n'
            '  http://test.url')

        handler.uninstall()