added tests for new public api method
This commit is contained in:
		
							parent
							
								
									1bc5087575
								
							
						
					
					
						commit
						66d02c08a1
					
				|  | @ -11,6 +11,8 @@ from youtube_transcript_api import ( | ||||||
|     NoTranscriptFound, |     NoTranscriptFound, | ||||||
|     VideoUnavailable, |     VideoUnavailable, | ||||||
|     NoTranscriptAvailable, |     NoTranscriptAvailable, | ||||||
|  |     NotTranslatable, | ||||||
|  |     TranslationLanguageNotAvailable, | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -48,6 +50,51 @@ class TestYouTubeTranscriptApi(TestCase): | ||||||
|             ] |             ] | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|  |     def test_list_transcripts(self): | ||||||
|  |         transcript_list = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8') | ||||||
|  | 
 | ||||||
|  |         language_codes = {transcript.language_code for transcript in transcript_list} | ||||||
|  | 
 | ||||||
|  |         self.assertEqual(language_codes, {'zh', 'de', 'en', 'hi', 'ja', 'ko', 'es', 'cs', 'en'}) | ||||||
|  | 
 | ||||||
|  |     def test_list_transcripts__find_manually_created(self): | ||||||
|  |         transcript_list = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8') | ||||||
|  |         transcript = transcript_list.find_manually_created_transcript(['cs']) | ||||||
|  | 
 | ||||||
|  |         self.assertFalse(transcript.is_generated) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     def test_list_transcripts__find_generated(self): | ||||||
|  |         transcript_list = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8') | ||||||
|  | 
 | ||||||
|  |         with self.assertRaises(NoTranscriptFound): | ||||||
|  |             transcript_list.find_generated_transcript(['cs']) | ||||||
|  | 
 | ||||||
|  |         transcript = transcript_list.find_generated_transcript(['en']) | ||||||
|  | 
 | ||||||
|  |         self.assertTrue(transcript.is_generated) | ||||||
|  | 
 | ||||||
|  |     def test_translate_transcript(self): | ||||||
|  |         transcript = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8').find_transcript(['en']) | ||||||
|  | 
 | ||||||
|  |         translated_transcript = transcript.translate('af') | ||||||
|  | 
 | ||||||
|  |         self.assertEqual(translated_transcript.language_code, 'af') | ||||||
|  |         self.assertIn('&tlang=af', translated_transcript._url) | ||||||
|  | 
 | ||||||
|  |     def test_translate_transcript__translation_language_not_available(self): | ||||||
|  |         transcript = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8').find_transcript(['en']) | ||||||
|  | 
 | ||||||
|  |         with self.assertRaises(TranslationLanguageNotAvailable): | ||||||
|  |             transcript.translate('xyz') | ||||||
|  | 
 | ||||||
|  |     def test_translate_transcript__not_translatable(self): | ||||||
|  |         transcript = YouTubeTranscriptApi.list_transcripts('GJLlxj_dtq8').find_transcript(['en']) | ||||||
|  |         transcript.translation_languages = [] | ||||||
|  | 
 | ||||||
|  |         with self.assertRaises(NotTranslatable): | ||||||
|  |             transcript.translate('af') | ||||||
|  | 
 | ||||||
|     def test_get_transcript__correct_language_is_used(self): |     def test_get_transcript__correct_language_is_used(self): | ||||||
|         YouTubeTranscriptApi.get_transcript('GJLlxj_dtq8', ['de', 'en']) |         YouTubeTranscriptApi.get_transcript('GJLlxj_dtq8', ['de', 'en']) | ||||||
|         query_string = httpretty.last_request().querystring |         query_string = httpretty.last_request().querystring | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue