def test_error_and_recover(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, autorecover=True, recorderklass=self.recorderklass) self.assertEqual(recorder_service.status, INIT_STATUS) recorder_service.preview() self.__sleep() recorder_service.record() self.assertEqual(recorder_service.error_msg, None) self.assertNotEqual(recorder_service.current_mediapackage, None) dispatcher.emit("recorder-error", "Test Error") self.assertEqual(recorder_service.status, ERROR_STATUS) self.assertEqual(recorder_service.is_error(), True) self.assertNotEqual(recorder_service.error_msg, None) dispatcher.emit("timer-long") while Gtk.events_pending(): Gtk.main_iteration() self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertEqual(recorder_service.error_msg, None) recorder_service.record() self.assertEqual(recorder_service.status, RECORDING_STATUS) self.assertNotEqual(recorder_service.current_mediapackage, None) dispatcher.emit("timer-long") self.assertEqual(recorder_service.status, RECORDING_STATUS) self.assertNotEqual(recorder_service.current_mediapackage, None)
def test_init(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, recorderklass=self.recorderklass) self.assertEqual(recorder_service.status, INIT_STATUS) self.assertEqual(recorder_service.get_recorded_time(), 0)
def test_error_and_recover(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, self.recorderklass) self.assertEqual(recorder_service.status, INIT_STATUS) recorder_service.preview() self.__sleep() recorder_service.record() self.assertEqual(recorder_service.error_msg, None) self.assertNotEqual(recorder_service.current_mediapackage, None) dispatcher.emit("recorder-error", "Test Error") self.assertEqual(recorder_service.status, ERROR_STATUS) self.assertEqual(recorder_service.is_error(), True) self.assertEqual(recorder_service.current_mediapackage, None) self.assertNotEqual(recorder_service.error_msg, None) dispatcher.emit("galicaster-notify-timer-long") self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertEqual(recorder_service.error_msg, None) self.assertEqual(recorder_service.current_mediapackage, None) recorder_service.record() self.assertEqual(recorder_service.status, RECORDING_STATUS) self.assertNotEqual(recorder_service.current_mediapackage, None) dispatcher.emit("galicaster-notify-timer-long") self.assertEqual(recorder_service.status, RECORDING_STATUS) self.assertNotEqual(recorder_service.current_mediapackage, None)
def test_new_recording_when_recording_not_allow(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, recorderklass=self.recorderklass) recorder_service.preview() self.__sleep() recorder_service.record() self.__sleep() recorder_service.record() self.assertEqual(recorder_service.status, RECORDING_STATUS) self.assertEqual(len(repo), 0) self.__sleep() self.assertEqual(recorder_service.status, RECORDING_STATUS) recorder_service.stop() self.assertEqual(len(repo), 1)
def test_preview(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, recorderklass=self.recorderklass) self.assertEqual(recorder_service.status, INIT_STATUS) recorder_service.preview() self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertEqual(recorder_service.preview(), False) self.assertEqual(recorder_service.stop(), False) self.assertEqual(recorder_service.pause(), False) self.assertEqual(recorder_service.resume(), False) self.__sleep() recorder_service.stop() self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertEqual(len(repo), 0)
def test_new_recording_when_recording(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() conf.set("allows", "overlap", "True") recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, self.recorderklass) recorder_service.preview() self.__sleep() recorder_service.record() self.__sleep() recorder_service.record() self.assertEqual(recorder_service.status, RECORDING_STATUS) self.assertEqual(len(repo), 1) self.__sleep() self.assertEqual(recorder_service.status, RECORDING_STATUS) recorder_service.stop() self.assertEqual(len(repo), 2)
def test_handle_reload_profile(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, self.recorderklass) self.assertEqual(recorder_service.status, INIT_STATUS) recorder_service.preview() old_id = id(recorder_service.recorder) dispatcher.emit("reload-profile") new_id = id(recorder_service.recorder) self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertNotEqual(old_id, new_id) self.__sleep() recorder_service.record() old_id = id(recorder_service.recorder) self.assertEqual(recorder_service.status, RECORDING_STATUS) dispatcher.emit("reload-profile") new_id = id(recorder_service.recorder) self.assertEqual(old_id, new_id) self.assertEqual(recorder_service.status, RECORDING_STATUS)
def test_handle_reload_profile(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() #Necessary for execute test without Glib loop dispatcher.connect_ui = dispatcher.connect recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, recorderklass=self.recorderklass) self.assertEqual(recorder_service.status, INIT_STATUS) recorder_service.preview() old_id = id(recorder_service.recorder) dispatcher.emit("action-reload-profile") new_id = id(recorder_service.recorder) self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertNotEqual(old_id, new_id) self.__sleep() recorder_service.record() old_id = id(recorder_service.recorder) self.assertEqual(recorder_service.status, RECORDING_STATUS) dispatcher.emit("action-reload-profile") new_id = id(recorder_service.recorder) self.assertEqual(old_id, new_id) self.assertEqual(recorder_service.status, RECORDING_STATUS)
def test_recording(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, recorderklass=self.recorderklass) self.assertEqual(recorder_service.status, INIT_STATUS) recorder_service.preview() self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertEqual(recorder_service.current_mediapackage, None) self.__sleep() recorder_service.record() self.assertEqual(recorder_service.status, RECORDING_STATUS) self.assertNotEqual(recorder_service.current_mediapackage, None) self.__sleep() recorder_service.stop() self.assertEqual(recorder_service.current_mediapackage, None) self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertEqual(len(repo), 1)
def get_recorder(): """Creates if necessary and retrives Galicaster Recorder from the App Context. Returns: Recorder: the recorder instance in galicaster context. """ from galicaster.recorder.service import RecorderService if 'recorder' not in __galicaster_context: recorder = RecorderService( get_dispatcher(), get_repository(), get_worker(), get_conf(), get_logger(), get_conf().get_boolean('recorder', 'autorecover', False)) __galicaster_context['recorder'] = recorder return __galicaster_context['recorder']
def test_record_scheduled_mp(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, recorderklass=self.recorderklass) self.assertEqual(len(repo), 0) recorder_service.preview() self.assertEqual(recorder_service.current_mediapackage, None) self.assertEqual(len(repo), 0) self.__sleep() recorder_service.record() self.assertNotEqual(recorder_service.current_mediapackage, None) self.assertEqual(recorder_service.current_mediapackage.status, mediapackage.RECORDING) self.assertEqual(len(repo), 0) self.__sleep() recorder_service.stop() self.assertEqual(recorder_service.current_mediapackage, None) self.assertEqual(len(repo), 1) mp = mediapackage.Mediapackage(title="test") repo.add(mp) self.assertEqual(len(repo), 2) recorder_service.preview() self.assertEqual(recorder_service.current_mediapackage, None) self.assertEqual(len(repo), 2) self.__sleep() recorder_service.record(mp) self.assertEqual(recorder_service.current_mediapackage, mp) self.assertEqual(recorder_service.current_mediapackage.status, mediapackage.RECORDING) self.assertEqual(repo[mp.identifier].status, mediapackage.RECORDING) self.assertEqual(len(repo), 2) self.__sleep() recorder_service.stop() self.assertEqual(recorder_service.current_mediapackage, None) self.assertEqual(len(repo), 2) for mp in repo.values(): self.assertEqual(mp.status, mediapackage.RECORDED)
def test_stop_recoding_on_pause(self): dispatcher, repo, worker, conf, logger = self.__get_dependencies() recorder_service = RecorderService(dispatcher, repo, worker, conf, logger, recorderklass=self.recorderklass) self.assertEqual(recorder_service.status, INIT_STATUS) recorder_service.preview() self.assertEqual(recorder_service.is_recording(), False) self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.__sleep() recorder_service.record() self.assertEqual(recorder_service.is_recording(), True) self.assertEqual(recorder_service.status, RECORDING_STATUS) self.__sleep() recorder_service.pause() self.assertEqual(recorder_service.is_recording(), True) self.assertEqual(recorder_service.status, PAUSED_STATUS) self.__sleep() recorder_service.stop() self.assertEqual(recorder_service.is_recording(), False) self.assertEqual(recorder_service.status, PREVIEW_STATUS) self.assertEqual(len(repo), 1)