Beispiel #1
0
 def test_avatar_hr_with_data(self):
     """
     Check human readable format for an avatar with data.
     """
     log_avatar = manufacture.makeFilesystemApplicationAvatar()
     entry = LogEntry(None, None, log_avatar, None)
     self.assertEqual(log_avatar.name, entry.avatar_hr)
Beispiel #2
0
    def test_log(self):
        """
        `log` method is here for transition and used the old Logger.log
        interface to emit an event.
        """
        handler = EventsHandler()
        message = u'Some message ' + manufacture.getUniqueString()
        peer = manufacture.makeIPv4Address()
        avatar = manufacture.makeFilesystemApplicationAvatar()
        data = {}
        handler.log(100, message, peer=peer, avatar=avatar, data=data)

        log_message = self.popLog()
        self.assertEqual(100, log_message[0])
        self.assertTrue('Some message' in log_message[1])
        self.assertEqual(avatar, log_message[2])
        self.assertEqual(peer, log_message[3])
        self.assertEqual(data, log_message[4])
Beispiel #3
0
    def test_init(self):
        """
        Check LogEntry initialization.
        """
        log_id = 999999
        log_text = manufacture.getUniqueString()
        log_avatar = manufacture.makeFilesystemApplicationAvatar()
        log_peer = manufacture.makeIPv4Address()
        entry = LogEntry(log_id, log_text, log_avatar, log_peer)
        now = time()
        self.assertEqual(log_id, entry.message_id)
        self.assertEqual(log_text, entry.text)
        self.assertEqual(log_avatar, entry.avatar)
        self.assertEqual(log_peer, entry.peer)

        # We just check that human representation of time not empty.
        self.assertTrue(entry.timestamp_hr)

        # We just test that the entry's timestamp is very recent.
        time_diff = now - entry.timestamp
        self.assertTrue(time_diff <= 0.05, 'Timediff is %f' % time_diff)
        self.assertTrue(time_diff >= 0.0, 'Timediff is %f' % time_diff)
Beispiel #4
0
    def test_init(self):
        """
        Check Event initialization.
        """
        event_id = manufacture.getUniqueString()
        message = manufacture.getUniqueString()
        data = {
            'attr1': 'value1',
            'attr2': 'value2',
            'peer': manufacture.makeIPv4Address(),
            'avatar': manufacture.makeFilesystemApplicationAvatar()}

        event = Event(
            id=event_id,
            message=message,
            data=data,
            )

        self.assertProvides(IEvent, event)
        self.assertEqual(event_id, event.id)
        self.assertEqual(message, event.message)
        self.assertEqual(data, event.data)