Merge "Python3: fix test_xprofile.py"

This commit is contained in:
Zuul 2018-12-13 20:33:16 +00:00 committed by Gerrit Code Review
commit d645e216c0
4 changed files with 21 additions and 12 deletions

View File

@ -21,9 +21,13 @@ import string
import tempfile
from swift import gettext_ as _
from exceptions import PLOTLIBNotInstalled, ODFLIBNotInstalled,\
NotFoundException, MethodNotAllowed, DataLoadFailure, ProfileException
from profile_model import Stats2
from swift.common.middleware.x_profile.exceptions import PLOTLIBNotInstalled
from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled
from swift.common.middleware.x_profile.exceptions import NotFoundException
from swift.common.middleware.x_profile.exceptions import MethodNotAllowed
from swift.common.middleware.x_profile.exceptions import DataLoadFailure
from swift.common.middleware.x_profile.exceptions import ProfileException
from swift.common.middleware.x_profile.profile_model import Stats2
PLOTLIB_INSTALLED = True
try:

View File

@ -86,10 +86,11 @@ from six.moves import urllib
from swift import gettext_ as _
from swift.common.utils import get_logger, config_true_value
from swift.common.swob import Request
from x_profile.exceptions import NotFoundException, MethodNotAllowed,\
ProfileException
from x_profile.html_viewer import HTMLViewer
from x_profile.profile_model import ProfileLog
from swift.common.middleware.x_profile.exceptions import MethodNotAllowed
from swift.common.middleware.x_profile.exceptions import NotFoundException
from swift.common.middleware.x_profile.exceptions import ProfileException
from swift.common.middleware.x_profile.html_viewer import HTMLViewer
from swift.common.middleware.x_profile.profile_model import ProfileLog
DEFAULT_PROFILE_PREFIX = '/tmp/log/swift/profile/default.profile'
@ -107,7 +108,10 @@ PROFILE_EXEC_LAZY = """
app_iter_ = self.app(environ, start_response)
"""
thread = patcher.original('thread') # non-monkeypatched module needed
if six.PY3:
thread = patcher.original('_thread') # non-monkeypatched module needed
else:
thread = patcher.original('thread') # non-monkeypatched module needed
# This monkey patch code fix the problem of eventlet profile tool
@ -177,7 +181,7 @@ class ProfileMiddleware(object):
def _combine_body_qs(self, request):
wsgi_input = request.environ['wsgi.input']
query_dict = request.params
qs_in_body = wsgi_input.read()
qs_in_body = wsgi_input.read().decode('utf-8')
query_dict.update(urllib.parse.parse_qs(qs_in_body,
keep_blank_values=True,
strict_parsing=False))

View File

@ -132,7 +132,7 @@ class TestProfileMiddleware(unittest.TestCase):
'QUERY_STRING': 'profile=all&format=json',
'wsgi.input': wsgi_input}
resp = self.app(environ, self.start_response)
self.assertTrue(resp[0].find('<html>') > 0, resp)
self.assertTrue(resp[0].find(b'<html>') > 0, resp)
self.assertEqual(self.got_statuses, ['200 OK'])
self.assertEqual(self.headers, [('content-type', 'text/html')])
wsgi_input = BytesIO(body + b'&plot=plot')
@ -144,12 +144,12 @@ class TestProfileMiddleware(unittest.TestCase):
else:
resp = self.app(environ, self.start_response)
self.assertEqual(self.got_statuses, ['500 Internal Server Error'])
wsgi_input = BytesIO(body + '&download=download&format=default')
wsgi_input = BytesIO(body + b'&download=download&format=default')
environ['wsgi.input'] = wsgi_input
resp = self.app(environ, self.start_response)
self.assertEqual(self.headers, [('content-type',
HTMLViewer.format_dict['default'])])
wsgi_input = BytesIO(body + '&download=download&format=json')
wsgi_input = BytesIO(body + b'&download=download&format=json')
environ['wsgi.input'] = wsgi_input
resp = self.app(environ, self.start_response)
self.assertTrue(self.headers == [('content-type',

View File

@ -56,6 +56,7 @@ commands =
test/unit/common/middleware/test_proxy_logging.py \
test/unit/common/middleware/test_subrequest_logging.py \
test/unit/common/middleware/test_tempauth.py \
test/unit/common/middleware/test_xprofile.py \
test/unit/common/ring \
test/unit/common/test_base_storage_server.py \
test/unit/common/test_bufferedhttp.py \