mocked all the html and js with local fixtures
Browse files- tests/test_pytube.py +16 -39
tests/test_pytube.py
CHANGED
@@ -1,45 +1,22 @@
|
|
1 |
#!/usr/bin/env/python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
|
4 |
-
|
5 |
-
from
|
6 |
-
from pytube
|
7 |
|
8 |
|
9 |
-
class
|
10 |
-
"""Test all methods of Youtube class"""
|
11 |
-
|
12 |
def setUp(self):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
def
|
23 |
-
|
24 |
-
|
25 |
-
def test_video_id(self):
|
26 |
-
eq_(self.yt.video_id, self.video_id)
|
27 |
-
|
28 |
-
def test_filename(self):
|
29 |
-
eq_(self.yt.filename, self.filename)
|
30 |
-
|
31 |
-
def test_get_videos(self):
|
32 |
-
eq_(self.yt.get_videos())
|
33 |
-
|
34 |
-
def test_get_video_data(self):
|
35 |
-
eq_((self.yt.get_video_data()['args']['loaderUrl']), self.url)
|
36 |
-
|
37 |
-
@raises(MultipleObjectsReturned)
|
38 |
-
def test_get_false(self):
|
39 |
-
self.yt.get()
|
40 |
-
|
41 |
-
def test_get_true(self):
|
42 |
-
eq_(str(self.yt.get('flv')), self.flv)
|
43 |
-
|
44 |
-
def test_filter(self):
|
45 |
-
eq_(str(self.yt.filter('flv')[0]), self.flv)
|
|
|
1 |
#!/usr/bin/env/python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
|
4 |
+
import mock
|
5 |
+
from nose.tools import eq_
|
6 |
+
from pytube import api
|
7 |
|
8 |
|
9 |
+
class TestPytube(object):
|
|
|
|
|
10 |
def setUp(self):
|
11 |
+
url = 'http://www.youtube.com/watch?v=Ik-RsDGPI5Y'
|
12 |
+
mock_js = open('tests/mock_video.js')
|
13 |
+
mock_html = open('tests/mock_video.html')
|
14 |
+
with mock.patch('pytube.api.urlopen') as urlopen:
|
15 |
+
urlopen.return_value.read.return_value = mock_html.read()
|
16 |
+
self.yt = api.YouTube()
|
17 |
+
self.yt._js_code = mock_js.read()
|
18 |
+
self.yt.from_url(url)
|
19 |
+
|
20 |
+
def test_get_video_id(self):
|
21 |
+
"""Resolve the video id from url"""
|
22 |
+
eq_(self.yt.video_id, 'Ik-RsDGPI5Y')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|