def test_get_videos_for_id(self): """ Tests retrieving videos for id """ edx_video_id = constants.VIDEO_DICT_FISH["edx_video_id"] videos = list(api.get_videos_for_ids([edx_video_id])) self.assertEqual(len(videos), 1) self.assertEqual(videos[0]["edx_video_id"], edx_video_id) videos = list(api.get_videos_for_ids(["unknown"])) self.assertEqual(len(videos), 0)
def test_get_videos_for_id(self): """ Tests retrieving videos for id """ edx_video_id = constants.VIDEO_DICT_FISH['edx_video_id'] videos = list(api.get_videos_for_ids([edx_video_id])) self.assertEqual(len(videos), 1) self.assertEqual(videos[0]['edx_video_id'], edx_video_id) videos = list(api.get_videos_for_ids(['unknown'])) self.assertEqual(len(videos), 0)
def test_get_videos_for_ids_duplicates(self): """ Tests retrieving videos for ids when there are duplicate ids """ edx_video_id = constants.VIDEO_DICT_FISH["edx_video_id"] videos = list(api.get_videos_for_ids([edx_video_id, edx_video_id])) self.assertEqual(len(videos), 1)
def test_get_videos_for_ids_duplicates(self): """ Tests retrieving videos for ids when there are duplicate ids """ edx_video_id = constants.VIDEO_DICT_FISH['edx_video_id'] videos = list(api.get_videos_for_ids([edx_video_id, edx_video_id])) self.assertEqual(len(videos), 1)
def _get_videos(course): """ Retrieves the list of videos from VAL corresponding to the videos listed in the asset metadata store and returns the needed subset of fields """ edx_videos_ids = [ v.asset_id.path for v in modulestore().get_all_asset_metadata( course.id, VIDEO_ASSET_TYPE) ] return list({ attr: video[attr] for attr in ["edx_video_id", "client_video_id", "created", "duration", "status"] } for video in get_videos_for_ids(edx_videos_ids))
def _get_videos(course): """ Retrieves the list of videos from VAL corresponding to the videos listed in the asset metadata store. """ edx_videos_ids = [v.asset_id.path for v in modulestore().get_all_asset_metadata(course.id, VIDEO_ASSET_TYPE)] videos = list(get_videos_for_ids(edx_videos_ids, VideoSortField.created, SortDirection.desc)) # convert VAL's status to studio's Video Upload feature status. for video in videos: video["status"] = StatusDisplayStrings.get(video["status"]) return videos
def test_get_videos_for_ids(self): """ Tests retrieving videos for ids """ Video.objects.create(**constants.VIDEO_DICT_DIFFERENT_ID_FISH) EncodedVideo.objects.create( video=Video.objects.get(edx_video_id=constants.VIDEO_DICT_DIFFERENT_ID_FISH.get("edx_video_id")), profile=Profile.objects.get(profile_name="mobile"), **constants.ENCODED_VIDEO_DICT_MOBILE ) edx_video_id = constants.VIDEO_DICT_FISH["edx_video_id"] edx_video_id_2 = constants.VIDEO_DICT_DIFFERENT_ID_FISH["edx_video_id"] videos = list(api.get_videos_for_ids([edx_video_id, edx_video_id_2])) self.assertEqual(len(videos), 2)
def test_get_videos_for_ids(self): """ Tests retrieving videos for ids """ Video.objects.create(**constants.VIDEO_DICT_DIFFERENT_ID_FISH) EncodedVideo.objects.create( video=Video.objects.get( edx_video_id=constants.VIDEO_DICT_DIFFERENT_ID_FISH.get( "edx_video_id")), profile=Profile.objects.get(profile_name="mobile"), **constants.ENCODED_VIDEO_DICT_MOBILE) edx_video_id = constants.VIDEO_DICT_FISH['edx_video_id'] edx_video_id_2 = constants.VIDEO_DICT_DIFFERENT_ID_FISH['edx_video_id'] videos = list(api.get_videos_for_ids([edx_video_id, edx_video_id_2])) self.assertEqual(len(videos), 2)
def _get_videos(course): """ Retrieves the list of videos from VAL corresponding to the videos listed in the asset metadata store and returns the needed subset of fields """ edx_videos_ids = [ v.asset_id.path for v in modulestore().get_all_asset_metadata(course.id, VIDEO_ASSET_TYPE) ] return list( { attr: video[attr] for attr in ["edx_video_id", "client_video_id", "created", "duration", "status"] } for video in get_videos_for_ids(edx_videos_ids) )
def create(self, request, *args, **kwargs): # pylint: disable=unused-argument """ Creates an HLS video object for a course and returns a serialized version of the newly-created video object """ course_id = kwargs.get("course_id") file_name = request.data.get("filename") hls_url = request.data.get("hls_url") error = None if not file_name: error = u"Request does not contain file name" if not hls_url: error = u"Request does not contain HLS URL" elif not is_valid_hls_url(hls_url): error = u"Request does not contain a valid HLS URL" if error: return Response({ERROR_KEY: error}, status=status.HTTP_400_BAD_REQUEST) edx_video_id = unicode(uuid4()) try: video_id = create_video({ "edx_video_id": edx_video_id, "status": "file_complete", "client_video_id": file_name, "duration": 0, "encoded_videos": [{ "profile": "hls", "url": hls_url, "bitrate": 0, "file_size": 0 }], "courses": [course_id] }) except ValCannotCreateError as exc: return Response( { ERROR_KEY: u"Could not create video (exception: {})".format(str(exc)) }, status=status.HTTP_400_BAD_REQUEST) serialized_video = next(get_videos_for_ids([video_id])) return Response(json_serialize_video(serialized_video))
def _get_videos(course): """ Retrieves the list of videos from VAL corresponding to the videos listed in the asset metadata store. """ edx_videos_ids = [ v.asset_id.path for v in modulestore().get_all_asset_metadata( course.id, VIDEO_ASSET_TYPE) ] videos = list(get_videos_for_ids(edx_videos_ids)) # convert VAL's status to studio's Video Upload feature status. for video in videos: video["status"] = StatusDisplayStrings.get(video["status"]) return videos
def _get_videos(course): """ Retrieves the list of videos from VAL corresponding to the videos listed in the asset metadata store. """ edx_videos_ids = [ v.asset_id.path for v in modulestore().get_all_asset_metadata(course.id, VIDEO_ASSET_TYPE) ] videos = list(get_videos_for_ids(edx_videos_ids)) # convert VAL's status to studio's Video Upload feature status. for video in videos: video["status"] = status_display_string(video["status"]) return videos
def api_func(expected_ids, sort_field, sort_direction): return api.get_videos_for_ids(expected_ids, sort_field, sort_direction)
def api_func(expected_ids, sort_field, sort_direction): return api.get_videos_for_ids( expected_ids, sort_field, sort_direction, )