This repository has been archived by the owner on Oct 25, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use HTTPS when calling get_video_url API endpoint
We also use requests for this since it has much better SSL support than Python 2's urllib/urllib2.
- Loading branch information
Showing
7 changed files
with
58 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,52 @@ | ||
#!/usr/bin/env python2 | ||
|
||
import json | ||
import httpretty | ||
import os | ||
import yturl | ||
from nose.tools import assert_raises, eq_ as eq | ||
from mock import patch | ||
|
||
|
||
SCRIPT_DIR = os.path.dirname(__file__) | ||
FAKE_URL = 'http://foo.com/' + 'x' * 11 | ||
VIDEO_ID = 'x' * 11 | ||
FAKE_URL = 'http://foo.com/' + VIDEO_ID | ||
|
||
|
||
@httpretty.activate | ||
@patch("yturl.urlopen") | ||
def test_quality_as_word_ok(urlopen_mock): | ||
with open(os.path.join(SCRIPT_DIR, 'files/success_output')) as output_f: | ||
expected = dict(json.load(output_f))[43] | ||
|
||
with open(os.path.join(SCRIPT_DIR, 'files/success_input'), 'rb') as mock_f: | ||
urlopen_mock.return_value = mock_f | ||
chosen_uri = yturl.main(['-q', 'high', FAKE_URL], force_return=True) | ||
eq(chosen_uri, expected) | ||
fake_api_output = mock_f.read() | ||
|
||
httpretty.register_uri( | ||
httpretty.GET, yturl.GVI_BASE_URL + VIDEO_ID, | ||
body=fake_api_output, content_type='application/x-www-form-urlencoded', | ||
) | ||
|
||
chosen_uri = yturl.main(['-q', 'high', FAKE_URL], force_return=True) | ||
eq(chosen_uri, expected) | ||
|
||
|
||
def test_unknown_quality(): | ||
with assert_raises(yturl.UnknownQualityError): | ||
yturl.main(['-q', '123456', FAKE_URL], force_return=True) | ||
|
||
|
||
@httpretty.activate | ||
@patch('yturl.urlopen') | ||
def test_youtube_api_error_exit(urlopen_mock): | ||
mock_filename = os.path.join(SCRIPT_DIR, 'files/embed_restricted') | ||
with open(mock_filename, 'rb') as mock_f: | ||
urlopen_mock.return_value = mock_f | ||
with assert_raises(yturl.YouTubeAPIError): | ||
yturl.main([FAKE_URL], force_return=True) | ||
fake_api_output = mock_f.read() | ||
|
||
httpretty.register_uri( | ||
httpretty.GET, yturl.GVI_BASE_URL + VIDEO_ID, | ||
body=fake_api_output, content_type='application/x-www-form-urlencoded', | ||
) | ||
|
||
with assert_raises(yturl.YouTubeAPIError): | ||
yturl.main([FAKE_URL], force_return=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mock | ||
nose | ||
nose-parameterized | ||
httpretty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters