mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
wayback app: add support for root collection, specified as '$root' -- no other collections support if root colletion is set
tests: add test_root_coll.py (move from unused tests) wombat.js: proxy: fix typo in location access
This commit is contained in:
parent
33ba67646b
commit
e9fa167564
@ -42,11 +42,19 @@ class FrontEndApp(object):
|
||||
self.url_map = Map()
|
||||
self.url_map.add(Rule('/static/_/<coll>/<path:filepath>', endpoint=self.serve_static))
|
||||
self.url_map.add(Rule('/static/<path:filepath>', endpoint=self.serve_static))
|
||||
self.url_map.add(Rule('/<coll>/', endpoint=self.serve_coll_page))
|
||||
self.url_map.add(Rule('/<coll>/timemap/<timemap_output>/<path:url>', endpoint=self.serve_content))
|
||||
self.url_map.add(Rule('/<coll>/<path:url>', endpoint=self.serve_content))
|
||||
self.url_map.add(Rule('/collinfo.json', endpoint=self.serve_listing))
|
||||
self.url_map.add(Rule('/', endpoint=self.serve_home))
|
||||
|
||||
if self.is_valid_coll('$root'):
|
||||
self.url_map.add(Rule('/', endpoint=self.serve_coll_page))
|
||||
self.url_map.add(Rule('/timemap/<timemap_output>/<path:url>', endpoint=self.serve_content))
|
||||
self.url_map.add(Rule('/<path:url>', endpoint=self.serve_content))
|
||||
|
||||
else:
|
||||
self.url_map.add(Rule('/<coll>/', endpoint=self.serve_coll_page))
|
||||
self.url_map.add(Rule('/<coll>/timemap/<timemap_output>/<path:url>', endpoint=self.serve_content))
|
||||
self.url_map.add(Rule('/<coll>/<path:url>', endpoint=self.serve_content))
|
||||
|
||||
self.url_map.add(Rule('/', endpoint=self.serve_home))
|
||||
|
||||
self.rewriterapp.paths = self.get_upstream_paths(self.warcserver_server.port)
|
||||
|
||||
@ -101,7 +109,7 @@ class FrontEndApp(object):
|
||||
|
||||
return metadata
|
||||
|
||||
def serve_coll_page(self, environ, coll):
|
||||
def serve_coll_page(self, environ, coll='$root'):
|
||||
if not self.is_valid_coll(coll):
|
||||
self.raise_not_found(environ, 'No handler for "/{0}"'.format(coll))
|
||||
|
||||
@ -111,13 +119,17 @@ class FrontEndApp(object):
|
||||
|
||||
view = BaseInsertView(self.rewriterapp.jinja_env, 'search.html')
|
||||
|
||||
wb_prefix = environ.get('SCRIPT_NAME')
|
||||
if wb_prefix:
|
||||
wb_prefix += '/'
|
||||
|
||||
content = view.render_to_string(environ,
|
||||
wb_prefix=environ.get('SCRIPT_NAME') + '/',
|
||||
wb_prefix=wb_prefix,
|
||||
metadata=metadata)
|
||||
|
||||
return WbResponse.text_response(content, content_type='text/html; charset="utf-8"')
|
||||
|
||||
def serve_content(self, environ, coll='', url='', timemap_output=''):
|
||||
def serve_content(self, environ, coll='$root', url='', timemap_output=''):
|
||||
if not self.is_valid_coll(coll):
|
||||
self.raise_not_found(environ, 'No handler for "/{0}"'.format(coll))
|
||||
|
||||
@ -141,14 +153,21 @@ class FrontEndApp(object):
|
||||
return response
|
||||
|
||||
def setup_paths(self, environ, coll):
|
||||
pop_path_info(environ)
|
||||
if not coll or not self.warcserver.root_dir:
|
||||
return
|
||||
|
||||
if coll != '$root':
|
||||
pop_path_info(environ)
|
||||
|
||||
paths = [self.warcserver.root_dir]
|
||||
|
||||
if coll != '$root':
|
||||
paths.append(coll)
|
||||
|
||||
paths.append(self.templates_dir)
|
||||
|
||||
# jinja2 template paths always use '/' as separator
|
||||
environ['pywb.templates_dir'] = '/'.join([self.warcserver.root_dir,
|
||||
coll,
|
||||
self.templates_dir])
|
||||
environ['pywb.templates_dir'] = '/'.join(paths)
|
||||
|
||||
def serve_listing(self, environ):
|
||||
result = {'fixed': self.warcserver.list_fixed_routes(),
|
||||
|
@ -2580,7 +2580,7 @@ var _WBWombat = function($wbwindow, wbinfo) {
|
||||
if (prop == '__WBProxyRealObj__') {
|
||||
return obj;
|
||||
} else if (prop == 'location') {
|
||||
return obj._WB_wombat_location || (obj.defaultView && obj._WB_wombat_location);
|
||||
return obj._WB_wombat_location || (obj.defaultView && obj.defaultView._WB_wombat_location);
|
||||
} else if (prop == "_WB_wombat_obj_proxy") {
|
||||
return obj._WB_wombat_obj_proxy;
|
||||
}
|
||||
|
8
tests/config_test_root_coll.yaml
Normal file
8
tests/config_test_root_coll.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
debug: true
|
||||
|
||||
collections_root: _test_colls
|
||||
|
||||
collections:
|
||||
'$root': $live
|
||||
|
||||
|
39
tests/test_root_coll.py
Normal file
39
tests/test_root_coll.py
Normal file
@ -0,0 +1,39 @@
|
||||
from .base_config_test import BaseConfigTest, fmod
|
||||
|
||||
|
||||
# ============================================================================
|
||||
class TestRootColl(BaseConfigTest):
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
super(TestRootColl, cls).setup_class('config_test_root_coll.yaml')
|
||||
|
||||
def test_root_replay_ts(self, fmod):
|
||||
resp = self.get('/20140127171238{0}/http://www.iana.org/', fmod)
|
||||
|
||||
# Body
|
||||
assert '"20140127171238"' in resp.text
|
||||
assert 'wb.js' in resp.text
|
||||
assert 'new _WBWombat' in resp.text, resp.text
|
||||
assert '/20140127171238{0}/http://www.iana.org/time-zones"'.format(fmod) in resp.text
|
||||
|
||||
def test_root_replay_no_ts(self, fmod):
|
||||
fmod_slash = fmod + '/' if fmod else ''
|
||||
resp = self.get('/{0}http://www.iana.org/', fmod_slash)
|
||||
|
||||
# Body
|
||||
assert 'request_ts = ""' in resp.text
|
||||
assert 'wb.js' in resp.text
|
||||
assert 'new _WBWombat' in resp.text, resp.text
|
||||
assert '/{0}http://www.iana.org/time-zones"'.format(fmod_slash) in resp.text
|
||||
|
||||
def test_root_replay_redir(self, fmod):
|
||||
resp = self.get('/20140128051539{0}/http://www.iana.org/domains/example', fmod)
|
||||
|
||||
assert resp.status_int == 302
|
||||
|
||||
assert resp.headers['Location'] == 'http://localhost:80/20140128051539{0}/https://www.iana.org/domains/reserved'.format(fmod)
|
||||
|
||||
def test_root_home_search(self):
|
||||
resp = self.testapp.get('/')
|
||||
assert 'Search' in resp.text
|
||||
|
@ -1,41 +0,0 @@
|
||||
from pywb.webapp.pywb_init import create_wb_router
|
||||
from pywb.framework.wsgi_wrappers import init_app
|
||||
from pywb.framework.basehandlers import BaseHandler
|
||||
from pywb.framework.wbrequestresponse import WbResponse
|
||||
|
||||
from .server_mock import make_setup_module, BaseIntegration
|
||||
|
||||
setup_module = make_setup_module('tests/test_config_root_coll.yaml')
|
||||
|
||||
|
||||
# A custom handler
|
||||
class RedirHandler(BaseHandler):
|
||||
def __call__(self, wbrequest):
|
||||
return WbResponse.redir_response(self.redir_path + wbrequest.wb_url_str)
|
||||
|
||||
|
||||
class TestMementoFrameInverse(BaseIntegration):
|
||||
def test_timestamp_replay_redir(self):
|
||||
resp = self.testapp.get('/http://www.iana.org/')
|
||||
assert resp.status_int == 302
|
||||
assert resp.headers['Location'].endswith('/20140127171238/http://www.iana.org/')
|
||||
|
||||
|
||||
def test_replay(self):
|
||||
resp = self.testapp.get('/20140127171238/http://www.iana.org/')
|
||||
|
||||
# Body
|
||||
assert '"20140127171238"' in resp.text
|
||||
assert 'wb.js' in resp.text
|
||||
assert 'new _WBWombat' in resp.text, resp.text
|
||||
assert '/20140127171238/http://www.iana.org/time-zones"' in resp.text
|
||||
|
||||
def test_redir_handler_redir(self):
|
||||
resp = self.testapp.get('/foo/20140127171238mp_/http://www.iana.org/')
|
||||
assert resp.status_int == 302
|
||||
assert resp.headers['Location'].endswith('/20140127171238mp_/http://www.iana.org/')
|
||||
|
||||
def test_home_search(self):
|
||||
resp = self.testapp.get('/')
|
||||
assert 'Search' in resp.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user