mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
youtube-dl tests: use mock youtube-dl info for tests
This commit is contained in:
parent
4e37bf0a4a
commit
080587516b
@ -229,7 +229,7 @@ class RewriteHandler(SearchPageWbUrlHandler):
|
|||||||
msg = ('youtube-dl is not installed, pip install youtube-dl to ' +
|
msg = ('youtube-dl is not installed, pip install youtube-dl to ' +
|
||||||
'enable improved video proxy')
|
'enable improved video proxy')
|
||||||
|
|
||||||
return WbResponse.text_response(msg=msg, status='404 Not Found')
|
return WbResponse.text_response(text=msg, status='404 Not Found')
|
||||||
|
|
||||||
#if info and info.formats and len(info.formats) == 1:
|
#if info and info.formats and len(info.formats) == 1:
|
||||||
|
|
||||||
@ -256,14 +256,14 @@ class RewriteHandler(SearchPageWbUrlHandler):
|
|||||||
|
|
||||||
#=================================================================
|
#=================================================================
|
||||||
class YoutubeDLWrapper(object):
|
class YoutubeDLWrapper(object):
|
||||||
""" YoutubeDL wrapper, inits youtubee-dil if it is available
|
""" YoutubeDL wrapper, inits youtubee-dl if it is available
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
try:
|
try:
|
||||||
from youtube_dl import YoutubeDL as YoutubeDL
|
from youtube_dl import YoutubeDL as YoutubeDL
|
||||||
except ImportError: #pragma: no cover
|
except ImportError: #pragma: no cover
|
||||||
self.ydl = None
|
self.ydl = None
|
||||||
pass
|
return
|
||||||
|
|
||||||
self.ydl = YoutubeDL(dict(simulate=True,
|
self.ydl = YoutubeDL(dict(simulate=True,
|
||||||
youtube_include_dash_manifest=False))
|
youtube_include_dash_manifest=False))
|
||||||
|
@ -9,7 +9,6 @@ from pywb.webapp.pywb_init import create_wb_router
|
|||||||
from pywb.framework.wsgi_wrappers import init_app
|
from pywb.framework.wsgi_wrappers import init_app
|
||||||
import webtest
|
import webtest
|
||||||
import shutil
|
import shutil
|
||||||
import pytest
|
|
||||||
|
|
||||||
import pywb.webapp.live_rewrite_handler
|
import pywb.webapp.live_rewrite_handler
|
||||||
|
|
||||||
@ -48,6 +47,14 @@ class ProxyRequest(BaseHTTPRequestHandler):
|
|||||||
self.do_GET()
|
self.do_GET()
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================================
|
||||||
|
class MockYTDWrapper(object):
|
||||||
|
def extract_info(self, url):
|
||||||
|
return {'mock': 'youtube_dl_data'}
|
||||||
|
|
||||||
|
|
||||||
|
pywb.webapp.live_rewrite_handler.YoutubeDLWrapper = MockYTDWrapper
|
||||||
|
|
||||||
#=================================================================
|
#=================================================================
|
||||||
class TestProxyLiveRewriter:
|
class TestProxyLiveRewriter:
|
||||||
def setup(self):
|
def setup(self):
|
||||||
@ -163,8 +170,6 @@ class TestProxyLiveRewriter:
|
|||||||
assert len(self.cache) == 1
|
assert len(self.cache) == 1
|
||||||
|
|
||||||
def test_echo_proxy_video_info(self):
|
def test_echo_proxy_video_info(self):
|
||||||
yt = pytest.importorskip('youtube_dl')
|
|
||||||
|
|
||||||
resp = self.testapp.get('/rewrite/vi_/https://www.youtube.com/watch?v=DjFZyFWSt1M')
|
resp = self.testapp.get('/rewrite/vi_/https://www.youtube.com/watch?v=DjFZyFWSt1M')
|
||||||
assert resp.status_int == 200
|
assert resp.status_int == 200
|
||||||
assert resp.content_type == RewriteHandler.YT_DL_TYPE, resp.content_type
|
assert resp.content_type == RewriteHandler.YT_DL_TYPE, resp.content_type
|
||||||
@ -181,8 +186,6 @@ class TestProxyLiveRewriter:
|
|||||||
assert RewriteHandler.create_cache_key('v:', 'https://www.youtube.com/watch?v=DjFZyFWSt1M') in self.cache
|
assert RewriteHandler.create_cache_key('v:', 'https://www.youtube.com/watch?v=DjFZyFWSt1M') in self.cache
|
||||||
|
|
||||||
def test_echo_proxy_video_with_referrer(self):
|
def test_echo_proxy_video_with_referrer(self):
|
||||||
yt = pytest.importorskip('youtube_dl')
|
|
||||||
|
|
||||||
headers = [('Range', 'bytes=1000-2000'), ('Referer', 'http://localhost:80/rewrite/https://example.com/')]
|
headers = [('Range', 'bytes=1000-2000'), ('Referer', 'http://localhost:80/rewrite/https://example.com/')]
|
||||||
resp = self.testapp.get('/rewrite/http://www.youtube.com/watch?v=DjFZyFWSt1M', headers=headers)
|
resp = self.testapp.get('/rewrite/http://www.youtube.com/watch?v=DjFZyFWSt1M', headers=headers)
|
||||||
|
|
||||||
|
@ -2,9 +2,19 @@ from pywb.webapp.live_rewrite_handler import RewriteHandler
|
|||||||
from pywb.apps.cli import LiveCli
|
from pywb.apps.cli import LiveCli
|
||||||
from pywb.framework.wsgi_wrappers import init_app
|
from pywb.framework.wsgi_wrappers import init_app
|
||||||
import webtest
|
import webtest
|
||||||
import pytest
|
import pywb.webapp.live_rewrite_handler
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================================
|
||||||
|
class MockYTDWrapper(object):
|
||||||
|
def extract_info(self, url):
|
||||||
|
return {'mock': 'youtube_dl_data'}
|
||||||
|
|
||||||
|
|
||||||
|
pywb.webapp.live_rewrite_handler.YoutubeDLWrapper = MockYTDWrapper
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================================
|
||||||
class TestLiveRewriter:
|
class TestLiveRewriter:
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.app = LiveCli(['-f']).application
|
self.app = LiveCli(['-f']).application
|
||||||
@ -41,7 +51,6 @@ class TestLiveRewriter:
|
|||||||
assert resp.status_int == 400
|
assert resp.status_int == 400
|
||||||
|
|
||||||
def test_live_video_info(self):
|
def test_live_video_info(self):
|
||||||
yt = pytest.importorskip('youtube_dl')
|
|
||||||
resp = self.testapp.get('/live/vi_/https://www.youtube.com/watch?v=DjFZyFWSt1M')
|
resp = self.testapp.get('/live/vi_/https://www.youtube.com/watch?v=DjFZyFWSt1M')
|
||||||
assert resp.status_int == 200
|
assert resp.status_int == 200
|
||||||
assert resp.content_type == RewriteHandler.YT_DL_TYPE, resp.content_type
|
assert resp.content_type == RewriteHandler.YT_DL_TYPE, resp.content_type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user