Merge pull request #71 from garg10may/master
Browse files- tests/test.py +64 -0
tests/test.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env/python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
|
4 |
+
import os
|
5 |
+
import sys
|
6 |
+
import unittest
|
7 |
+
from pytube import YouTube
|
8 |
+
from pytube.exceptions import MultipleObjectsReturned
|
9 |
+
|
10 |
+
SHOW_ERROR_MESSAGES = True
|
11 |
+
|
12 |
+
class TestYouTube(unittest.TestCase):
|
13 |
+
'''Test all methods of Youtube class'''
|
14 |
+
|
15 |
+
def setUp(self):
|
16 |
+
'''Set up the all attributes required for a particular video'''
|
17 |
+
|
18 |
+
self.url="https://www.youtube.com/watch?v=Ik-RsDGPI5Y"
|
19 |
+
self.video_id = 'Ik-RsDGPI5Y'
|
20 |
+
self.filename = 'Pulp Fiction - Dancing Scene'
|
21 |
+
self.yt = YouTube(self.url)
|
22 |
+
#: don't hard code, make is universal
|
23 |
+
self.videos = ['<Video: MPEG-4 Visual (.3gp) - 144p - Simple>',
|
24 |
+
'<Video: MPEG-4 Visual (.3gp) - 240p - Simple>',
|
25 |
+
'<Video: Sorenson H.263 (.flv) - 240p - N/A>',
|
26 |
+
'<Video: H.264 (.mp4) - 360p - Baseline>',
|
27 |
+
'<Video: H.264 (.mp4) - 720p - High>',
|
28 |
+
'<Video: VP8 (.webm) - 360p - N/A>']
|
29 |
+
# using flv since it has only once video
|
30 |
+
self.flv = '<Video: Sorenson H.263 (.flv) - 240p - N/A>'
|
31 |
+
|
32 |
+
def test_url(self):
|
33 |
+
|
34 |
+
self.assertEqual(self.yt.url ,self.url)
|
35 |
+
|
36 |
+
def test_video_id(self):
|
37 |
+
|
38 |
+
self.assertEqual(self.yt.video_id, self.video_id )
|
39 |
+
|
40 |
+
def test_filename(self):
|
41 |
+
|
42 |
+
self.assertEqual(self.yt.filename, self.filename)
|
43 |
+
|
44 |
+
def test_get_videos(self):
|
45 |
+
|
46 |
+
self.assertEqual ( map( str, self.yt.get_videos() ), self.videos )
|
47 |
+
|
48 |
+
def test_get_video_data(self):
|
49 |
+
|
50 |
+
self.assertEqual((self.yt.get_video_data()['args']['loaderUrl']),
|
51 |
+
self.url)
|
52 |
+
|
53 |
+
def test_get_false(self):
|
54 |
+
with self.assertRaises(MultipleObjectsReturned):
|
55 |
+
self.yt.get()
|
56 |
+
|
57 |
+
def test_get_true(self):
|
58 |
+
self.assertEqual( str( self.yt.get('flv') ), self.flv )
|
59 |
+
|
60 |
+
def test_filter(self):
|
61 |
+
self.assertEqual( str( self.yt.filter('flv')[0] ), self.flv )
|
62 |
+
|
63 |
+
if __name__ == '__main__':
|
64 |
+
unittest.main()
|