Bug 1428709 - Enable several mozhttpd tests for Python 3; r=davehunt

MozReview-Commit-ID: K7m58KGR29N

--HG--
extra : rebase_source : cc95b403348679ee4cc263c7ae0e9f6d54026261
This commit is contained in:
Raphael Pierzina 2018-07-12 18:37:54 +02:00
Родитель 6650158314
Коммит d4d5aeaf26
4 изменённых файлов: 17 добавлений и 18 удалений

Просмотреть файл

@ -108,9 +108,9 @@ class RequestHandler(SimpleHTTPRequestHandler):
"""Find the on-disk path to serve this request from,
using self.path_mappings and self.docroot.
Return (url_path, disk_path)."""
path_components = filter(None, self.request.path.split('/'))
path_components = list(filter(None, self.request.path.split('/')))
for prefix, disk_path in iteritems(self.path_mappings):
prefix_components = filter(None, prefix.split('/'))
prefix_components = list(filter(None, prefix.split('/')))
if len(path_components) < len(prefix_components):
continue
if path_components[:len(prefix_components)] == prefix_components:
@ -166,7 +166,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
# fragment and mangled the path for proxying, if required.
path = posixpath.normpath(unquote(self.path))
words = path.split('/')
words = filter(None, words)
words = list(filter(None, words))
path = self.disk_root
for word in words:
drive, word = os.path.splitdrive(word)

Просмотреть файл

@ -3,12 +3,8 @@ subsuite = mozbase, os == "linux"
[api.py]
skip-if = python == 3
[baseurl.py]
skip-if = python == 3
[basic.py]
skip-if = python == 3
[filelisting.py]
skip-if = python == 3
[paths.py]
skip-if = python == 3
[requestlog.py]
skip-if = python == 3

Просмотреть файл

@ -9,7 +9,9 @@ from mozfile import TemporaryDirectory
import mozhttpd
import os
import unittest
import urllib2
from six.moves.urllib.request import urlopen
from six.moves.urllib.error import HTTPError
import mozunit
@ -17,13 +19,13 @@ import mozunit
class PathTest(unittest.TestCase):
def try_get(self, url, expected_contents):
f = urllib2.urlopen(url)
f = urlopen(url)
self.assertEqual(f.getcode(), 200)
self.assertEqual(f.read(), expected_contents)
def try_get_expect_404(self, url):
with self.assertRaises(urllib2.HTTPError) as cm:
urllib2.urlopen(url)
with self.assertRaises(HTTPError) as cm:
urlopen(url)
self.assertEqual(404, cm.exception.code)
def test_basic(self):
@ -36,8 +38,8 @@ class PathTest(unittest.TestCase):
path_mappings={'/files': d2}
)
httpd.start(block=False)
self.try_get(httpd.get_url("/test1.txt"), "test 1 contents")
self.try_get(httpd.get_url("/files/test2.txt"), "test 2 contents")
self.try_get(httpd.get_url("/test1.txt"), b"test 1 contents")
self.try_get(httpd.get_url("/files/test2.txt"), b"test 2 contents")
self.try_get_expect_404(httpd.get_url("/files/test2_nope.txt"))
httpd.stop()
@ -51,8 +53,8 @@ class PathTest(unittest.TestCase):
'/abc': d2, }
)
httpd.start(block=False)
self.try_get(httpd.get_url("/abcxyz/test1.txt"), "test 1 contents")
self.try_get(httpd.get_url("/abc/test2.txt"), "test 2 contents")
self.try_get(httpd.get_url("/abcxyz/test1.txt"), b"test 1 contents")
self.try_get(httpd.get_url("/abc/test2.txt"), b"test 2 contents")
httpd.stop()
def test_multipart_path_mapping(self):
@ -63,7 +65,7 @@ class PathTest(unittest.TestCase):
path_mappings={'/abc/def/ghi': d1}
)
httpd.start(block=False)
self.try_get(httpd.get_url("/abc/def/ghi/test1.txt"), "test 1 contents")
self.try_get(httpd.get_url("/abc/def/ghi/test1.txt"), b"test 1 contents")
self.try_get_expect_404(httpd.get_url("/abc/test1.txt"))
self.try_get_expect_404(httpd.get_url("/abc/def/test1.txt"))
httpd.stop()

Просмотреть файл

@ -5,10 +5,11 @@
from __future__ import absolute_import
import mozhttpd
import urllib2
import os
import unittest
from six.moves.urllib.request import urlopen
import mozunit
here = os.path.dirname(os.path.abspath(__file__))
@ -21,7 +22,7 @@ class RequestLogTest(unittest.TestCase):
httpd = mozhttpd.MozHttpd(port=0, docroot=here, log_requests=log_requests)
httpd.start(block=False)
url = "http://%s:%s/" % ('127.0.0.1', httpd.httpd.server_port)
f = urllib2.urlopen(url)
f = urlopen(url)
f.read()
return httpd.request_log