Commit 422835e7 authored by Stein Magnus Jodal's avatar Stein Magnus Jodal Committed by GitHub
Browse files

Merge pull request #74 from ticosax/maintain-tests

Maintain tests
parents 8727700d f79d0871
......@@ -95,7 +95,7 @@ def search_youtube(q):
'q': q,
'key': yt_key
}
result = session.get(yt_api_endpoint+'search', params=query)
result = session.get(yt_api_endpoint + 'search', params=query)
data = result.json()
resolve_pool = ThreadPool(processes=16)
......@@ -123,7 +123,7 @@ def resolve_playlist(url):
logger.debug("Get YouTube-Playlist '%s' page %s", url, page)
params['pageToken'] = page
result = session.get(yt_api_endpoint+'playlistItems', params=params)
result = session.get(yt_api_endpoint + 'playlistItems', params=params)
data = result.json()
page = data.get('nextPageToken')
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -5,67 +5,53 @@ interactions:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
User-Agent: [python-requests/2.9.1]
method: GET
uri: https://www.googleapis.com:443/youtube/v3/search?maxResults=15&key=AIzaSyAl1Xq9DwdE_KD4AtPaE4EJl3WZe2zCqg4&type=video&part=id&q=chvrches
uri: https://www.googleapis.com/youtube/v3/search?part=id&q=chvrches&maxResults=15&type=video&key=AIzaSyAl1Xq9DwdE_KD4AtPaE4EJl3WZe2zCqg4
response:
body: {string: !!python/unicode "{\n \"kind\": \"youtube#searchListResponse\"\
,\n \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/EB27u2NyX6LmPLJhLS1uP0bFhV4\\\
\"\",\n \"nextPageToken\": \"CA8QAA\",\n \"pageInfo\": {\n \"totalResults\"\
: 243298,\n \"resultsPerPage\": 15\n },\n \"items\": [\n {\n \"kind\"\
: \"youtube#searchResult\",\n \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/1L7o9RIHG0UaLLGT1d32ax2ffT4\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
TU3b1qyEGsE\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/3IezfTBiiPjbdpd5swNI4Gjx-jk\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
_mTRvJ9fugM\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/dnD7v3fj9beOaIe7j-LusVeUMUg\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
ipE-tnRh4fE\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/2W6aSevqn2e3xeRG5YpZgZlBWjw\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
zM0O1Pqjvuw\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/LGMW7H1MtkhsDLmWsw7R4IRL36o\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
1L9iUhiOXbE\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/YSHn1TNgPRAlT93S47BuyMUzlV4\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
ktoaj1IpTbw\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/Rg4U8fhd5B0WzXmSa8DDa3Jhrjw\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
RWhEUR0I9fo\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/jYmtypJsIvubTpjqp_xEj01401M\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
CjwwmFrsX_E\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/GjyLc47sdTqSDcg0cHnYVburu3A\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
haunJARHPm4\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/qXkLEENk7SdNRzJKrt0ffs44i8Y\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
JyqemIbjcfg\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/KWhkxmFs6poSxCh532xrpAM3qPg\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
JqKTLWhJYBU\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/mRGhpp2ySwRlTej53an0qlUleIk\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
kZfSuYCx9uU\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/kPwTMwlUdVdaA-3OSQV4o7fjOIQ\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
81RqEnvczV8\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/hDedba2GGyxUlSQjXpVHFIEUf3I\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
Kcarb0H6-U0\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/87v4Z1FHkQM3GC1O6I7axv3JIlo\\\
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\
Zdmg9QySDTs\"\n }\n }\n ]\n}\n"}
body: {string: !!python/unicode "{\n \"kind\": \"youtube#searchListResponse\",\n
\"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/VsP4qcJf6cr5ebPm-aH1WTFBsP8\\\"\",\n
\"nextPageToken\": \"CA8QAA\",\n \"regionCode\": \"DE\",\n \"pageInfo\": {\n
\ \"totalResults\": 367059,\n \"resultsPerPage\": 15\n },\n \"items\": [\n
\ {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/N62nNRIBR6JMMA3QHwCDamuj_Rc\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"4Eo84jDIMKI\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/W9dQENrUpeEpmfU_HUrA86qf6qs\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"B9BLMNn0PrQ\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/3IezfTBiiPjbdpd5swNI4Gjx-jk\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"_mTRvJ9fugM\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/_8h0hU7fZscgrbr6Ni8AcZ8SZek\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"BZyzX4c1vIs\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/YSHn1TNgPRAlT93S47BuyMUzlV4\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"ktoaj1IpTbw\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/7EQ7MT5JIRPIsfBOzoAGbmyrKZI\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"KNHxwSp-6Og\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/kPwTMwlUdVdaA-3OSQV4o7fjOIQ\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"81RqEnvczV8\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/6lLxsx4-nzLoy20iBcp6DevuCGQ\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"p_A1PDN2aXw\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/qXkLEENk7SdNRzJKrt0ffs44i8Y\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"JyqemIbjcfg\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/yw8l2TamUNuR1pdri9uul3Y324c\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"pWAkPRKx1HI\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/jYmtypJsIvubTpjqp_xEj01401M\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"CjwwmFrsX_E\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/nFRQICKOptZ_1Ql3WYQRy-xTMeQ\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"3UNP2aJKzyA\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/Wl1rkawwplyT-s8cZWZIutMx84M\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"AU9_0pxiDjY\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/GjyLc47sdTqSDcg0cHnYVburu3A\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"haunJARHPm4\"\n
\ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/1bC-AatWfiadKMhhPyURN4GztXM\\\"\",\n
\ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"fB4gjiMVKFI\"\n
\ }\n }\n ]\n}\n"}
headers:
alternate-protocol: ['443:quic,p=0.02']
alt-svc: ['quic=":443"; ma=2592000; v="35,34"']
cache-control: ['private, max-age=120, must-revalidate, no-transform']
content-length: ['3105']
content-length: ['3126']
content-type: [application/json; charset=UTF-8]
date: ['Fri, 02 Jan 2015 12:17:02 GMT']
etag: ['"F9iA7pnxqNgrkOutjQAa9F2k8HY/EB27u2NyX6LmPLJhLS1uP0bFhV4"']
expires: ['Fri, 02 Jan 2015 12:17:02 GMT']
date: ['Fri, 13 Jan 2017 22:12:22 GMT']
etag: ['"gMxXHe-zinKdE9lTnzKu8vjcmDI/VsP4qcJf6cr5ebPm-aH1WTFBsP8"']
expires: ['Fri, 13 Jan 2017 22:12:22 GMT']
server: [GSE]
vary: [Origin, X-Origin]
x-content-type-options: [nosniff]
......
from __future__ import unicode_literals
import os.path
import mock
import pafy
......@@ -32,28 +34,38 @@ def pafy_mock_with_video(pafy_mock):
return pafy_mock
@vcr.use_cassette('tests/fixtures/youtube_playlist_resolve.yaml')
here = os.path.abspath(os.path.dirname(__file__))
my_vcr = vcr.VCR(
serializer='yaml',
cassette_library_dir=os.path.join(here, 'fixtures'),
record_mode='once',
match_on=['method', 'scheme', 'host', 'port', 'path', 'query'],
)
@my_vcr.use_cassette('youtube_playlist_resolve.yaml')
def test_playlist_resolver(pafy_mock_with_video):
videos = backend.resolve_playlist('PLOxORm4jpOQfMU7bpfGCzDyLropIYEHuR')
assert len(videos) == 104
assert len(videos) == 108
@vcr.use_cassette('tests/fixtures/youtube_search.yaml')
@my_vcr.use_cassette('youtube_search.yaml')
def test_search_yt(pafy_mock_with_video):
videos = backend.search_youtube('chvrches')
assert len(videos) == 15
@vcr.use_cassette('tests/fixtures/resolve_track.yaml')
@my_vcr.use_cassette('resolve_track.yaml')
def test_resolve_track(pafy_mock_with_video):
video = backend.resolve_track('C0DPdy98e4c')
assert video
@vcr.use_cassette('tests/fixtures/resolve_track_failed.yaml')
@my_vcr.use_cassette('resolve_track_failed.yaml')
def test_resolve_track_failed(pafy_mock):
pafy_mock.new.side_effect = Exception('Removed')
......@@ -62,14 +74,14 @@ def test_resolve_track_failed(pafy_mock):
assert not video
@vcr.use_cassette('tests/fixtures/resolve_track_stream.yaml')
@my_vcr.use_cassette('resolve_track_stream.yaml')
def test_resolve_track_stream(pafy_mock_with_video):
video = backend.resolve_track('C0DPdy98e4c', stream=True)
assert video
@vcr.use_cassette('tests/fixtures/resolve_video_track_stream.yaml')
@my_vcr.use_cassette('resolve_video_track_stream.yaml')
def test_resolve_video_track_stream(pafy_mock_with_video):
video = backend.resolve_track('youtube:video/a title.a video id',
stream=True)
......@@ -78,7 +90,7 @@ def test_resolve_video_track_stream(pafy_mock_with_video):
assert video.uri == "http://example.com/"
@vcr.use_cassette('tests/fixtures/lookup_video_uri.yaml')
@my_vcr.use_cassette('lookup_video_uri.yaml')
def test_lookup_video_uri(caplog):
provider = YouTubeLibraryProvider(mock.PropertyMock())
......
......@@ -10,7 +10,6 @@ deps =
pytest-cov
pytest-capturelog
pytest-xdist
tornado >= 4
vcrpy
commands =
py.test \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment