示例#1
0
    def test_should_search_for_videos_and_save_results(self):
        # given
        context, storage = _create_context_and_storage()

        context.config.archive_all = False
        context.config.monitor_livestreams = False

        storage.video_exist.return_value = False

        context.video_recorders.is_recording_active.return_value = False
        context.livestream_recorders.is_recording_active.return_value = False

        context.api.find_channels.return_value = [CHANNEL_1]
        context.api.find_channel_uploaded_videos.return_value = [VIDEO_1, VIDEO_2]

        # when
        lookup(context, is_first_run=True)

        # then
        storage.add_video.assert_has_calls([
            call(context.api.find_channel_uploaded_videos.return_value[0]),
            call(context.api.find_channel_uploaded_videos.return_value[1])
        ], any_order=True)
        storage.add_livestream.assert_not_called()
        context.livestream_recorders.start_recording.assert_not_called()
        context.video_recorders.start_recording.assert_not_called()
        context.bus.add_event.assert_has_calls([
            call(Event(type=Event.NEW_VIDEO, content=context.api.find_channel_uploaded_videos.return_value[0])),
            call(Event(type=Event.NEW_VIDEO, content=context.api.find_channel_uploaded_videos.return_value[1]))
        ], any_order=True)
        context.bus.retrieve_events.assert_called_once()
        storage.commit.assert_called()
示例#2
0
    def test_should_not_download_if_video_already_exist(self):
        # given
        context, storage = _create_context_and_storage()

        context.config.archive_all = False
        context.config.monitor_livestreams = False

        storage.video_exist.return_value = True

        context.video_recorders.is_recording_active.return_value = False
        context.livestream_recorders.is_recording_active.return_value = False

        context.api.find_channels.return_value = [CHANNEL_1]
        context.api.find_channel_uploaded_videos.return_value = [VIDEO_1, VIDEO_2]

        # when
        lookup(context, is_first_run=False)

        # then
        storage.add_video.assert_not_called()
        storage.add_livestream.assert_not_called()
        context.video_recorders.start_recording.assert_not_called()
        context.livestream_recorders.start_recording.assert_not_called()
        context.bus.add_event.assert_not_called()
        context.bus.retrieve_events.assert_called_once()
        storage.commit.assert_called()
示例#3
0
def _trigger_lookup(context, first_run=False):
    now = datetime.now()
    context.logger.debug('[{}] triggering new lookup...'.format(
        now.strftime('%Y-%m-%d %H:%M:%S')))
    lookup(context, first_run)