From 2600d870d7e0687338d82269713615b15c3b7298 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Fri, 16 May 2014 22:17:51 -0700 Subject: [PATCH] improved test: dsrules remove redundant check static: check invalid static paths and file_wrapper memento: check non-memento paths test debug handlers and custom '-cdx' suffix --- pywb/utils/dsrules.py | 8 ++------ pywb/webapp/handlers.py | 2 +- tests/test_config.yaml | 10 +++++++++- tests/test_integration.py | 11 ++++++++++- tests/test_memento.py | 29 +++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/pywb/utils/dsrules.py b/pywb/utils/dsrules.py index 672ce738..7c0a8cf9 100644 --- a/pywb/utils/dsrules.py +++ b/pywb/utils/dsrules.py @@ -31,12 +31,8 @@ class RuleSet(object): config = load_yaml_config(ds_rules_file) - rulesmap = config.get('rules') if config else None - - # if default_rule_config provided, always init a default ruleset - if not rulesmap and default_rule_config is not None: - self.rules = [rule_cls(self.DEFAULT_KEY, default_rule_config)] - return + # load rules dict or init to empty + rulesmap = config.get('rules') if config else {} def_key_found = False diff --git a/pywb/webapp/handlers.py b/pywb/webapp/handlers.py index ce11b6b1..a19c9405 100644 --- a/pywb/webapp/handlers.py +++ b/pywb/webapp/handlers.py @@ -80,7 +80,7 @@ class StaticHandler(BaseHandler): raise NotFoundException('Static File Not Found: ' + wbrequest.wb_url_str) - def __str__(self): + def __str__(self): # pragma: no cover return 'Static files from ' + self.static_path diff --git a/tests/test_config.yaml b/tests/test_config.yaml index 6ed28757..b3ed0c03 100644 --- a/tests/test_config.yaml +++ b/tests/test_config.yaml @@ -87,7 +87,9 @@ static_routes: enable_http_proxy: true # enable cdx server api for querying cdx directly (experimental) -enable_cdx_api: true +#enable_cdx_api: True +# or specify suffix +enable_cdx_api: -cdx # test different port port: 9000 @@ -107,3 +109,9 @@ perms_policy: !!python/name:tests.perms_fixture.perms_policy # not testing memento here enable_memento: False + + +# Debug Handlers +debug_echo_env: True + +debug_echo_req: True diff --git a/tests/test_integration.py b/tests/test_integration.py index 1d469574..54620084 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -214,13 +214,22 @@ class TestWb: assert resp.status_int == 403 assert 'Excluded' in resp.body - def test_static_content(self): resp = self.testapp.get('/static/test/route/wb.css') assert resp.status_int == 200 assert resp.content_type == 'text/css' assert resp.content_length > 0 + def test_static_content_filewrapper(self): + from wsgiref.util import FileWrapper + resp = self.testapp.get('/static/test/route/wb.css', extra_environ = {'wsgi.file_wrapper': FileWrapper}) + assert resp.status_int == 200 + assert resp.content_type == 'text/css' + assert resp.content_length > 0 + + def test_static_not_found(self): + resp = self.testapp.get('/static/test/route/notfound.css', status = 404) + assert resp.status_int == 404 # 'Simulating' proxy by settings REQUEST_URI explicitly to http:// url and no SCRIPT_NAME # would be nice to be able to test proxy more diff --git a/tests/test_memento.py b/tests/test_memento.py index 1e60606b..42840e7e 100644 --- a/tests/test_memento.py +++ b/tests/test_memento.py @@ -155,6 +155,19 @@ rel="memento"; datetime="Fri, 03 Jan 2014 03:03:21 GMT",' assert lines[4] == '; \ rel="memento"; datetime="Fri, 03 Jan 2014 03:03:41 GMT"' + def test_timemap_2(self): + """ + Test application/link-format timemap total count + """ + + resp = self.testapp.get('/pywb/timemap/*/http://example.com') + assert resp.status_int == 200 + assert resp.content_type == LINK_FORMAT + + lines = resp.body.split('\n') + + assert len(lines) == 3 + 3 + # Below functions test pywb proxy mode behavior # They are designed to roughly conform to Memento protocol Pattern 1.3 # with the exception that the original resource is not available @@ -229,3 +242,19 @@ rel="memento"; datetime="Fri, 03 Jan 2014 03:03:41 GMT"' resp = self.testapp.get('/x-ignore-this-x', extra_environ=extra, headers=headers, status=400) assert resp.status_int == 400 + + def test_non_memento_path(self): + """ + Non WbUrl memento path -- just ignore ACCEPT_DATETIME + """ + headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04'} + resp = self.testapp.get('/pywb/', headers=headers) + assert resp.status_int == 200 + + def test_non_memento_cdx_path(self): + """ + CDX API Path -- different api, ignore ACCEPT_DATETIME for this + """ + headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04'} + resp = self.testapp.get('/pywb-cdx', headers=headers, status=400) + assert resp.status_int == 400