Exemplo n.º 1
0
    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')
Exemplo n.º 2
0
    def test_connect_and_emit(self):
        dispatcher = Dispatcher()

        dispatcher.connect('pr', self.callback)
        obj = {'called': False}
        dispatcher.emit('pr', obj)

        self.assertTrue(obj['called'])
    def test_connect_ui_and_emit(self):
        global called
        called = False
        
        dispatcher = Dispatcher()

        dispatcher.connect_ui('pr', self.callback_ui)
        obj = {'called': False}

        timeout_id = GObject.timeout_add_seconds(1, self.emit_signal, dispatcher, 'pr', obj)
        Gtk.main()
        self.assertTrue(called)
Exemplo n.º 4
0
    def test_connect_ui_and_emit(self):
        global called
        called = False

        dispatcher = Dispatcher()

        dispatcher.connect_ui('pr', self.callback_ui)
        obj = {'called': False}

        timeout_id = GObject.timeout_add_seconds(1, self.emit_signal,
                                                 dispatcher, 'pr', obj)
        Gtk.main()
        self.assertTrue(called)
Exemplo n.º 5
0
    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')
Exemplo n.º 6
0
    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')
Exemplo n.º 7
0
    def test_add_new_signal(self):
        dispatcher = Dispatcher()
        dispatcher.add_new_signal('test-signal', True)

        dispatcher.connect('test-signal', self.callback)
        obj = {'called': False}
        dispatcher.emit('test-signal', obj)

        self.assertTrue(obj['called'])
Exemplo n.º 8
0
def get_dispatcher():
    """
    Get the Dispatcher class from the App Context
    """
    if 'dispatcher' not in __galicaster_context:
        __galicaster_context['dispatcher'] = Dispatcher()

    return __galicaster_context['dispatcher']
Exemplo n.º 9
0
    def test_exec_nightly(self):
        repo = Repository('/tmp/repo_night')
        client = self.MHHTTPClientMock()
        dispatcher = Dispatcher()
        w = worker.Worker(dispatcher, repo, client)

        mp = mediapackage.Mediapackage()
        mp.setOpStatus(worker.INGEST_CODE, mediapackage.OP_NIGHTLY)
        repo.add(mp)

        dispatcher.emit('galicaster-notify-nightly')
        time.sleep(1) # Need time to create zip

        self.assertEqual(len(client.calls), 1)
        self.assertEqual(mp.getOpStatus(worker.INGEST_CODE), mediapackage.OP_DONE)

        rmtree('/tmp/repo_night')
Exemplo n.º 10
0
    def test_get_two_seg_until_next(self):
        dispatcher = Dispatcher()

        now = datetime.now()
        after_now = now + timedelta(minutes=1)
        n = Heartbeat(dispatcher, 1, 2, after_now.strftime('%H:%M'))
        one = n.get_seg_until_next()
        two = n.get_seg_until_next()
        self.assertTrue(two - one < 2)
Exemplo n.º 11
0
    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')
Exemplo n.º 12
0
    def test_add_new_signal(self):
        dispatcher = Dispatcher()
        dispatcher.add_new_signal('test-signal', True)

        dispatcher.connect('test-signal', self.callback)        
        obj = {'called': False}
        dispatcher.emit('test-signal', obj)

        self.assertTrue(obj['called'])
Exemplo n.º 13
0
    def test_init(self):
        dispatcher = Dispatcher()

        time_ok = ['10:10', '23:04', '1:2']
        time_ko = ['10-10', '23:12234', 'doce', '1:_2', 'tonight']

        for t in time_ok:
            Heartbeat(dispatcher, 1, 2, t)

        for t in time_ko:
            self.assertRaises(ValueError, Heartbeat, dispatcher, 1, 2, t)
Exemplo n.º 14
0
def get_dispatcher():
    """Creates if necessary and retrieves the Dispatcher class from the App Context.
    Returns:
      Dispatcher: the dispatcher instance in galicaster context.
    """
    from galicaster.core.dispatcher import Dispatcher

    if 'dispatcher' not in __galicaster_context:
        __galicaster_context['dispatcher'] = Dispatcher()

    return __galicaster_context['dispatcher']
Exemplo n.º 15
0
    def test_connect_and_emit(self):
        dispatcher = Dispatcher()

        dispatcher.connect('pr', self.callback)
        obj = {'called': False}

        dispatcher.emit('pr', obj)
        self.assertTrue(obj['called'])
Exemplo n.º 16
0
    def test_get_seg_until_next(self):
        dispatcher = Dispatcher()

        now = datetime.now()
        after_now = now + timedelta(minutes=1)
        n = Heartbeat(dispatcher, 1, 2, after_now.strftime('%H:%M'))
        seg = n.get_seg_until_next()

        self.assertLess(seg, 60)
        self.assertGreater(seg, 0)

        now = datetime.now()
        after_now = now - timedelta(hours=1)
        n = Heartbeat(dispatcher, 1, 2, after_now.strftime('%H:%M'))
        seg = n.get_seg_until_next()
        self.assertTrue(seg > 22 * 3600)
        self.assertTrue(seg < 24 * 3600)
Exemplo n.º 17
0
    def test_get_seg_until_next_now(self):
        dispatcher = Dispatcher()

        now = datetime.now()
        n = Heartbeat(dispatcher, 1, 2, now.strftime('%H:%M'))
        self.assertTrue(n.get_seg_until_next(), 24 * 60 * 60)