Try to fix test_web.py on Python 2.

This commit is contained in:
Itamar Turner-Trauring 2020-12-14 13:53:12 -05:00
parent 37d46cfb3d
commit c7759cb82c
2 changed files with 8 additions and 3 deletions

View File

@ -48,10 +48,10 @@ class VerboseError(Error):
@inlineCallbacks
def do_http(method, url, **kwargs):
"""
Run HTTP query, return Deferred of body as Unicode.
Run HTTP query, return Deferred of body as bytes.
"""
response = yield treq.request(method, url, persistent=False, **kwargs)
body = yield treq.text_content(response, "utf-8")
body = yield treq.content(response)
# TODO: replace this with response.fail_for_status when
# https://github.com/twisted/treq/pull/159 has landed
if 400 <= response.code < 600:

View File

@ -55,7 +55,7 @@ from .common import (
TEST_RSA_KEY_SIZE,
SameProcessStreamEndpointAssigner,
)
from .common_web import do_http, Error
from .common_web import do_http as do_http_bytes, Error
from .web.common import (
assert_soup_has_tag_with_attributes
)
@ -78,6 +78,11 @@ def run_cli(*args, **kwargs):
ensure_text(args[0]), [ensure_text(a) for a in args[1:]], **kwargs)
def do_http(*args, **kwargs):
"""Wrapper for do_http() that returns Unicode."""
return do_http_bytes(*args, **kwargs).addCallback(
lambda b: str(b, "utf-8"))
LARGE_DATA = b"""
This is some data to publish to the remote grid.., which needs to be large