Exemple #1
0
    def test_events_no_log_files(self):
        self.patch_object(collection, 'Streamer', name='mock_Streamer')
        manager1 = mock.Mock()
        manager2 = mock.Mock()

        def iter1():
            for x in []:
                yield x

        def iter2():
            for x in []:
                yield x

        manager1.log_files.return_value = iter1()
        manager2.log_files.return_value = iter2()

        c = collection.Collection()
        c.add_logging_manager(manager1)
        c.add_logging_manager(manager2)

        self.mock_Streamer.return_value = 'a-streamer'

        self.assertEqual(c.events(), 'a-streamer')
        self.mock_Streamer.assert_called_once_with(
            [],
            collection.LogFormats.InfluxDB)
Exemple #2
0
    def test_events_valid(self):
        self.patch_object(collection, 'Streamer', name='mock_Streamer')
        manager1 = mock.Mock()
        manager2 = mock.Mock()

        def iter1():
            for x in (
                    ('log1', collection.LogFormats.InfluxDB, 'log1.txt'),
                    ('log2', collection.LogFormats.InfluxDB, 'log2.txt')):
                yield x

        def iter2():
            for x in (
                    ('log3', collection.LogFormats.InfluxDB, 'log3.txt'),):
                yield x

        manager1.log_files.return_value = iter1()
        manager2.log_files.return_value = iter2()

        c = collection.Collection()
        c.add_logging_manager(manager1)
        c.add_logging_manager(manager2)

        self.mock_Streamer.return_value = 'a-streamer'

        self.assertEqual(c.events(), 'a-streamer')
        self.mock_Streamer.assert_called_once_with(
            ['log1.txt', 'log2.txt', 'log3.txt'],
            collection.LogFormats.InfluxDB,
            sort=True,
            precision='us',
            strip_precision=True)
Exemple #3
0
    def test_clean_up(self):
        manager1 = mock.Mock()
        manager2 = mock.Mock()
        c = collection.Collection()
        c.add_logging_manager(manager1)
        c.add_logging_manager(manager2)

        c.clean_up()
        manager1.clean_up.assert_called_once_with()
        manager2.clean_up.assert_called_once_with()
Exemple #4
0
    def test_finalise(self):
        manager1 = mock.Mock()
        manager2 = mock.Mock()
        c = collection.Collection()
        c.add_logging_manager(manager1)
        c.add_logging_manager(manager2)

        c.finalise()
        manager1.finalise.assert_called_once_with()
        manager2.finalise.assert_called_once_with()
Exemple #5
0
 def test_collection_init(self):
     c = collection.Collection(
         name='a-name',
         collection='a-collection',
         description='a-description',
         logs_dir='logs',
         log_format=None)
     self.assertEqual(c.name, 'a-name')
     self.assertEqual(c.collection, 'a-collection')
     self.assertEqual(c.description, 'a-description')
     self.assertEqual(c.logs_dir, 'logs')
     self.assertEqual(c.log_format, collection.LogFormats.InfluxDB)
Exemple #6
0
    def test_add_logging_manager(self):
        self.mock_mkdtemp.return_value = 'temp-logs'
        manager = mock.Mock()
        c = collection.Collection()
        c.log_format = None
        c.add_logging_manager(manager)

        self.assertIn(manager, c._event_managers)
        self.assertEqual(c.log_format, collection.LogFormats.InfluxDB)
        manager.configure.assert_called_once_with(collection_object=c)
        self.assertEqual(c.logs_dir, 'temp-logs')
        manager.configure_plugin.assert_called_once_with()

        # add it again to ensure that it doesn't get added again.
        manager.reset_mock()
        c.add_logging_manager(manager)
        manager.configure.assert_not_called()
        self.assertEqual(c.logs_dir, 'temp-logs')
        manager.configure_plugin.assert_not_called()
        self.assertEqual(len(c._event_managers), 1)
Exemple #7
0
    def test_log_files(self):
        manager1 = mock.Mock()
        manager2 = mock.Mock()

        def iter1():
            for x in ('log1', 'log2'):
                yield x

        def iter2():
            for y in ('log3', 'log4', 'log5'):
                yield y

        manager1.log_files.return_value = iter1()
        manager2.log_files.return_value = iter2()

        c = collection.Collection()
        c.add_logging_manager(manager1)
        c.add_logging_manager(manager2)

        self.assertEqual(list(c.log_files()),
                         ['log1', 'log2', 'log3', 'log4', 'log5'])
Exemple #8
0
    def test_reset(self):
        manager1 = mock.Mock()
        manager2 = mock.Mock()
        c = collection.Collection(
            name='a-name',
            collection='a-collection',
            description='a-description',
            logs_dir='logs',
            log_format=None)
        c.add_logging_manager(manager1)
        c.add_logging_manager(manager2)

        c.reset()
        manager1.reset.assert_called_once_with()
        manager2.reset.assert_called_once_with()
        self.assertIsNone(c.collection)
        self.assertIsNone(c.description)
        self.assertIsNone(c.logs_dir)
        self.assertIsNone(c.log_format)
        self.assertEqual(len(c._event_managers), 0)
        self.assertIsNone(manager1.collection_object)
        self.assertIsNone(manager2.collection_object)
Exemple #9
0
    def test_events_inconsistent_log_formats(self):
        manager1 = mock.Mock()
        manager2 = mock.Mock()

        def iter1():
            for x in (
                    ('log1', collection.LogFormats.InfluxDB, 'log1.txt'),
                    ('log2', collection.LogFormats.InfluxDB, 'log2.txt')):
                yield x

        def iter2():
            for x in (
                    ('log3', collection.LogFormats.CSV, 'log3.txt'),):
                yield x

        manager1.log_files.return_value = iter1()
        manager2.log_files.return_value = iter2()

        c = collection.Collection()
        c.add_logging_manager(manager1)
        c.add_logging_manager(manager2)

        with self.assertRaises(AssertionError):
            self.assertEqual(c.events(), 'a-streamer')
Exemple #10
0
 def test__ensure_logs_dir_is_none(self):
     self.mock_mkdtemp.return_value = 'temp-logs'
     c = collection.Collection()
     c._ensure_logs_dir()
     self.assertEqual(c.logs_dir, 'temp-logs')
     self.mock_mkdtemp.assert_called_once_with()
Exemple #11
0
 def test__ensure_logs_dir_is_not_none(self):
     self.mock_mkdtemp.return_value = "temp-logs"
     c = collection.Collection(logs_dir='logs')
     c._ensure_logs_dir()
     self.assertEqual(c.logs_dir, 'logs')
     self.mock_mkdtemp.assert_not_called()