More passing tests on Python 3.

This commit is contained in:
Itamar Turner-Trauring 2021-01-22 15:07:03 -05:00
parent 4e15b37062
commit 4c5ea34af6
8 changed files with 22 additions and 20 deletions

View File

@ -46,7 +46,7 @@ class ProvisioningTool(rend.Page):
req = inevow.IRequest(ctx)
def getarg(name, astype=int):
if req.method != "POST":
if req.method != b"POST":
return None
if name in req.fields:
return astype(req.fields[name].value)

View File

@ -859,6 +859,8 @@ class WebErrorMixin(object):
body = yield response.content()
self.assertEquals(response.code, code)
if response_substring is not None:
if isinstance(response_substring, unicode):
response_substring = response_substring.encode("utf-8")
self.assertIn(response_substring, body)
returnValue(body)

View File

@ -636,7 +636,7 @@ class WebMixin(TimezoneMixin):
getattr(res.value, "response", ""),
which))
if response_substring:
self.failUnlessIn(response_substring, res.value.response,
self.failUnlessIn(response_substring, unicode(res.value.response, "utf-8"),
"'%s' not in '%s' for test '%s'" % \
(response_substring, res.value.response,
which))
@ -2054,8 +2054,8 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
def test_GET_DIRURL_readonly(self):
# look at a readonly directory
data = yield self.GET(self.public_url + "/reedownlee", followRedirect=True)
self.failUnlessIn("(read-only)", data)
self.failIfIn("Upload a file", data)
self.failUnlessIn(b"(read-only)", data)
self.failIfIn(b"Upload a file", data)
@inlineCallbacks
def test_GET_DIRURL_readonly_dir(self):
@ -2090,7 +2090,7 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
tiny_litdir_uri = "URI:DIR2-LIT:gqytunj2onug64tufqzdcosvkjetutcjkq5gw4tvm5vwszdgnz5hgyzufqydulbshj5x2lbm" # contains one child which is itself also LIT
data = yield self.GET("/uri/" + tiny_litdir_uri, followRedirect=True)
soup = BeautifulSoup(data, 'html5lib')
self.failUnlessIn('(immutable)', data)
self.failUnlessIn(b'(immutable)', data)
file_links = list(
td.findNextSibling()(u"a")[0]
for td in soup.find_all(u"td")

View File

@ -283,8 +283,8 @@ def render_time_attr(t):
# actual exception). The latter is growing increasingly annoying.
def should_create_intermediate_directories(req):
t = get_arg(req, "t", "").strip()
return bool(req.method in ("PUT", "POST") and
t = unicode(get_arg(req, "t", "").strip(), "ascii")
return bool(req.method in (b"PUT", b"POST") and
t not in ("delete", "rename", "rename-form", "check"))
def humanize_exception(exc):

View File

@ -135,7 +135,7 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
terminal = (req.prepath + req.postpath)[-1].decode('utf8') == name
nonterminal = not terminal #len(req.postpath) > 0
t = get_arg(req, b"t", b"").strip()
t = unicode(get_arg(req, b"t", b"").strip(), "ascii")
if isinstance(node_or_failure, Failure):
f = node_or_failure
f.trap(NoSuchChildError)
@ -150,10 +150,10 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
else:
# terminal node
terminal_requests = (
("POST", "mkdir"),
("PUT", "mkdir"),
("POST", "mkdir-with-children"),
("POST", "mkdir-immutable")
(b"POST", "mkdir"),
(b"PUT", "mkdir"),
(b"POST", "mkdir-with-children"),
(b"POST", "mkdir-immutable")
)
if (req.method, t) in terminal_requests:
# final directory
@ -182,8 +182,8 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
)
return d
leaf_requests = (
("PUT",""),
("PUT","uri"),
(b"PUT",""),
(b"PUT","uri"),
)
if (req.method, t) in leaf_requests:
# we were trying to find the leaf filenode (to put a new
@ -255,7 +255,7 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
@render_exception
def render_PUT(self, req):
t = get_arg(req, b"t", b"").strip()
t = unicode(get_arg(req, b"t", b"").strip(), "ascii")
replace = parse_replace_arg(get_arg(req, "replace", "true"))
if t == "mkdir":

View File

@ -475,8 +475,8 @@ class FileDownloader(Resource, object):
size = contentsize
req.setHeader("content-length", b"%d" % contentsize)
if req.method == "HEAD":
return ""
if req.method == b"HEAD":
return b""
d = self.filenode.read(req, first, size)

View File

@ -106,7 +106,7 @@ class OphandleTable(resource.Resource, service.Service):
(monitor, renderer, when_added) = self.handles[ophandle]
t = get_arg(req, "t", "status")
if t == "cancel" and req.method == "POST":
if t == "cancel" and req.method == b"POST":
monitor.cancel()
# return the status anyways, but release the handle
self._release_ophandle(ophandle)

View File

@ -177,7 +177,7 @@ class FileHandler(resource.Resource, object):
@exception_to_child
def getChild(self, name, req):
if req.method not in ("GET", "HEAD"):
if req.method not in (b"GET", b"HEAD"):
raise WebError("/file can only be used with GET or HEAD")
# 'name' must be a file URI
try:
@ -200,7 +200,7 @@ class IncidentReporter(MultiFormatResource):
@render_exception
def render(self, req):
if req.method != "POST":
if req.method != b"POST":
raise WebError("/report_incident can only be used with POST")
log.msg(format="User reports incident through web page: %(details)s",