1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 00:21:15 +03:00

Fix Navigator tests on Py2.6

This commit is contained in:
Simon Sapin 2012-06-25 16:09:40 +02:00
parent c2375d2f5c
commit 6eee86dadf
3 changed files with 10 additions and 7 deletions

View File

@ -19,7 +19,8 @@ import email
if sys.version_info[0] >= 3:
# Python 3
from urllib.parse import (
urljoin, urlsplit, quote, unquote, unquote_to_bytes, parse_qs)
urljoin, urlsplit, quote, unquote, unquote_to_bytes, parse_qs,
urlencode)
from urllib.request import urlopen, Request, pathname2url
from array import array
@ -48,7 +49,7 @@ else:
# Python 2
from urlparse import urljoin, urlsplit, parse_qs
from urllib2 import urlopen, Request
from urllib import pathname2url, quote, unquote
from urllib import pathname2url, quote, unquote, urlencode
from array import array as _array
from itertools import izip

View File

@ -150,12 +150,13 @@ def app(environ, start_response):
return make_response(render_template(url))
elif path == '/':
args = parse_qs(environ.get('QUERY_STRING', ''))
args = parse_qs(environ.get('QUERY_STRING') or '')
url = normalize_url(args.get('url', [''])[0])
return make_response(render_template(url))
return make_response(b'<h1>Not Found</h1>', status='404 Not Found')
def run(port=5000):
host = '127.0.0.1'
try:

View File

@ -26,7 +26,7 @@ import pytest
from .testing_utils import (
resource_filename, assert_no_logs, TEST_UA_STYLESHEET)
from ..compat import urljoin, quote
from ..compat import urljoin, urlencode
from .. import HTML, CSS
from .. import __main__
from .. import navigator
@ -373,11 +373,12 @@ def test_unicode_filenames():
assert read_file(unicode_filename) == png_bytes
def wsgi_client(path_info, query_string=None):
def wsgi_client(path_info, qs_args=None):
start_response_calls = []
def start_response(status, headers):
start_response_calls.append((status, headers))
environ = {'PATH_INFO': path_info, 'QUERY_STRING': query_string}
environ = {'PATH_INFO': path_info,
'QUERY_STRING': urlencode(qs_args or {})}
response = b''.join(navigator.app(environ, start_response))
assert len(start_response_calls) == 1
status, headers = start_response_calls[0]
@ -411,7 +412,7 @@ def test_navigator():
for status, headers, body in [
wsgi_client('/view/file://' + filename),
wsgi_client('/', 'url=' + quote('file://' + filename, safe='')),
wsgi_client('/', {'url': 'file://' + filename}),
]:
body = body.decode('utf8')
assert status == '200 OK'