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): ...@@ -95,7 +95,7 @@ def search_youtube(q):
'q': q, 'q': q,
'key': yt_key 'key': yt_key
} }
result = session.get(yt_api_endpoint+'search', params=query) result = session.get(yt_api_endpoint + 'search', params=query)
data = result.json() data = result.json()
resolve_pool = ThreadPool(processes=16) resolve_pool = ThreadPool(processes=16)
...@@ -123,7 +123,7 @@ def resolve_playlist(url): ...@@ -123,7 +123,7 @@ def resolve_playlist(url):
logger.debug("Get YouTube-Playlist '%s' page %s", url, page) logger.debug("Get YouTube-Playlist '%s' page %s", url, page)
params['pageToken'] = 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() data = result.json()
page = data.get('nextPageToken') 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: ...@@ -5,67 +5,53 @@ interactions:
Accept: ['*/*'] Accept: ['*/*']
Accept-Encoding: ['gzip, deflate'] Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive] 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 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: response:
body: {string: !!python/unicode "{\n \"kind\": \"youtube#searchListResponse\"\ body: {string: !!python/unicode "{\n \"kind\": \"youtube#searchListResponse\",\n
,\n \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/EB27u2NyX6LmPLJhLS1uP0bFhV4\\\ \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/VsP4qcJf6cr5ebPm-aH1WTFBsP8\\\"\",\n
\"\",\n \"nextPageToken\": \"CA8QAA\",\n \"pageInfo\": {\n \"totalResults\"\ \"nextPageToken\": \"CA8QAA\",\n \"regionCode\": \"DE\",\n \"pageInfo\": {\n
: 243298,\n \"resultsPerPage\": 15\n },\n \"items\": [\n {\n \"kind\"\ \ \"totalResults\": 367059,\n \"resultsPerPage\": 15\n },\n \"items\": [\n
: \"youtube#searchResult\",\n \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/1L7o9RIHG0UaLLGT1d32ax2ffT4\\\ \ {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/N62nNRIBR6JMMA3QHwCDamuj_Rc\\\"\",\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"4Eo84jDIMKI\"\n
TU3b1qyEGsE\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/W9dQENrUpeEpmfU_HUrA86qf6qs\\\"\",\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/3IezfTBiiPjbdpd5swNI4Gjx-jk\\\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"B9BLMNn0PrQ\"\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/3IezfTBiiPjbdpd5swNI4Gjx-jk\\\"\",\n
_mTRvJ9fugM\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"_mTRvJ9fugM\"\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/dnD7v3fj9beOaIe7j-LusVeUMUg\\\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/_8h0hU7fZscgrbr6Ni8AcZ8SZek\\\"\",\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"BZyzX4c1vIs\"\n
ipE-tnRh4fE\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/YSHn1TNgPRAlT93S47BuyMUzlV4\\\"\",\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/2W6aSevqn2e3xeRG5YpZgZlBWjw\\\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"ktoaj1IpTbw\"\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/7EQ7MT5JIRPIsfBOzoAGbmyrKZI\\\"\",\n
zM0O1Pqjvuw\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"KNHxwSp-6Og\"\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/LGMW7H1MtkhsDLmWsw7R4IRL36o\\\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/kPwTMwlUdVdaA-3OSQV4o7fjOIQ\\\"\",\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"81RqEnvczV8\"\n
1L9iUhiOXbE\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/6lLxsx4-nzLoy20iBcp6DevuCGQ\\\"\",\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/YSHn1TNgPRAlT93S47BuyMUzlV4\\\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"p_A1PDN2aXw\"\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/qXkLEENk7SdNRzJKrt0ffs44i8Y\\\"\",\n
ktoaj1IpTbw\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"JyqemIbjcfg\"\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/Rg4U8fhd5B0WzXmSa8DDa3Jhrjw\\\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/yw8l2TamUNuR1pdri9uul3Y324c\\\"\",\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"pWAkPRKx1HI\"\n
RWhEUR0I9fo\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/jYmtypJsIvubTpjqp_xEj01401M\\\"\",\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/jYmtypJsIvubTpjqp_xEj01401M\\\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"CjwwmFrsX_E\"\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/nFRQICKOptZ_1Ql3WYQRy-xTMeQ\\\"\",\n
CjwwmFrsX_E\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"3UNP2aJKzyA\"\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/GjyLc47sdTqSDcg0cHnYVburu3A\\\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/Wl1rkawwplyT-s8cZWZIutMx84M\\\"\",\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"AU9_0pxiDjY\"\n
haunJARHPm4\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/GjyLc47sdTqSDcg0cHnYVburu3A\\\"\",\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/qXkLEENk7SdNRzJKrt0ffs44i8Y\\\ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"haunJARHPm4\"\n
\"\",\n \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"\ \ }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \"etag\": \"\\\"gMxXHe-zinKdE9lTnzKu8vjcmDI/1bC-AatWfiadKMhhPyURN4GztXM\\\"\",\n
JyqemIbjcfg\"\n }\n },\n {\n \"kind\": \"youtube#searchResult\",\n \ \ \"id\": {\n \"kind\": \"youtube#video\",\n \"videoId\": \"fB4gjiMVKFI\"\n
\ \"etag\": \"\\\"F9iA7pnxqNgrkOutjQAa9F2k8HY/KWhkxmFs6poSxCh532xrpAM3qPg\\\ \ }\n }\n ]\n}\n"}
\"\",\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"}
headers: 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'] cache-control: ['private, max-age=120, must-revalidate, no-transform']
content-length: ['3105'] content-length: ['3126']
content-type: [application/json; charset=UTF-8] content-type: [application/json; charset=UTF-8]
date: ['Fri, 02 Jan 2015 12:17:02 GMT'] date: ['Fri, 13 Jan 2017 22:12:22 GMT']
etag: ['"F9iA7pnxqNgrkOutjQAa9F2k8HY/EB27u2NyX6LmPLJhLS1uP0bFhV4"'] etag: ['"gMxXHe-zinKdE9lTnzKu8vjcmDI/VsP4qcJf6cr5ebPm-aH1WTFBsP8"']
expires: ['Fri, 02 Jan 2015 12:17:02 GMT'] expires: ['Fri, 13 Jan 2017 22:12:22 GMT']
server: [GSE] server: [GSE]
vary: [Origin, X-Origin] vary: [Origin, X-Origin]
x-content-type-options: [nosniff] x-content-type-options: [nosniff]
......
from __future__ import unicode_literals from __future__ import unicode_literals
import os.path
import mock import mock
import pafy import pafy
...@@ -32,28 +34,38 @@ def pafy_mock_with_video(pafy_mock): ...@@ -32,28 +34,38 @@ def pafy_mock_with_video(pafy_mock):
return 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): def test_playlist_resolver(pafy_mock_with_video):
videos = backend.resolve_playlist('PLOxORm4jpOQfMU7bpfGCzDyLropIYEHuR') 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): def test_search_yt(pafy_mock_with_video):
videos = backend.search_youtube('chvrches') videos = backend.search_youtube('chvrches')
assert len(videos) == 15 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): def test_resolve_track(pafy_mock_with_video):
video = backend.resolve_track('C0DPdy98e4c') video = backend.resolve_track('C0DPdy98e4c')
assert video 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): def test_resolve_track_failed(pafy_mock):
pafy_mock.new.side_effect = Exception('Removed') pafy_mock.new.side_effect = Exception('Removed')
...@@ -62,14 +74,14 @@ def test_resolve_track_failed(pafy_mock): ...@@ -62,14 +74,14 @@ def test_resolve_track_failed(pafy_mock):
assert not video 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): def test_resolve_track_stream(pafy_mock_with_video):
video = backend.resolve_track('C0DPdy98e4c', stream=True) video = backend.resolve_track('C0DPdy98e4c', stream=True)
assert video 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): def test_resolve_video_track_stream(pafy_mock_with_video):
video = backend.resolve_track('youtube:video/a title.a video id', video = backend.resolve_track('youtube:video/a title.a video id',
stream=True) stream=True)
...@@ -78,7 +90,7 @@ def test_resolve_video_track_stream(pafy_mock_with_video): ...@@ -78,7 +90,7 @@ def test_resolve_video_track_stream(pafy_mock_with_video):
assert video.uri == "http://example.com/" 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): def test_lookup_video_uri(caplog):
provider = YouTubeLibraryProvider(mock.PropertyMock()) provider = YouTubeLibraryProvider(mock.PropertyMock())
......
...@@ -10,7 +10,6 @@ deps = ...@@ -10,7 +10,6 @@ deps =
pytest-cov pytest-cov
pytest-capturelog pytest-capturelog
pytest-xdist pytest-xdist
tornado >= 4
vcrpy vcrpy
commands = commands =
py.test \ 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