mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
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
This commit is contained in:
parent
ca33287051
commit
2600d870d7
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -155,6 +155,19 @@ rel="memento"; datetime="Fri, 03 Jan 2014 03:03:21 GMT",'
|
||||
assert lines[4] == '<http://localhost:80/pywb/20140103030341/http://example.com?example=1>; \
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user