def test_run_check_tasks_except_check(self, m_log): m_run = FirstTimeRun() check_task = FirstTimeRun.CheckTask(True, self.fake_task) m_run._check_tasks.append(check_task) m_run._run_check_tasks() m_log.error.assert_called_once()
def test_run_check_tasks(self): # Crate a mocked method m_method = mock.Mock() m_run = FirstTimeRun() # create CheckTask instance check_task = FirstTimeRun.CheckTask(self.fake_check_true, m_method) m_run._check_tasks.append(check_task) m_run._run_check_tasks() m_method.assert_called_once()
def test_run_check_tasks_except_task(self, m_log): # Crate a mocked method m_method = mock.Mock() m_method.side_effect = Exception("Whoops") m_run = FirstTimeRun() check_task = FirstTimeRun.CheckTask(self.fake_check_true, m_method) # Force mocked method into the tasks list m_run._check_tasks.append(check_task) m_run._run_check_tasks() m_method.assert_called_once() m_log.error.assert_called_once()
def main(): configurator.setup_config_and_logging(sys.argv, CONF) # Display logo's LOG.info(ascii_logo.TEXT + ascii_logo.LOGO) # Display pid LOG.info(_('Starting RadLoggerPy service on PID %s') % os.getpid()) # Perform first time initialization if required FirstTimeRun() # Create database session for main thread sess = database_manager.create_session() # launch device manager manager = DeviceManager() devices = SerialDeviceObject.find_enabled(sess) for device in devices: manager.launch_device(device) # TODO(Dantali0n): Improve state checking and error handling while True: manager.check_devices() time.sleep(30) # close all database sessions that are still left open database_manager.close_lingering_sessions()
def initialize_app(self, argv): # update configuration (sets CONF.version amongst others) parse_args(argv=()) # Display logo self.LOG.info(ascii_logo.TEXT + ascii_logo.LOGO) # Perform first time initialization if required FirstTimeRun() # Display version self.LOG.info(_('Initializing radloggercli %s') % CONF.version)
def test_constructor(self): m_method = mock.Mock() self.assertEqual(0, len(FirstTimeRun._tasks)) self.assertEqual(0, len(FirstTimeRun._checks)) FirstTimeRun.add_check(self.fake_check_true) FirstTimeRun.add_check(self.fake_check_false) FirstTimeRun.add_task(self.fake_task()) FirstTimeRun._tasks.append(m_method) FirstTimeRun() m_method.assert_called_once()
def test_run_tasks(self): # Crate a mocked method m_method = mock.Mock() m_run = FirstTimeRun() m_run.add_task(self.fake_task) # Force mocked method into the tasks list m_run._tasks.append(m_method) m_run._run_tasks() m_method.assert_called_once()
def test_run_tasks_error(self, m_log): # Crate a mocked method m_method = mock.Mock() m_method.side_effect = Exception("Whoops") m_run = FirstTimeRun() m_run.add_task(self.fake_task) # Force mocked method into the tasks list m_run._tasks.append(m_method) m_run._run_tasks() m_method.assert_called_once() m_log.error.assert_called_once()
def test_run_checks_false(self): m_run = FirstTimeRun() m_run.add_check(self.fake_check_false) self.assertFalse(m_run._run_checks())
from radloggerpy import config from cliff import app from cliff import commandmanager from cliff.complete import CompleteCommand from radloggerpy._i18n import _ from radloggerpy.common import ascii_logo from radloggerpy.common.first_time_run import FirstTimeRun from radloggerpy.config.config import parse_args from radloggerpy.database import database_manager as dm from radloggerpy import version CONF = config.CONF FirstTimeRun.add_check_task(dm.check_database_missing, dm.create_database) class RadLoggerShell(app.App): """RadLoggerPy interactive command line interface""" def __init__(self, **kwargs): super().__init__( description=self.__doc__.strip(), version=version.version_string, command_manager=commandmanager.CommandManager('radloggerpy.cli'), deferred_help=True, **kwargs) self.command_manager.add_command('complete', CompleteCommand) self.database_session = dm.create_session() def initialize_app(self, argv):
def test_run_checks_all_true(self): m_run = FirstTimeRun() m_run.add_check(self.fake_check_true) m_run.add_check(self.fake_check_true) self.assertTrue(m_run._run_checks(all_to_init=True))
def test_run_checks_error(self, m_log): m_run = FirstTimeRun() m_run._checks.append(True) self.assertFalse(m_run._run_checks()) m_log.error.assert_called_once()
def test_add_check_task_fake_task(self, m_log): FirstTimeRun.add_check_task(self.fake_check_true, True) self.assertEqual(0, len(FirstTimeRun._check_tasks)) m_log.warning.assert_called_once()
def test_add_check_task(self): FirstTimeRun.add_check_task(self.fake_check_true, self.fake_task) self.assertEqual(1, len(FirstTimeRun._check_tasks))
def test_add_task_fake(self): FirstTimeRun.add_task(True) self.assertEqual(0, len(FirstTimeRun._tasks))
def test_add_check_fake(self): FirstTimeRun.add_check(True) self.assertEqual(0, len(FirstTimeRun._checks))
def test_run_checks_true(self): m_run = FirstTimeRun() m_run.add_check(self.fake_check_true) self.assertTrue(m_run._run_checks())