def test_ingest_nightly_with_params(self): workflow_name = 'GC-fast_workflow' workflow_parameters = 'trimHold:true;' repo = Repository('/tmp/repo_night') dispatcher = Dispatcher() logger = Logger(None) w = worker.Worker(dispatcher, repo, logger, self.client) mp = mediapackage.Mediapackage() repo.add(mp) w.enqueue_nightly_job_by_name( worker.INGEST_CODE, mp, { 'workflow': workflow_name, 'workflow_parameters': workflow_parameters }) dispatcher.emit('timer-nightly') time.sleep(1) # Need time to create zip self.assertEqual(len(self.client.calls), 1) self.assertEqual(self.client.calls[0]['workflow'], workflow_name) self.assertEqual(self.client.calls[0]['workflow_parameters'], workflow_parameters) self.assertEqual(mp.getOpStatus(worker.INGEST_CODE), mediapackage.OP_DONE) rmtree('/tmp/repo_night')
def __get_dependencies(self): dispatcher = context.get_dispatcher() repo = Repository(self.tmppath) worker = self.WorkerMock() conf = Conf() conf.reload() conf.set("allows", "overlap", "False") logger = Logger(None) return dispatcher, repo, worker, conf, logger
def setUp(self): self.logger_filename = '/tmp/galicaster_test.log' self.repo = self.RepoMock() self.client = self.OCHTTPClientMock() self.dispatcher = self.DispatcherMock() self.logger = Logger(self.logger_filename) self.worker = worker.Worker(self.dispatcher, self.repo, self.logger, self.client) self.repo1 = Repository() self.mp = mediapackage.Mediapackage() self.repo1.add(self.mp)
def get_logger(): """ Get the Logger class from the App Context """ if 'logger' not in __galicaster_context: conf = get_conf() logger = Logger(conf.get('logger', 'path'), conf.get('logger', 'level').upper(), conf.get_boolean('logger', 'rotate'), conf.get_boolean('logger', 'use_syslog')) __galicaster_context['logger'] = logger conf.logger = logger return __galicaster_context['logger']
def test_manual(self): repo = self.RepoMock() client = self.MHHTTPClientMock() dispatcher = self.DispatcherMock() logger = Logger(None) w = worker.Worker(dispatcher, repo, logger, client) mp = mediapackage.Mediapackage(uri='/tmp') mp.manual = True w._ingest(mp) self.assertEqual(client.calls[0]['workflow'], None) self.assertEqual(client.calls[0]['workflow_instance'], None) self.assertEqual(client.calls[0]['workflow_parameters'], None)
def test_ingest_nightly(self): repo = Repository('/tmp/repo_night') dispatcher = Dispatcher() logger = Logger(None) w = worker.Worker(dispatcher, repo, logger, self.client) mp = mediapackage.Mediapackage() mp.setOpStatus(worker.INGEST_CODE, mediapackage.OP_NIGHTLY) repo.add(mp) dispatcher.emit('timer-nightly') time.sleep(1) # Need time to create zip self.assertEqual(len(self.client.calls), 1) self.assertEqual(mp.getOpStatus(worker.INGEST_CODE), mediapackage.OP_DONE) rmtree('/tmp/repo_night')
def test_no_manual_only_workflow(self): repo = self.RepoMock() client = self.MHHTTPClientMock() dispatcher = self.DispatcherMock() logger = Logger(None) w = worker.Worker(dispatcher, repo, logger, client) mp = mediapackage.Mediapackage(identifier='1', uri='/tmp') mp.addAttachmentAsString( 'org.opencastproject.workflow.definition=mini-full', name='org.opencastproject.capture.agent.properties', identifier='org.opencastproject.capture.agent.properties') mp.manual = False w._ingest(mp) self.assertEqual(client.calls[0]['workflow'], 'mini-full') self.assertEqual(client.calls[0]['workflow_instance'], '1') self.assertEqual(client.calls[0]['workflow_parameters'], {})
def test_no_manual(self): repo = self.RepoMock() client = self.MHHTTPClientMock() dispatcher = self.DispatcherMock() logger = Logger(None) w = worker.Worker(dispatcher, repo, logger, client) mp = mediapackage.Mediapackage(identifier='1', uri='/tmp') mp.add(self.path_capture_agent_properties, mediapackage.TYPE_ATTACHMENT, identifier='org.opencastproject.capture.agent.properties') mp.manual = False w._ingest(mp) self.assertEqual(client.calls[0]['workflow'], 'full') self.assertEqual(client.calls[0]['workflow_instance'], '1') self.assertEqual(client.calls[0]['workflow_parameters'], { 'trimHold': 'false', 'captionHold': 'false' })
def get_logger(): """Creates if necessary and retrieves the Logger class from the App Context. Returns: Logger: the logger in galicaster app. """ from galicaster.core.logger import Logger if 'logger' not in __galicaster_context: conf = get_conf() logger = Logger( conf.get('logger', 'path'), conf.get_choice_uppercase('logger', 'level', [ 'CRITICAL', 'ERROR', 'WARN', 'WARNING', 'INFO', 'DEBUG', 'NOTSET' ], 'DEBUG'), conf.get_boolean('logger', 'rotate'), conf.get_boolean('logger', 'use_syslog')) __galicaster_context['logger'] = logger conf.logger = logger return __galicaster_context['logger']
def test_init_parameters(self): repo = self.RepoMock() client = self.MHHTTPClientMock() dispatcher = self.DispatcherMock() logger = Logger(None) w = worker.Worker(dispatcher, repo, logger, client) self.assertEqual(w.export_path, os.path.expanduser('~')) self.assertEqual(w.tmp_path, tempfile.gettempdir()) #self.assertRaises(OSError, worker.Worker, repo, client, '/a/b/c', None) #self.assertRaises(OSError, worker.Worker, repo, client, None, '/a/b/c') w = worker.Worker(dispatcher, repo, logger, client, '/tmp/galicaster_tdd/a/b/c', '/tmp/galicaster_tdd/1/2/3') self.assertEqual(w.export_path, '/tmp/galicaster_tdd/a/b/c') self.assertEqual(w.tmp_path, '/tmp/galicaster_tdd/1/2/3') for dir_path in ('/tmp/galicaster_tdd/a/b/c', '/tmp/galicaster_tdd/1/2/3'): self.assertTrue(os.path.isdir(dir_path)) rmtree('/tmp/galicaster_tdd')