def _teardown_video(context): delete_instances([context.video.id]) try: os.remove(context._subtitle_file_path) except WindowsError as e: print("Couldn't remove temporary subtitle file {}. Exception:\n\t{}". format(context._subtitle_file_path, str(e)))
def _make_video(context): root = get({"parent": None}) lang_code = "en" youtube_id = "my_cool_id" item_dict = { "title": "Subtitled Video", "description": "A video with subtitles", "available": True, "kind": "Video", "id": "video_with_subtitles", "slug": "video_with_subtitles", "path": "khan/video_with_subtitles", "extra_fields": { "subtitle_urls": [{"url": get_subtitle_url(youtube_id=youtube_id, code=lang_code), "code": lang_code, "name": "English"}], "content_urls": {"stream": "/foo", "stream_type": "video/mp4"}, }, "parent": root, } # `create` will quietly do nothing if the item already exists. Possible from pathological test runs. # So delete any identical Items first. delete_instances(ids=[item_dict["id"]]) context.video = create(item_dict) subtitle_path = get_subtitle_file_path(lang_code=lang_code, youtube_id=youtube_id) with open(subtitle_path, "w") as f: f.write("foo") context._subtitle_file_path = subtitle_path
def _teardown_video(context): delete_instances([context.video.id]) try: os.remove(context._subtitle_file_path) except WindowsError as e: print("Couldn't remove temporary subtitle file {}. Exception:\n\t{}".format( context._subtitle_file_path, str(e)) )
def _make_video(context): root = get({"parent": None}) lang_code = "en" youtube_id = "my_cool_id" item_dict = { "title": "Subtitled Video", "description": "A video with subtitles", "available": True, "kind": "Video", "id": "video_with_subtitles", "slug": "video_with_subtitles", "path": "khan/video_with_subtitles", "extra_fields": { "subtitle_urls": [{ "url": get_subtitle_url(youtube_id=youtube_id, code=lang_code), "code": lang_code, "name": "English" }], "content_urls": { "stream": "/foo", "stream_type": "video/mp4" }, }, "parent": root, } # `create` will quietly do nothing if the item already exists. Possible from pathological test runs. # So delete any identical Items first. delete_instances(ids=[item_dict["id"]]) context.video = create(item_dict) subtitle_path = get_subtitle_file_path(lang_code=lang_code, youtube_id=youtube_id) subtitle_dir = os.path.dirname(subtitle_path) if not os.path.exists(subtitle_dir): os.makedirs(subtitle_dir) with open(subtitle_path, "w") as f: f.write("foo") context._subtitle_file_path = subtitle_path