22import json
33import os
44import shutil
5- from apiclient .discovery import build
6- from apiclient .http import HttpMock
7- from mock import patch
85
96from django .conf import settings
107from django .urls import reverse
2118from ietf .secr .proceedings .proc_utils import (import_audio_files ,
2219 get_timeslot_for_filename , normalize_room_name , send_audio_import_warning ,
2320 get_or_create_recording_document , create_recording , get_next_sequence ,
24- get_youtube_playlistid , get_youtube_videos , import_youtube_video_urls ,
2521 _get_session , _get_urls_from_json )
2622
2723
@@ -43,47 +39,6 @@ def test_main(self):
4339
4440
4541class VideoRecordingTestCase (TestCase ):
46- @patch ('ietf.secr.proceedings.proc_utils.get_youtube_videos' )
47- @patch ('ietf.secr.proceedings.proc_utils.get_youtube_playlistid' )
48- def test_import_youtube_video_urls (self , mock_playlistid , mock_videos ):
49- meeting = make_meeting_test_data ()
50- session = Session .objects .filter (meeting = meeting , group__acronym = 'mars' ).first ()
51- title = self ._get_video_title_for_session (session )
52- url = 'https://youtube.com?v=test'
53- mock_playlistid .return_value = 'PLC86T-6ZTP5g87jdxNqdWV5475U-yEE8M'
54- mock_videos .return_value = [{'title' :title ,'url' :url }]
55- discovery = os .path .join (settings .BASE_DIR , "../test/data/youtube-discovery.json" )
56- http = HttpMock (discovery , {'status' : '200' })
57- import_youtube_video_urls (meeting = meeting , http = http )
58- doc = Document .objects .get (external_url = url )
59- self .assertTrue (doc in session .materials .all ())
60-
61- def _get_video_title_for_session (self , session ):
62- '''Returns the youtube video title of a session recording given session'''
63- timeslot = session .official_timeslotassignment ().timeslot
64- return "{prefix}-{group}-{date}" .format (
65- prefix = session .meeting .type .slug + session .meeting .number ,
66- group = session .group .acronym ,
67- date = timeslot .time .strftime ('%Y%m%d-%H%M' )).upper ()
68-
69- def test_get_youtube_playlistid (self ):
70- discovery = os .path .join (settings .BASE_DIR , "../test/data/youtube-discovery.json" )
71- http = HttpMock (discovery , {'status' : '200' })
72- youtube = build (settings .YOUTUBE_API_SERVICE_NAME , settings .YOUTUBE_API_VERSION ,
73- developerKey = '' ,http = http )
74- path = os .path .join (settings .BASE_DIR , "../test/data/youtube-playlistid.json" )
75- http = HttpMock (path , {'status' : '200' })
76- self .assertEqual (get_youtube_playlistid (youtube , 'IETF98' , http = http ),'PLC86T-test' )
77-
78- def test_get_youtube_videos (self ):
79- discovery = os .path .join (settings .BASE_DIR , "../test/data/youtube-discovery.json" )
80- http = HttpMock (discovery , {'status' : '200' })
81- youtube = build (settings .YOUTUBE_API_SERVICE_NAME , settings .YOUTUBE_API_VERSION ,
82- developerKey = '' ,http = http )
83- path = os .path .join (settings .BASE_DIR , "../test/data/youtube-playlistitems.json" )
84- http = HttpMock (path , {'status' : '200' })
85- videos = get_youtube_videos (youtube , 'PLC86T' , http = http )
86- self .assertEqual (len (videos ),2 )
8742
8843 def test_get_session (self ):
8944 meeting = make_meeting_test_data ()
0 commit comments