2015-04-03 10:13:27 -07:00
|
|
|
from pywb.webapp.live_rewrite_handler import RewriteHandler
|
|
|
|
from pywb.apps.cli import LiveCli
|
2014-04-09 15:46:03 -07:00
|
|
|
from pywb.framework.wsgi_wrappers import init_app
|
|
|
|
import webtest
|
|
|
|
|
|
|
|
class TestLiveRewriter:
|
|
|
|
def setup(self):
|
2015-04-03 10:13:27 -07:00
|
|
|
self.app = LiveCli(['-f']).application
|
2014-04-09 15:46:03 -07:00
|
|
|
self.testapp = webtest.TestApp(self.app)
|
|
|
|
|
2015-04-13 13:00:06 -07:00
|
|
|
def test_live_live_1(self):
|
|
|
|
headers = [('User-Agent', 'python'), ('Referer', 'http://localhost:80/live/other.example.com')]
|
|
|
|
resp = self.testapp.get('/live/mp_/http://example.com/', headers=headers)
|
2014-04-09 15:46:03 -07:00
|
|
|
assert resp.status_int == 200
|
|
|
|
|
2015-04-13 13:00:06 -07:00
|
|
|
def test_live_live_redirect_2(self):
|
|
|
|
resp = self.testapp.get('/live/mp_/http://httpbin.org/redirect-to?url=http://example.com/')
|
2014-10-29 09:47:32 -07:00
|
|
|
assert resp.status_int == 302
|
2014-04-09 15:46:03 -07:00
|
|
|
|
2015-04-13 13:00:06 -07:00
|
|
|
def test_live_live_post(self):
|
|
|
|
resp = self.testapp.post('/live/mp_/httpbin.org/post', {'foo': 'bar', 'test': 'abc'})
|
2014-08-04 21:59:46 -07:00
|
|
|
assert resp.status_int == 200
|
|
|
|
assert '"foo": "bar"' in resp.body
|
|
|
|
assert '"test": "abc"' in resp.body
|
|
|
|
assert resp.status_int == 200
|
|
|
|
|
2015-04-13 13:00:06 -07:00
|
|
|
def test_live_live_frame(self):
|
|
|
|
resp = self.testapp.get('/live/http://example.com/')
|
2014-04-09 15:46:03 -07:00
|
|
|
assert resp.status_int == 200
|
|
|
|
assert '<iframe ' in resp.body
|
2015-04-13 13:00:06 -07:00
|
|
|
assert 'src="http://localhost:80/live/mp_/http://example.com/"' in resp.body, resp.body
|
2014-04-09 15:46:03 -07:00
|
|
|
|
2014-07-21 22:43:34 -07:00
|
|
|
def test_live_invalid(self):
|
2015-04-13 13:00:06 -07:00
|
|
|
resp = self.testapp.get('/live/mp_/http://abcdef', status=400)
|
2014-07-21 22:43:34 -07:00
|
|
|
assert resp.status_int == 400
|
|
|
|
|
|
|
|
def test_live_invalid_2(self):
|
2015-04-13 13:00:06 -07:00
|
|
|
resp = self.testapp.get('/live/mp_/@#$@#$', status=400)
|
2014-07-21 22:43:34 -07:00
|
|
|
assert resp.status_int == 400
|
|
|
|
|
2014-11-01 13:22:54 -07:00
|
|
|
def test_live_video_info(self):
|
2015-04-13 13:00:06 -07:00
|
|
|
resp = self.testapp.get('/live/vi_/https://www.youtube.com/watch?v=DjFZyFWSt1M')
|
2014-11-01 13:22:54 -07:00
|
|
|
assert resp.status_int == 200
|
2014-12-23 11:07:47 -08:00
|
|
|
assert resp.content_type == RewriteHandler.YT_DL_TYPE, resp.content_type
|
2015-06-24 13:11:33 -07:00
|
|
|
|
|
|
|
def test_deflate(self):
|
|
|
|
resp = self.testapp.get('/live/mp_/http://httpbin.org/deflate')
|
|
|
|
assert '"deflated": true' in resp.body
|