Merge "Fix and enable integration tests on py35."

This commit is contained in:
Jenkins 2017-04-13 23:49:15 +00:00 committed by Gerrit Code Review
commit 085f375a13
7 changed files with 24 additions and 13 deletions

View File

@ -249,7 +249,9 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
def _inject_location_header(self, response, task): def _inject_location_header(self, response, task):
location = self._get_task_location(task) location = self._get_task_location(task)
response.headers['Location'] = location.encode('utf-8') if six.PY2:
location = location.encode('utf-8')
response.headers['Location'] = location
def _get_task_location(self, task): def _get_task_location(self, task):
return '/v2/tasks/%s' % task.task_id return '/v2/tasks/%s' % task.task_id

View File

@ -202,7 +202,7 @@ class ApiTest(test_utils.BaseTestCase):
def _load_paste_app(self, name, flavor, conf): def _load_paste_app(self, name, flavor, conf):
conf_file_path = os.path.join(self.test_dir, '%s-paste.ini' % name) conf_file_path = os.path.join(self.test_dir, '%s-paste.ini' % name)
with open(conf_file_path, 'wb') as conf_file: with open(conf_file_path, 'w') as conf_file:
conf_file.write(conf) conf_file.write(conf)
conf_file.flush() conf_file.flush()
return config.load_paste_app(name, flavor=flavor, return config.load_paste_app(name, flavor=flavor,

View File

@ -46,7 +46,7 @@ class TestApi(base.ApiTest):
# 2. POST /images with public image named Image1 # 2. POST /images with public image named Image1
# attribute and no custom properties. Verify a 200 OK is returned # attribute and no custom properties. Verify a 200 OK is returned
image_data = "*" * FIVE_KB image_data = b"*" * FIVE_KB
headers = minimal_headers('Image1') headers = minimal_headers('Image1')
path = "/v1/images" path = "/v1/images"
response, content = self.http.request(path, 'POST', headers=headers, response, content = self.http.request(path, 'POST', headers=headers,
@ -100,8 +100,9 @@ class TestApi(base.ApiTest):
expected_value, expected_value,
response[expected_key])) response[expected_key]))
self.assertEqual("*" * FIVE_KB, content) content = content.encode('utf-8')
self.assertEqual(hashlib.md5("*" * FIVE_KB).hexdigest(), self.assertEqual(image_data, content)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
hashlib.md5(content).hexdigest()) hashlib.md5(content).hexdigest())
# 5. GET /images # 5. GET /images
@ -290,7 +291,7 @@ class TestApi(base.ApiTest):
self.assertEqual(image_id, response['x-image-meta-id']) self.assertEqual(image_id, response['x-image-meta-id'])
# 4. PUT image with image data, verify 200 returned # 4. PUT image with image data, verify 200 returned
image_data = "*" * FIVE_KB image_data = b"*" * FIVE_KB
headers = {'Content-Type': 'application/octet-stream'} headers = {'Content-Type': 'application/octet-stream'}
path = "/v1/images/%s" % (image_id) path = "/v1/images/%s" % (image_id)
response, content = self.http.request(path, 'PUT', headers=headers, response, content = self.http.request(path, 'PUT', headers=headers,
@ -388,7 +389,7 @@ class TestApi(base.ApiTest):
# Content-Type to application/octet-stream, verify a # Content-Type to application/octet-stream, verify a
# 400 returned and that the error is readable. # 400 returned and that the error is readable.
with tempfile.NamedTemporaryFile() as test_data_file: with tempfile.NamedTemporaryFile() as test_data_file:
test_data_file.write("XXX") test_data_file.write(b"XXX")
test_data_file.flush() test_data_file.flush()
path = "/v1/images" path = "/v1/images"
headers = minimal_headers('Image1') headers = minimal_headers('Image1')
@ -1003,7 +1004,7 @@ class TestApi(base.ApiTest):
headers = minimal_headers('Image1') headers = minimal_headers('Image1')
headers['X-Image-Meta-' + format] = 'bad_value' headers['X-Image-Meta-' + format] = 'bad_value'
with tempfile.NamedTemporaryFile() as test_data_file: with tempfile.NamedTemporaryFile() as test_data_file:
test_data_file.write("XXX") test_data_file.write(b"XXX")
test_data_file.flush() test_data_file.flush()
response, content = self.http.request(path, 'POST', response, content = self.http.request(path, 'POST',
headers=headers, headers=headers,
@ -1054,7 +1055,7 @@ class TestApi(base.ApiTest):
headers = minimal_headers('Image1') headers = minimal_headers('Image1')
del headers['X-Image-Meta-' + format] del headers['X-Image-Meta-' + format]
with tempfile.NamedTemporaryFile() as test_data_file: with tempfile.NamedTemporaryFile() as test_data_file:
test_data_file.write("XXX") test_data_file.write(b"XXX")
test_data_file.flush() test_data_file.flush()
response, content = self.http.request(path, 'PUT', response, content = self.http.request(path, 'PUT',
headers=headers, headers=headers,

View File

@ -197,7 +197,7 @@ class ApiTest(test_utils.BaseTestCase):
def _load_paste_app(self, name, flavor, conf): def _load_paste_app(self, name, flavor, conf):
conf_file_path = os.path.join(self.test_dir, '%s-paste.ini' % name) conf_file_path = os.path.join(self.test_dir, '%s-paste.ini' % name)
with open(conf_file_path, 'wb') as conf_file: with open(conf_file_path, 'w') as conf_file:
conf_file.write(conf) conf_file.write(conf)
conf_file.flush() conf_file.flush()
return config.load_paste_app(name, flavor=flavor, return config.load_paste_app(name, flavor=flavor,

View File

@ -114,6 +114,8 @@ class TestTasksApi(base.ApiTest):
self.assertEqual(task_owner, task['owner']) self.assertEqual(task_owner, task['owner'])
self.assertEqual(task_data['type'], task['type']) self.assertEqual(task_data['type'], task['type'])
self.assertEqual(task_data['input'], task['input']) self.assertEqual(task_data['input'], task['input'])
self.assertEqual("http://localhost" + path + "/" + task_id,
response.webob_resp.headers['Location'])
return task, task_data return task, task_data

View File

@ -627,9 +627,12 @@ class Httplib2WsgiAdapter(object):
def request(self, uri, method="GET", body=None, headers=None): def request(self, uri, method="GET", body=None, headers=None):
req = webob.Request.blank(uri, method=method, headers=headers) req = webob.Request.blank(uri, method=method, headers=headers)
req.body = body if isinstance(body, str):
req.body = body.encode('utf-8')
else:
req.body = body
resp = req.get_response(self.app) resp = req.get_response(self.app)
return Httplib2WebobResponse(resp), resp.body return Httplib2WebobResponse(resp), resp.body.decode('utf-8')
class Httplib2WebobResponse(object): class Httplib2WebobResponse(object):

View File

@ -64,7 +64,10 @@ commands =
glance.tests.functional.v2.test_metadef_resourcetypes \ glance.tests.functional.v2.test_metadef_resourcetypes \
glance.tests.functional.v2.test_metadef_tags \ glance.tests.functional.v2.test_metadef_tags \
glance.tests.functional.v2.test_images \ glance.tests.functional.v2.test_images \
glance.tests.functional.v2.test_metadef_namespaces glance.tests.functional.v2.test_metadef_namespaces \
glance.tests.integration.v2.test_tasks_api \
glance.tests.integration.v2.test_property_quota_violations \
glance.tests.integration.legacy_functional.test_v1_api
[testenv:pep8] [testenv:pep8]
commands = commands =