1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

tests: convert test_inputreq to use werkzeug (same as the app), remove bottle from test dependencies

This commit is contained in:
Ilya Kreymer 2017-03-08 23:09:19 -08:00
parent e86e3e6d32
commit d4321792b7
2 changed files with 26 additions and 16 deletions

View File

@ -1,34 +1,45 @@
from pywb.webagg.inputrequest import DirectWSGIInputRequest, POSTInputRequest
from bottle import Bottle, request, response, debug
from werkzeug.routing import Map, Rule
import webtest
import traceback
from six.moves.urllib.parse import parse_qsl
#=============================================================================
class InputReqApp(object):
def __init__(self):
self.application = Bottle()
debug(True)
self.url_map = Map()
self.url_map.add(Rule('/test/<path:url>', endpoint=self.direct_input_request))
self.url_map.add(Rule('/test-postreq', endpoint=self.post_fullrequest))
@self.application.route('/test/<url:re:.*>', 'ANY')
def direct_input_request(url=''):
inputreq = DirectWSGIInputRequest(request.environ)
response['Content-Type'] = 'text/plain; charset=utf-8'
return inputreq.reconstruct_request(url)
def direct_input_request(self, environ, url=''):
inputreq = DirectWSGIInputRequest(environ)
return inputreq.reconstruct_request(url)
def post_fullrequest(self, environ):
params = dict(parse_qsl(environ.get('QUERY_STRING', '')))
inputreq = POSTInputRequest(environ)
return inputreq.reconstruct_request(params['url'])
def __call__(self, environ, start_response):
urls = self.url_map.bind_to_environ(environ)
try:
endpoint, args = urls.match()
except HTTPException as e:
return e(environ, start_response)
result = endpoint(environ, **args)
start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')])
return [result]
@self.application.route('/test-postreq', 'POST')
def post_fullrequest():
params = dict(request.query)
inputreq = POSTInputRequest(request.environ)
response['Content-Type'] = 'text/plain; charset=utf-8'
return inputreq.reconstruct_request(params.get('url'))
#=============================================================================
class TestInputReq(object):
def setup(self):
self.app = InputReqApp()
self.testapp = webtest.TestApp(self.app.application)
self.testapp = webtest.TestApp(self.app)
def test_get_direct(self):
res = self.testapp.get('/test/http://example.com/', headers={'Foo': 'Bar'})

View File

@ -86,7 +86,6 @@ setup(
'fakeredis',
'mock',
'urllib3',
'bottle',
'werkzeug',
],
cmdclass={'test': PyTest},