nficano commited on
Commit
6ef7310
·
1 Parent(s): 29d3538

mocked all the html and js with local fixtures

Browse files
Files changed (1) hide show
  1. 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
- from nose.tools import eq_, raises
5
- from pytube import YouTube
6
- from pytube.exceptions import MultipleObjectsReturned
7
 
8
 
9
- class TestYouTube(object):
10
- """Test all methods of Youtube class"""
11
-
12
  def setUp(self):
13
- """Set up the all attributes required for a particular video."""
14
-
15
- self.url = "https://www.youtube.com/watch?v=Ik-RsDGPI5Y"
16
- self.video_id = 'Ik-RsDGPI5Y'
17
- self.filename = 'Pulp Fiction - Dancing Scene'
18
- self.yt = YouTube(self.url)
19
- # using flv since it has only once video
20
- self.flv = '<Video: Sorenson H.263 (.flv) - 240p - N/A>'
21
-
22
- def test_url(self):
23
- eq_(self.yt.url, self.url)
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')