def testRejectLog(self):
     stream = StringIO()
     writer = ApacheLogWriter(
         stream,
         rejectLog=lambda collectedLog: getScoped(
             collectedLog, scopeNames=(), key='httpRequest').get(
                 'RequestURI') == ['/abc'])
     collectedLog = {
         'httpRequest': {
             'Headers': [{}],
             'Client': [('10.11.12.13', 12345)],
             'timestamp': [1468845136.824253],
             'Method': ['GET'],
             'RequestURI': ['/abc'],
         },
         'httpResponse': {
             'httpStatus': ['200'],
         }
     }
     writer.writeLog(collectedLog)
     self.assertEquals('', stream.getvalue())
     collectedLog['httpRequest']['RequestURI'] = ['/abcd']
     writer.writeLog(collectedLog)
     self.assertEquals(
         '10.11.12.13 - - [18/Jul/2016:12:32:16 +0000] "GET /abcd HTTP/1.0" 200 - "-" "-"\n',
         stream.getvalue())
Example #2
0
 def testNormalLog(self):
     stream = StringIO()
     writer = ApacheLogWriter(stream)
     writer.writeLog(
         collectedLog={
             'httpRequest': {
                 'Headers': [{}],
                 'Client': [('10.11.12.13', 12345)],
                 'timestamp': [1468845136.824253],
                 'Method': ['GET'],
                 'RequestURI': ['/abc'],
             },
             'httpResponse': {
                 'httpStatus': ['200'],
             }
         }
     )
     self.assertEquals('10.11.12.13 - - [18/Jul/2016:12:32:16 +0000] "GET /abc HTTP/1.0" 200 - "-" "-"\n', stream.getvalue())
 def testNormalLog(self):
     stream = StringIO()
     writer = ApacheLogWriter(stream)
     writer.writeLog(
         collectedLog={
             'httpRequest': {
                 'Headers': [{}],
                 'Client': [('10.11.12.13', 12345)],
                 'timestamp': [1468845136.824253],
                 'Method': ['GET'],
                 'RequestURI': ['/abc'],
             },
             'httpResponse': {
                 'httpStatus': ['200'],
             }
         })
     self.assertEquals(
         '10.11.12.13 - - [18/Jul/2016:12:32:16 +0000] "GET /abc HTTP/1.0" 200 - "-" "-"\n',
         stream.getvalue())
 def testLogWithException(self):
     stream = StringIO()
     writer = ApacheLogWriter(stream)
     writer.writeLog(
         collectedLog={
             'httpRequest': {
                 'Headers': [{}],
                 'Client': [('10.11.12.13', 12345)],
                 'timestamp': [1468845136.824253],
                 'Method': ['GET'],
                 'RequestURI': ['/abc'],
             },
             'httpResponse': {
                 'httpStatus': ['200'],
                 'exception': [ValueError('xyz')]
             }
         })
     self.assertEqual(
         '10.11.12.13 - - [18/Jul/2016:12:32:16 +0000] "GET /abc HTTP/1.0" 200 - "-" "-" Exception raised:\n    ValueError(\'xyz\')\n',
         stream.getvalue())
 def testRejectLog(self):
     stream = StringIO()
     writer = ApacheLogWriter(stream, rejectLog=lambda collectedLog: getScoped(collectedLog, scopeNames=(), key='httpRequest').get('RequestURI') == ['/abc'])
     collectedLog={
         'httpRequest': {
             'Headers': [{}],
             'Client': [('10.11.12.13', 12345)],
             'timestamp': [1468845136.824253],
             'Method': ['GET'],
             'RequestURI': ['/abc'],
         },
         'httpResponse': {
             'httpStatus': ['200'],
         }
     }
     writer.writeLog(collectedLog)
     self.assertEquals('', stream.getvalue())
     collectedLog['httpRequest']['RequestURI'] = ['/abcd']
     writer.writeLog(collectedLog)
     self.assertEquals('10.11.12.13 - - [18/Jul/2016:12:32:16 +0000] "GET /abcd HTTP/1.0" 200 - "-" "-"\n', stream.getvalue())
Example #6
0
 def testWriteLogWithoutSensibleData(self):
     stream = StringIO()
     writer = ApacheLogWriter(stream)
     writer.writeLog(collectedLog={'key':['value']})
     self.assertEquals("", stream.getvalue())
 def testWriteLogWithoutSensibleData(self):
     stream = StringIO()
     writer = ApacheLogWriter(stream)
     writer.writeLog(collectedLog={'key': ['value']})
     self.assertEquals("", stream.getvalue())