def test_init_warn(self): config = MagicMock() config.get.return_value = 10 DataCleaner.logger.reset_mock() cleaner = DataCleaner.DataCleaner(config) self.assertTrue(DataCleaner.logger.warn.called) self.assertTrue(cleaner.file_max_age == 3600)
def test_init_warn(self): config = MagicMock() config.get.side_effect = [1, (3600 - 1), (10000 + 1), "/test_path"] DataCleaner.logger.reset_mock() cleaner = DataCleaner.DataCleaner(config) self.assertTrue(DataCleaner.logger.warn.called) self.assertTrue(cleaner.file_max_age == 86400) self.assertTrue(cleaner.cleanup_interval == 3600) self.assertTrue(cleaner.cleanup_max_size_MB == 10000)
def test_config(self): """ Verify that if the config does not have a property, default values are used. """ DataCleaner.logger.reset_mock() config = AmbariConfig.AmbariConfig() config.remove_option('agent', 'data_cleanup_max_age') config.remove_option('agent', 'data_cleanup_interval') config.remove_option('agent', 'data_cleanup_max_size_MB') cleaner = DataCleaner.DataCleaner(config) self.assertEqual(cleaner.file_max_age, 86400) self.assertEqual(cleaner.cleanup_interval, 3600) self.assertEqual(cleaner.cleanup_max_size_MB, 10000)
def test_cleanup_success(self, remMock, mtimeMock, timeMock, walkMock): self.config.reset_mock() DataCleaner.logger.reset_mock() walkMock.return_value = iter(self.test_dir) timeMock.return_value = 2592000 + 2 mtimeMock.side_effect = [1, 1, 1, 2, 1, 1] cleaner = DataCleaner.DataCleaner(self.config) cleaner.cleanup() self.assertTrue(len(remMock.call_args_list) == 4) remMock.assert_any_call('/test_path/errors-12.txt') remMock.assert_any_call('/test_path/output-12.txt') remMock.assert_any_call('/test_path/site-12.pp') remMock.assert_any_call('/test_path/site-15.pp') pass
def test_cleanup_success(self, sizeMock, remMock, mtimeMock, timeMock, walkMock): self.config.reset_mock() DataCleaner.logger.reset_mock() walkMock.return_value = iter(self.test_dir) timeMock.return_value = 2592000 + 2 mtimeMock.side_effect = [1, 1, 1, 2, 1, 1, 1, 1] sizeMock.return_value = 100 cleaner = DataCleaner.DataCleaner(self.config) cleaner.cleanup() self.assertTrue(len(remMock.call_args_list) == 6) remMock.assert_any_call(os.path.join('test_path', 'errors-12.txt')) remMock.assert_any_call(os.path.join('test_path', 'output-12.txt')) remMock.assert_any_call(os.path.join('test_path', 'site-12.pp')) remMock.assert_any_call(os.path.join('test_path', 'site-15.pp')) remMock.assert_any_call(os.path.join('test_path', 'structured-out-13.json')) remMock.assert_any_call(os.path.join('test_path', 'command-13.json')) pass
def test_cleanup_remove_error(self, sizeMock, remMock, mtimeMock, timeMock, walkMock): self.config.reset_mock() DataCleaner.logger.reset_mock() walkMock.return_value = iter(self.test_dir) timeMock.return_value = 2592000 + 2 mtimeMock.side_effect = [1, 1, 1, 2, 1, 1, 1, 1] sizeMock.return_value = 100 def side_effect(arg): if arg == os.path.join('test_path', 'site-15.pp'): raise Exception("Can't remove file") remMock.side_effect = side_effect cleaner = DataCleaner.DataCleaner(self.config) cleaner.cleanup() self.assertTrue(len(remMock.call_args_list) == 6) self.assertTrue(DataCleaner.logger.error.call_count == 1) pass
def test_init_success(self): config = MagicMock() config.get.side_effect = [2592000, (3600 + 1), 10000, "/test_path"] DataCleaner.logger.reset_mock() cleaner = DataCleaner.DataCleaner(config) self.assertFalse(DataCleaner.logger.warn.called)
def test_init_success(self): config = MagicMock() config.get.return_value = 2592000 DataCleaner.logger.reset_mock() cleaner = DataCleaner.DataCleaner(config) self.assertFalse(DataCleaner.logger.warn.called)