Exemplo n.º 1
0
    def test_valid(self):
        formatter = logging.Formatter('%(asctime)s: %(levelname)s %(message)s')
        message = "There is a problem."
        uri = "/some/random/uri"
        status_code = 400
        username = '******'
        log_record = logging.makeLogRecord({
                    'name':'huxley.server',
                    'level':10,
                    'fn':'',
                    'lno':'',
                    'msg':json.dumps({
                         'message': message,
                         'uri': uri,
                         'status_code': status_code,
                         'username': username}),
                    'args':(),
                    'exc_info':None})

        handler = DatabaseHandler()
        handler.formatter = formatter
        handler.emit(log_record)

        log_entry = LogEntry.objects.get(id=1)
        self.assertEqual(log_entry.level, log_record.levelname)
        self.assertEqual(log_entry.message, message)
        self.assertEqual(log_entry.timestamp,
            datetime.datetime.strptime(log_record.asctime, "%Y-%m-%d %H:%M:%S,%f"))
        self.assertEqual(log_entry.uri, uri)
        self.assertEqual(log_entry.status_code, status_code)
        self.assertEqual(log_entry.username, username)
Exemplo n.º 2
0
    def test_valid(self):
        formatter = logging.Formatter('%(asctime)s: %(levelname)s %(message)s')
        message = "There is a problem."
        uri = "/some/random/uri"
        status_code = 400
        username = '******'
        log_record = logging.makeLogRecord({
                    'name':'huxley.server',
                    'level':10,
                    'fn':'',
                    'lno':'',
                    'msg':json.dumps({
                         'message': message,
                         'uri': uri,
                         'status_code': status_code,
                         'username': username}),
                    'args':(),
                    'exc_info':None})

        handler = DatabaseHandler()
        handler.formatter = formatter
        handler.emit(log_record)

        log_entry = LogEntry.objects.get(id=1)
        self.assertEqual(log_entry.level, log_record.levelname)
        self.assertEqual(log_entry.message, message)
        self.assertEqual(log_entry.timestamp,
            datetime.datetime.strptime(log_record.asctime, "%Y-%m-%d %H:%M:%S,%f"))
        self.assertEqual(log_entry.uri, uri)
        self.assertEqual(log_entry.status_code, status_code)
        self.assertEqual(log_entry.username, username)
Exemplo n.º 3
0
    def test_valid(self):
        formatter = logging.Formatter('%(asctime)s: %(levelname)s %(message)s')
        log_record = logging.makeLogRecord({
                    'name':'huxley.server',
                    'level':10,
                    'fn':'',
                    'lno':'',
                    'msg':'There is a problem.',
                    'args':(),
                    'exc_info':None})

        handler = DatabaseHandler()
        handler.formatter = formatter
        handler.emit(log_record)

        log_entry = LogEntry.objects.get(id=1)
        self.assertEqual(log_entry.level, log_record.levelname)
        self.assertEqual(log_entry.message, log_record.message)
        self.assertEqual(log_entry.timestamp,
            datetime.datetime.strptime(log_record.asctime, "%Y-%m-%d %H:%M:%S,%f"))
Exemplo n.º 4
0
    def test_valid(self):
        formatter = logging.Formatter('%(asctime)s: %(levelname)s %(message)s')
        log_record = logging.makeLogRecord({
            'name': 'huxley.server',
            'level': 10,
            'fn': '',
            'lno': '',
            'msg': 'There is a problem.',
            'args': (),
            'exc_info': None
        })

        handler = DatabaseHandler()
        handler.formatter = formatter
        handler.emit(log_record)

        log_entry = LogEntry.objects.get(id=1)
        self.assertEqual(log_entry.level, log_record.levelname)
        self.assertEqual(log_entry.message, log_record.message)
        self.assertEqual(
            log_entry.timestamp,
            datetime.datetime.strptime(log_record.asctime,
                                       "%Y-%m-%d %H:%M:%S,%f"))