From 7bf8b97cb007a6e663a666d33423886877dba83b Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Fri, 17 Apr 2015 11:48:50 -0700 Subject: [PATCH] tests: add tests for root collection access, and also a custom handler passed to pywb_init (a simple redirect handler) --- tests/test_config_root_coll.yaml | 10 +++++++ tests/test_root_coll.py | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/test_config_root_coll.yaml create mode 100644 tests/test_root_coll.py diff --git a/tests/test_config_root_coll.yaml b/tests/test_config_root_coll.yaml new file mode 100644 index 00000000..a64a476f --- /dev/null +++ b/tests/test_config_root_coll.yaml @@ -0,0 +1,10 @@ +collections: + # root handler! + '': + index_paths: ./sample_archive/cdx/ + + foo: !!python/object:tests.test_root_coll.RedirHandler { redir_path: '/' } + +archive_paths: ./sample_archive/warcs/ + +framed_replay: false diff --git a/tests/test_root_coll.py b/tests/test_root_coll.py new file mode 100644 index 00000000..90a3eeb4 --- /dev/null +++ b/tests/test_root_coll.py @@ -0,0 +1,47 @@ +import webtest +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 + + +# A custom handler +class RedirHandler(BaseHandler): + def __call__(self, wbrequest): + return WbResponse.redir_response(self.redir_path + wbrequest.wb_url_str) + + +class TestMementoFrameInverse(object): + TEST_CONFIG = 'tests/test_config_root_coll.yaml' + + def setup(self): + self.app = init_app(create_wb_router, + load_yaml=True, + config_file=self.TEST_CONFIG) + + self.testapp = webtest.TestApp(self.app) + + 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.body + assert 'wb.js' in resp.body + assert 'new _WBWombat' in resp.body, resp.body + assert '/20140127171238/http://www.iana.org/time-zones"' in resp.body + + 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.body +