Beispiel #1
0
class TestLoggerBackend(TestCase):
    def setUp(self):

        self.handler = MockLoggingHandler()
        self.handler.setLevel(logging.INFO)

        logger_name = 'track.backends.logger.test'
        logger = logging.getLogger(logger_name)
        logger.addHandler(self.handler)

        self.backend = LoggerBackend(name=logger_name)

    def test_logger_backend(self):
        self.handler.reset()

        # Send a couple of events and check if they were recorded
        # by the logger. The events are serialized to JSON.

        event = {'test': True}
        event_as_json = json.dumps(event)

        self.backend.send(event)
        self.backend.send(event)

        self.assertEqual(
            self.handler.messages['info'],
            [event_as_json, event_as_json]
        )
def test_logger_backend(caplog):
    """
    Send a couple of events and check if they were recorded
    by the logger. The events are serialized to JSON.
    """
    caplog.set_level(logging.INFO)
    logger_name = 'track.backends.logger.test'
    backend = LoggerBackend(name=logger_name)
    event = {
        'test': True,
        'time': datetime.datetime(2012, 5, 1, 7, 27, 1, 200),
        'date': datetime.date(2012, 5, 7),
    }

    backend.send(event)
    backend.send(event)

    saved_events = [
        json.loads(e[2]) for e in caplog.record_tuples if e[0] == logger_name
    ]

    unpacked_event = {
        'test': True,
        'time': '2012-05-01T07:27:01.000200+00:00',
        'date': '2012-05-07'
    }

    assert saved_events[0] == unpacked_event
    assert saved_events[1] == unpacked_event
def test_logger_backend(caplog):
    """
    Send a couple of events and check if they were recorded
    by the logger. The events are serialized to JSON.
    """
    caplog.set_level(logging.INFO)
    logger_name = 'track.backends.logger.test'
    backend = LoggerBackend(name=logger_name)
    event = {
        'test': True,
        'time': datetime.datetime(2012, 5, 1, 7, 27, 1, 200),
        'date': datetime.date(2012, 5, 7),
    }

    backend.send(event)
    backend.send(event)

    saved_events = [json.loads(e[2]) for e in caplog.record_tuples if e[0] == logger_name]

    unpacked_event = {
        'test': True,
        'time': '2012-05-01T07:27:01.000200+00:00',
        'date': '2012-05-07'
    }

    assert saved_events[0] == unpacked_event
    assert saved_events[1] == unpacked_event
Beispiel #4
0
class TestLoggerBackend(TestCase):
    def setUp(self):
        super(TestLoggerBackend, self).setUp()
        self.handler = MockLoggingHandler()
        self.handler.setLevel(logging.INFO)

        logger_name = "track.backends.logger.test"
        logger = logging.getLogger(logger_name)
        logger.addHandler(self.handler)

        self.backend = LoggerBackend(name=logger_name)

    def test_logger_backend(self):
        self.handler.reset()

        # Send a couple of events and check if they were recorded
        # by the logger. The events are serialized to JSON.

        event = {
            "test": True,
            "time": datetime.datetime(2012, 05, 01, 07, 27, 01, 200),
            "date": datetime.date(2012, 05, 07),
        }

        self.backend.send(event)
        self.backend.send(event)

        saved_events = [json.loads(e) for e in self.handler.messages["info"]]

        unpacked_event = {"test": True, "time": "2012-05-01T07:27:01.000200+00:00", "date": "2012-05-07"}

        self.assertEqual(saved_events[0], unpacked_event)
        self.assertEqual(saved_events[1], unpacked_event)
class TestLoggerBackend(TestCase):
    def setUp(self):

        self.handler = MockLoggingHandler()
        self.handler.setLevel(logging.INFO)

        logger_name = 'track.backends.logger.test'
        logger = logging.getLogger(logger_name)
        logger.addHandler(self.handler)

        self.backend = LoggerBackend(name=logger_name)

    def test_logger_backend(self):
        self.handler.reset()

        # Send a couple of events and check if they were recorded
        # by the logger. The events are serialized to JSON.

        event = {'test': True}
        event_as_json = json.dumps(event)

        self.backend.send(event)
        self.backend.send(event)

        self.assertEqual(self.handler.messages['info'],
                         [event_as_json, event_as_json])
Beispiel #6
0
class TestLoggerBackend(TestCase):
    def setUp(self):
        super(TestLoggerBackend, self).setUp()
        self.handler = MockLoggingHandler()
        self.handler.setLevel(logging.INFO)

        logger_name = 'track.backends.logger.test'
        logger = logging.getLogger(logger_name)
        logger.addHandler(self.handler)

        self.backend = LoggerBackend(name=logger_name)

    def test_logger_backend(self):
        self.handler.reset()

        # Send a couple of events and check if they were recorded
        # by the logger. The events are serialized to JSON.

        event = {
            'test': True,
            'time': datetime.datetime(2012, 05, 01, 07, 27, 01, 200),
            'date': datetime.date(2012, 05, 07),
        }

        self.backend.send(event)
        self.backend.send(event)

        saved_events = [json.loads(e) for e in self.handler.messages['info']]

        unpacked_event = {
            'test': True,
            'time': '2012-05-01T07:27:01.000200+00:00',
            'date': '2012-05-07'
        }

        self.assertEqual(saved_events[0], unpacked_event)
        self.assertEqual(saved_events[1], unpacked_event)