Merge "Extracted HTTP response codes to constants in tests"

This commit is contained in:
Jenkins 2016-10-21 08:54:28 +00:00 committed by Gerrit Code Review
commit 3eceb64dec
46 changed files with 1410 additions and 1300 deletions

View File

@ -15,6 +15,7 @@
from oslo_serialization import jsonutils
import requests
from six.moves import http_client as http
from glance.tests import functional
@ -42,7 +43,7 @@ class TestRegistryURLVisibility(functional.FunctionalTest):
path = self._url('/rpc')
response = requests.post(path, headers=self._headers(),
data=self.req_body)
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
self.stop_servers()
def test_v2_enabled(self):
@ -51,5 +52,5 @@ class TestRegistryURLVisibility(functional.FunctionalTest):
path = self._url('/rpc')
response = requests.post(path, headers=self._headers(),
data=self.req_body)
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
self.stop_servers()

View File

@ -19,6 +19,7 @@ import mock
from oslo_serialization import jsonutils
import pkg_resources
import requests
from six.moves import http_client as http
from glance.api.glare.v0_1 import glare
from glance.api.glare.v0_1 import router
@ -182,7 +183,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
super(TestArtifacts, self).start_servers(**kwargs)
def _create_artifact(self, type_name, type_version='1.0', data=None,
status=201):
status=http.CREATED):
# create an artifact first
artifact_data = data or {'name': 'artifact-1',
'version': '12'}
@ -190,7 +191,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
type_version),
artifact_data, status=status)
def _check_artifact_method(self, method, url, data=None, status=200,
def _check_artifact_method(self, method, url, data=None, status=http.OK,
headers=None):
if not headers:
headers = self._headers()
@ -202,13 +203,13 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
response = getattr(requests, method)(self._url(url), headers=headers,
data=data)
self.assertEqual(status, response.status_code)
if status >= 400:
if status >= http.BAD_REQUEST:
return response.text
if "application/json" in response.headers["content-type"]:
return jsonutils.loads(response.text)
return response.text
def _check_artifact_post(self, url, data, status=201,
def _check_artifact_post(self, url, data, status=http.CREATED,
headers=None):
if headers is None:
headers = {'Content-Type': 'application/json'}
@ -216,20 +217,20 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
return self._check_artifact_method("post", url, data, status=status,
headers=headers)
def _check_artifact_get(self, url, status=200):
def _check_artifact_get(self, url, status=http.OK):
return self._check_artifact_method("get", url, status=status)
def _check_artifact_delete(self, url, status=204):
def _check_artifact_delete(self, url, status=http.NO_CONTENT):
response = requests.delete(self._url(url), headers=self._headers())
self.assertEqual(status, response.status_code)
return response.text
def _check_artifact_patch(self, url, data, status=200,
def _check_artifact_patch(self, url, data, status=http.OK,
headers={'Content-Type': 'application/json'}):
return self._check_artifact_method("patch", url, data, status=status,
headers=headers)
def _check_artifact_put(self, url, data, status=200,
def _check_artifact_put(self, url, data, status=http.OK,
headers={'Content-Type': 'application/json'}):
return self._check_artifact_method("put", url, data, status=status,
headers=headers)
@ -268,7 +269,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
'/noprop/v1.0/drafts')["artifacts"]
self.assertEqual(1, len(list_creating))
bad_version = self._check_artifact_get('/noprop/v1.0bad',
status=400)
status=http.BAD_REQUEST)
self.assertIn("Invalid version string: u'1.0bad'", bad_version)
def test_list_artifacts_with_pagination(self):
@ -313,7 +314,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
a wrong version should result in
400 BadRequest 'No such plugin has been loaded'
"""
msg = self._check_artifact_get('/noprop/v0.0.9', 400)
msg = self._check_artifact_get('/noprop/v0.0.9', http.BAD_REQUEST)
self.assertIn("No plugin for 'noprop v 0.0.9' has been loaded",
msg)
@ -386,11 +387,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
artifact_id = art['id']
# 'hui' is invalid show level
self._check_artifact_get(
'/noprop/%s?show_level=yoba' % artifact_id, status=400)
'/noprop/%s?show_level=yoba' % artifact_id,
status=http.BAD_REQUEST)
def test_get_artifact_no_such_id(self):
msg = self._check_artifact_get(
'/noprop/%s' % str(uuid.uuid4()), status=404)
'/noprop/%s' % str(uuid.uuid4()), status=http.NOT_FOUND)
self.assertIn('No artifact found with ID', msg)
def test_get_artifact_present_id_wrong_type(self):
@ -402,11 +404,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
art2 = self._create_artifact('noprop')
# ok id and type_name but bad type_version should result in 404
self._check_artifact_get('/noprop/v0.5/%s' % str(art2['id']),
status=404)
status=http.NOT_FOUND)
# try to access art2 by supplying art1.type and art2.id
self._check_artifact_get('/withprops/%s' % str(art2['id']),
status=404)
self._check_artifact_get('/noprop/%s' % str(art1['id']), status=404)
status=http.NOT_FOUND)
self._check_artifact_get('/noprop/%s' % str(art1['id']),
status=http.NOT_FOUND)
def test_delete_artifact(self):
artifact_data = {'name': 'artifact-1',
@ -416,12 +419,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
art1 = self._create_artifact('withprops', data=artifact_data)
self._check_artifact_delete('/withprops/v1.0/%s' % art1['id'])
art1_deleted = self._check_artifact_get('/withprops/%s' % art1['id'],
status=404)
status=http.NOT_FOUND)
self.assertIn('No artifact found with ID', art1_deleted)
def test_delete_artifact_no_such_id(self):
self._check_artifact_delete('/noprop/v1/%s' % str(uuid.uuid4()),
status=404)
status=http.NOT_FOUND)
@unittest.skip("Test is unstable")
def test_delete_artifact_with_dependency(self):
@ -441,7 +444,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
self.assertEqual(1, len(art_updated['depends_on_list']))
# try to delete an artifact prior to its dependency
res = self._check_artifact_delete('/withprops/v1/%s' % art['id'],
status=400)
status=http.BAD_REQUEST)
self.assertIn(
"Dependency property 'depends_on' has to be deleted first", res)
# delete a dependency
@ -450,7 +453,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
data=[{'op': 'remove', 'path': '/depends_on'}])
# try to delete prior to deleting artifact_list dependencies
res = self._check_artifact_delete('/withprops/v1/%s' % art['id'],
status=400)
status=http.BAD_REQUEST)
self.assertIn(
"Dependency property 'depends_on_list' has to be deleted first",
res)
@ -466,7 +469,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
headers = self._headers({'Content-Type': 'application/octet-stream'})
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
headers=headers,
data='ZZZZZ', status=200)
data='ZZZZZ', status=http.OK)
self._check_artifact_delete('/withblob/v1/%s' % art['id'])
def test_update_nonexistent_property_by_replace_op(self):
@ -477,7 +480,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
result = self._check_artifact_patch('/withprops/v1/%s' %
art['id'],
data=data,
status=400)
status=http.BAD_REQUEST)
self.assertIn('400 Bad Request', result)
self.assertIn('Artifact has no property nonexistent_property', result)
@ -489,7 +492,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
result = self._check_artifact_patch('/withprops/v1/%s' %
art['id'],
data=data,
status=400)
status=http.BAD_REQUEST)
self.assertIn('400 Bad Request', result)
self.assertIn('Artifact has no property nonexistent_property', result)
@ -554,7 +557,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
'path': '/dict_prop/foo'}]
art_updated = self._check_artifact_patch('/withprops/v1/%s'
% art['id'],
data=data, status=400)
data=data,
status=http.BAD_REQUEST)
self.assertIn("The provided path 'dict_prop/foo' is invalid",
art_updated)
@ -564,7 +568,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
data = [{'op': 'remove', 'path': '/dict_prop/bar_list'}]
art_updated = self._check_artifact_patch('/withprops/v1/%s'
% art['id'],
data=data, status=400)
data=data,
status=http.BAD_REQUEST)
self.assertIn("The provided path 'dict_prop/bar_list' is invalid",
art_updated)
@ -654,7 +659,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
art_updated = self._check_artifact_patch('/withprops/v1/%s'
% art['id'],
data=bad_index_data,
status=400)
status=http.BAD_REQUEST)
self.assertIn("The provided path 'prop_list/11' is invalid",
art_updated)
@ -723,7 +728,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
data = [{'op': 'remove', 'value': 'some value',
'path': '/non-existent-path/and-another'}]
art_updated = self._check_artifact_patch(
'/withprops/v1/%s' % art['id'], data=data, status=400)
'/withprops/v1/%s' % art['id'], data=data,
status=http.BAD_REQUEST)
self.assertIn('Artifact has no property', art_updated)
def test_update_replace_non_existent_artifact_properties(self):
@ -733,7 +739,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
data = [{'op': 'replace', 'value': 'some value',
'path': '/non-existent-path/and-another'}]
art_updated = self._check_artifact_patch(
'/withprops/v1/%s' % art['id'], data=data, status=400)
'/withprops/v1/%s' % art['id'], data=data,
status=http.BAD_REQUEST)
self.assertIn('Artifact has no property', art_updated)
def test_update_artifact_remove_property(self):
@ -756,7 +763,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
self.assertIsNone(art[prop])
data = [{'op': 'replace', 'value': 123, 'path': '/prop1'}]
art_updated = self._check_artifact_patch(
'/withprops/v1/%s' % art['id'], data=data, status=400)
'/withprops/v1/%s' % art['id'], data=data, status=http.BAD_REQUEST)
self.assertIn("Property 'prop1' may not have value '123'", art_updated)
def test_update_multiple_properties(self):
@ -798,7 +805,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
'withprops',
data={"name": "name", "version": "42",
"depends_on_list": [no_prop_art['id'],
no_prop_art['id']]}, status=400)
no_prop_art['id']]},
status=http.BAD_REQUEST)
self.assertIn("Items have to be unique", res)
def test_create_artifact_bad_dependency_format(self):
@ -812,12 +820,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
art = self._check_artifact_post(
'/withprops/v1/drafts',
{"name": "name", "version": "42",
"depends_on": [no_prop_art['id']]}, status=400)
"depends_on": [no_prop_art['id']]}, status=http.BAD_REQUEST)
self.assertIn('Not a valid value type', art)
art = self._check_artifact_post(
'/withprops/v1.0/drafts',
{"name": "name", "version": "42",
"depends_on_list": no_prop_art['id']}, status=400)
"depends_on_list": no_prop_art['id']}, status=http.BAD_REQUEST)
self.assertIn('object is not iterable', art)
def test_update_dependency(self):
@ -846,7 +854,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
'path': '/depends_on',
'value': [with_prop_art['id']]}]
not_updated = self._check_artifact_patch(
'/withprops/v1/%s' % with_prop_art['id'], data=data, status=400)
'/withprops/v1/%s' % with_prop_art['id'], data=data,
status=http.BAD_REQUEST)
self.assertIn('Artifact with a circular dependency can not be created',
not_updated)
@ -862,14 +871,15 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
self.assertNotEqual(0, len(art_updated['depends_on']))
# artifact can't be published if any dependency is in non-active state
res = self._check_artifact_post(
'/withprops/v1/%s/publish' % art['id'], {}, status=400)
'/withprops/v1/%s/publish' % art['id'], {},
status=http.BAD_REQUEST)
self.assertIn("Not all dependencies are in 'active' state", res)
# after you publish the dependency -> artifact can be published
dep_published = self._check_artifact_post(
'/noprop/v1/%s/publish' % no_prop_art['id'], {}, status=200)
'/noprop/v1/%s/publish' % no_prop_art['id'], {}, status=http.OK)
self.assertEqual('active', dep_published['state'])
art_published = self._check_artifact_post(
'/withprops/v1.0/%s/publish' % art['id'], {}, status=200)
'/withprops/v1.0/%s/publish' % art['id'], {}, status=http.OK)
self.assertEqual('active', art_published['state'])
def test_no_mutable_change_in_published_state(self):
@ -891,25 +901,26 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
self.assertEqual(no_prop_other['id'], art_updated['depends_on']['id'])
# publish dependency
dep_published = self._check_artifact_post(
'/noprop/v1/%s/publish' % no_prop_other['id'], {}, status=200)
'/noprop/v1/%s/publish' % no_prop_other['id'], {}, status=http.OK)
self.assertEqual('active', dep_published['state'])
# publish artifact
art_published = self._check_artifact_post(
'/withprops/v1.0/%s/publish' % art['id'], {}, status=200)
'/withprops/v1.0/%s/publish' % art['id'], {}, status=http.OK)
self.assertEqual('active', art_published['state'])
# try to change dependency, should fail as already published
res = self._check_artifact_patch(
'/withprops/v1/%s' % art_published['id'],
data=[{'op': 'remove', 'path': '/depends_on'}], status=400)
data=[{'op': 'remove', 'path': '/depends_on'}],
status=http.BAD_REQUEST)
self.assertIn('Attempt to set value of immutable property', res)
def test_create_artifact_empty_body(self):
self._check_artifact_post('/noprop/v1.0/drafts', {}, 400)
self._check_artifact_post('/noprop/v1.0/drafts', {}, http.BAD_REQUEST)
def test_create_artifact_insufficient_arguments(self):
self._check_artifact_post('/noprop/v1.0/drafts',
{'name': 'some name, no version'},
status=400)
status=http.BAD_REQUEST)
def test_create_artifact_no_such_version(self):
"""Creation impossible without specifying a correct version.
@ -919,12 +930,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
400 BadRequest 'No such plugin has been loaded'
"""
# make sure there is no such artifact noprop
self._check_artifact_get('/noprop/v0.0.9', 400)
self._check_artifact_get('/noprop/v0.0.9', http.BAD_REQUEST)
artifact_data = {'name': 'artifact-1',
'version': '12'}
msg = self._check_artifact_post('/noprop/v0.0.9/drafts',
artifact_data,
status=400)
status=http.BAD_REQUEST)
self.assertIn("No plugin for 'noprop v 0.0.9' has been loaded",
msg)
@ -936,7 +947,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
"""
artifact_data = {'name': 'artifact-1',
'version': '12'}
self._check_artifact_post('/noprop/drafts', artifact_data, 404)
self._check_artifact_post('/noprop/drafts', artifact_data,
http.NOT_FOUND)
def test_create_artifact_no_properties(self):
"""Create an artifact with minimum parameters"""
@ -1022,13 +1034,13 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
'prop1': 1}
res = self._check_artifact_post('/withprops/v1.0/drafts',
artifact_data,
status=400)
status=http.BAD_REQUEST)
self.assertIn("Property 'prop1' may not have value '1'", res)
artifact_data.pop('prop1')
artifact_data['nosuchprop'] = "Random"
res = self._check_artifact_post('/withprops/v1.0/drafts',
artifact_data,
status=400)
status=http.BAD_REQUEST)
self.assertIn("Artifact has no property nosuchprop", res)
def test_create_public_artifact(self):
@ -1059,18 +1071,18 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
headers = self._headers({'Content-Type': 'application/octet-stream'})
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
headers=headers,
data='ZZZZZ', status=200)
data='ZZZZZ', status=http.OK)
def test_upload_file_with_invalid_content_type(self):
art = self._create_artifact('withblob')
data = {'data': 'jjjjjj'}
res = self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
data=data, status=400)
data=data, status=http.BAD_REQUEST)
self.assertIn('Invalid Content-Type for work with blob1', res)
res = self._check_artifact_post('/withblob/v1/%s/blob_list'
% art['id'],
data=data, status=400)
data=data, status=http.BAD_REQUEST)
self.assertIn('Invalid Content-Type for work with blob_list', res)
def test_upload_list_files(self):
@ -1078,10 +1090,10 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
headers = self._headers({'Content-Type': 'application/octet-stream'})
self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'],
headers=headers,
data='ZZZZZ', status=200)
data='ZZZZZ', status=http.OK)
self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'],
headers=headers,
data='YYYYY', status=200)
data='YYYYY', status=http.OK)
def test_download_file(self):
# Download some data from an artifact
@ -1090,7 +1102,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
headers = self._headers({'Content-Type': 'application/octet-stream'})
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
headers=headers,
data='ZZZZZ', status=200)
data='ZZZZZ', status=http.OK)
art = self._check_artifact_get('/withblob/%s' % artifact_id)
self.assertEqual(artifact_id, art['id'])
@ -1113,7 +1125,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
headers = self._headers({'Content-Type': 'application/octet-stream'})
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
headers=headers,
data=iterate_string('ZZZZZ'), status=200)
data=iterate_string('ZZZZZ'), status=http.OK)
art = self._check_artifact_get('/withblob/%s' % artifact_id)
self.assertEqual(artifact_id, art['id'])
@ -1212,12 +1224,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
# append to list property via POST
upd = self._check_artifact_post(
'/withprops/v1.0/%s/prop_list' % art['id'], data={'data': [11]},
status=200)
status=http.OK)
self.assertEqual([11], upd['prop_list'])
# append to list property via POST
upd = self._check_artifact_post(
'/withprops/v1.0/%s/prop_list/-' % art['id'],
status=200, data={'data': 10})
status=http.OK, data={'data': 10})
self.assertEqual([11, 10], upd['prop_list'])
def test_bad_update_property(self):
@ -1227,22 +1239,23 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
# try to update nonexistent property
upd = self._check_artifact_put(
'/withprops/v1.0/%s/nosuchprop' % art['id'],
data={'data': 'wont be set'}, status=400)
data={'data': 'wont be set'}, status=http.BAD_REQUEST)
self.assertIn('Artifact has no property nosuchprop', upd)
# try to pass wrong property value
upd = self._check_artifact_put(
'/withprops/v1.0/%s/tuple_prop' % art['id'],
data={'data': ['should be an int', False]}, status=400)
data={'data': ['should be an int', False]},
status=http.BAD_REQUEST)
self.assertIn("Property 'tuple_prop[0]' may not have value", upd)
# try to pass bad body (not a valid json)
upd = self._check_artifact_put(
'/withprops/v1.0/%s/tuple_prop' % art['id'], data="not a json",
status=400)
status=http.BAD_REQUEST)
self.assertIn("Invalid json body", upd)
# try to pass json body invalid under schema
upd = self._check_artifact_put(
'/withprops/v1.0/%s/tuple_prop' % art['id'],
data={"bad": "schema"}, status=400)
data={"bad": "schema"}, status=http.BAD_REQUEST)
self.assertIn("Invalid json body", upd)
def test_update_different_depths_levels(self):
@ -1251,36 +1264,36 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
art = self._create_artifact('withprops', data=data)
upd = self._check_artifact_post(
'/withprops/v1.0/%s/dict_prop' % art['id'],
data={'data': {'foo': 'some value'}}, status=200)
data={'data': {'foo': 'some value'}}, status=http.OK)
self.assertEqual({'foo': 'some value'}, upd['dict_prop'])
upd = self._check_artifact_post(
'/withprops/v1.0/%s/dict_prop/bar_list' % art['id'],
data={'data': [5]}, status=200)
data={'data': [5]}, status=http.OK)
self.assertEqual({'foo': 'some value', 'bar_list': [5]},
upd['dict_prop'])
upd = self._check_artifact_post(
'/withprops/v1.0/%s/dict_prop/bar_list/0' % art['id'],
data={'data': 15}, status=200)
data={'data': 15}, status=http.OK)
self.assertEqual({'foo': 'some value', 'bar_list': [5, 15]},
upd['dict_prop'])
# try to attempt dict_property by nonexistent path
upd = self._check_artifact_post(
'/withprops/v1.0/%s/dict_prop/bar_list/nosuchkey' % art['id'],
data={'data': 15}, status=400)
data={'data': 15}, status=http.BAD_REQUEST)
def test_artifact_inaccessible_by_different_user(self):
data = {'name': 'an artifact',
'version': '42'}
art = self._create_artifact('withprops', data=data)
self._set_user('user2')
self._check_artifact_get('/withprops/%s' % art['id'], 404)
self._check_artifact_get('/withprops/%s' % art['id'], http.NOT_FOUND)
def test_artifact_accessible_by_admin(self):
data = {'name': 'an artifact',
'version': '42'}
art = self._create_artifact('withprops', data=data)
self._set_user('admin')
self._check_artifact_get('/withprops/%s' % art['id'], 200)
self._check_artifact_get('/withprops/%s' % art['id'], http.OK)
def test_public_artifact_accessible_by_different_user(self):
data = {'name': 'an artifact',
@ -1290,7 +1303,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
'/withprops/v1.0/%s' % art['id'],
data=[{'op': 'replace', 'value': 'public', 'path': '/visibility'}])
self._set_user('user2')
self._check_artifact_get('/withprops/%s' % art['id'], 200)
self._check_artifact_get('/withprops/%s' % art['id'], http.OK)
def test_public_artifact_not_editable_by_different_user(self):
data = {'name': 'an artifact',
@ -1303,7 +1316,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
self._check_artifact_patch(
'/withprops/v1.0/%s' % art['id'],
data=[{'op': 'replace', 'value': 'private',
'path': '/visibility'}], status=403)
'path': '/visibility'}], status=http.FORBIDDEN)
def test_public_artifact_editable_by_admin(self):
data = {'name': 'an artifact',
@ -1316,7 +1329,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
self._check_artifact_patch(
'/withprops/v1.0/%s' % art['id'],
data=[{'op': 'replace', 'value': 'private',
'path': '/visibility'}], status=200)
'path': '/visibility'}], status=http.OK)
def test_list_artifact_types(self):
actual = {
@ -1347,7 +1360,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
u'http://127.0.0.1:%d/v0.1/artifacts/withprops/v1.0'
% self.api_port}]}]}
response = self._check_artifact_get("", status=200)
response = self._check_artifact_get("", status=http.OK)
response[u'artifact_types'].sort(key=lambda x: x[u'type_name'])
for artifact_type in response[u'artifact_types']:
artifact_type[u'versions'].sort(key=lambda x: x[u'id'])
@ -1358,7 +1371,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
data = {'name': 'name1', 'version': '2.2'}
self._check_artifact_post('/withprops/v1.0/drafts',
data=data,
status=400,
status=http.BAD_REQUEST,
headers={'Content-Type': 'lalala'})
def test_filter_by_non_dict_props(self):
@ -1905,7 +1918,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
self.assertEqual(2, len(result))
url = '/withprops/v1.0/drafts?version=latest'
self._check_artifact_get(url=url, status=400)
self._check_artifact_get(url=url, status=http.BAD_REQUEST)
def test_filter_by_version_only(self):
data = {'name': 'art1',
@ -1942,7 +1955,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
result = self._check_artifact_patch(
'/withblob/v1.0/%s' % art['id'],
status=400,
status=http.BAD_REQUEST,
data=[{'op': 'replace',
'value': 'public',
'path': '/blob1'}])
@ -1950,7 +1963,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
result = self._check_artifact_patch(
'/withblob/v1.0/%s' % art['id'],
status=400,
status=http.BAD_REQUEST,
data=[{'op': 'remove',
'value': 'public',
'path': '/blob1'}])
@ -1958,7 +1971,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
result = self._check_artifact_patch(
'/withblob/v1.0/%s' % art['id'],
status=400,
status=http.BAD_REQUEST,
data=[{'op': 'add',
'value': 'public',
'path': '/blob1'}])
@ -1970,7 +1983,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
'Use semver notation')
for bad_version in bad_versions:
url = '/withprops/v1.0/drafts?version=gt:%s' % bad_version
result = self._check_artifact_get(url=url, status=400)
result = self._check_artifact_get(url=url, status=http.BAD_REQUEST)
self.assertIn(response_string % bad_version, result)
def test_circular_dependency(self):
@ -1980,6 +1993,6 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
upd = self._check_artifact_post(
'/withprops/v1.0/%s/depends_on' % art['id'],
data={'data': art['id']}, status=400)
data={'data': art['id']}, status=http.BAD_REQUEST)
self.assertIn(
'Artifact with a circular dependency can not be created', upd)

View File

@ -24,6 +24,7 @@ import threading
from oslo_utils import units
from six.moves import BaseHTTPServer
from six.moves import http_client as http
FIVE_KB = 5 * units.Ki
@ -35,13 +36,13 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
Respond to an image HEAD request fake metadata
"""
if 'images' in self.path:
self.send_response(200)
self.send_response(http.OK)
self.send_header('Content-Type', 'application/octet-stream')
self.send_header('Content-Length', FIVE_KB)
self.end_headers()
return
else:
self.send_error(404, 'File Not Found: %s' % self.path)
self.send_error(http.NOT_FOUND, 'File Not Found: %s' % self.path)
return
def do_GET(self):
@ -49,7 +50,7 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
Respond to an image GET request with fake image content.
"""
if 'images' in self.path:
self.send_response(200)
self.send_response(http.OK)
self.send_header('Content-Type', 'application/octet-stream')
self.send_header('Content-Length', FIVE_KB)
self.end_headers()
@ -58,7 +59,7 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.wfile.close()
return
else:
self.send_error(404, 'File Not Found: %s' % self.path)
self.send_error(http.NOT_FOUND, 'File Not Found: %s' % self.path)
return
def log_message(self, format, *args):

View File

@ -18,6 +18,7 @@
import httplib2
from oslo_serialization import jsonutils
from six.moves import http_client
from glance.tests import functional
@ -73,7 +74,7 @@ class TestApiVersions(functional.FunctionalTest):
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(versions_json, content)
def test_v2_api_configuration(self):
@ -115,7 +116,7 @@ class TestApiVersions(functional.FunctionalTest):
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(versions_json, content)
def test_v1_api_configuration(self):
@ -142,7 +143,7 @@ class TestApiVersions(functional.FunctionalTest):
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(versions_json, content)
@ -201,7 +202,7 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(self.versions_json, content)
def test_get_images_path(self):
@ -211,7 +212,7 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(self.versions_json, content)
def test_get_v1_images_path(self):
@ -221,7 +222,7 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/v1/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
def test_get_root_path_with_unknown_header(self):
"""Assert GET / with Accept: unknown header
@ -232,7 +233,7 @@ class TestApiPaths(functional.FunctionalTest):
http = httplib2.Http()
headers = {'Accept': 'unknown'}
response, content = http.request(path, 'GET', headers=headers)
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(self.versions_json, content)
def test_get_root_path_with_openstack_header(self):
@ -243,7 +244,7 @@ class TestApiPaths(functional.FunctionalTest):
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.images-v1'}
response, content = http.request(path, 'GET', headers=headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(self.images_json, content)
def test_get_images_path_with_openstack_header(self):
@ -256,7 +257,7 @@ class TestApiPaths(functional.FunctionalTest):
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.compute-v1'}
response, content = http.request(path, 'GET', headers=headers)
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(self.versions_json, content)
def test_get_v10_images_path(self):
@ -266,7 +267,7 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
def test_get_v1a_images_path(self):
"""Assert GET /v1.a/images with no Accept: header
@ -275,7 +276,7 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
def test_get_va1_images_path(self):
"""Assert GET /va.1/images with no Accept: header
@ -284,7 +285,7 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/va.1/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(self.versions_json, content)
def test_get_versions_path(self):
@ -294,7 +295,7 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(self.versions_json, content)
def test_get_versions_path_with_openstack_header(self):
@ -306,7 +307,7 @@ class TestApiPaths(functional.FunctionalTest):
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.images-v1'}
response, content = http.request(path, 'GET', headers=headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(self.versions_json, content)
def test_get_v1_versions_path(self):
@ -316,14 +317,14 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/v1/versions' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(404, response.status)
self.assertEqual(http_client.NOT_FOUND, response.status)
def test_get_versions_choices(self):
"""Verify version choices returned"""
path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(self.versions_json, content)
def test_get_images_path_with_openstack_v2_header(self):
@ -336,7 +337,7 @@ class TestApiPaths(functional.FunctionalTest):
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.images-v10'}
response, content = http.request(path, 'GET', headers=headers)
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(self.versions_json, content)
def test_get_v12_images_path(self):
@ -346,5 +347,5 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/v1.2/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
self.assertEqual(self.versions_json, content)

View File

@ -23,6 +23,7 @@ import sys
import httplib2
from oslo_serialization import jsonutils
from oslo_utils import units
from six.moves import http_client
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
@ -61,7 +62,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
@ -144,7 +145,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
ids[1])
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertTrue(self.is_image_cached(ids[1]),
"%s is not cached." % ids[1])

View File

@ -29,6 +29,7 @@ import time
import httplib2
from oslo_serialization import jsonutils
from oslo_utils import units
from six.moves import http_client
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
@ -61,7 +62,7 @@ class BaseCacheMiddlewareTest(object):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
@ -81,7 +82,7 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Verify image now in cache
image_cached_path = os.path.join(self.api_server.image_cache_dir,
@ -111,7 +112,7 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertFalse(os.path.exists(image_cached_path))
@ -136,7 +137,7 @@ class BaseCacheMiddlewareTest(object):
response, content = http.request(path, 'POST',
headers=headers,
body=jsonutils.dumps(image_entity))
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
image_id = data['id']
@ -147,7 +148,7 @@ class BaseCacheMiddlewareTest(object):
response, content = http.request(path, 'PUT',
headers=headers,
body=image_data)
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
# Verify image not in cache
image_cached_path = os.path.join(self.api_server.image_cache_dir,
@ -157,7 +158,7 @@ class BaseCacheMiddlewareTest(object):
# Grab the image
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Verify image now in cache
image_cached_path = os.path.join(self.api_server.image_cache_dir,
@ -169,7 +170,7 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
self.assertFalse(os.path.exists(image_cached_path))
@ -195,7 +196,7 @@ class BaseCacheMiddlewareTest(object):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
self.assertEqual(FIVE_KB, data['image']['size'])
@ -206,13 +207,13 @@ class BaseCacheMiddlewareTest(object):
# Grab the image
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Grab the image again to ensure it can be served out from
# cache with the correct size
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(FIVE_KB, int(response['content-length']))
self.stop_servers()
@ -233,7 +234,7 @@ class BaseCacheMiddlewareTest(object):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
@ -257,7 +258,7 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
# Now, we delete the image from the server and verify that
# the image cache no longer contains the deleted image
@ -265,7 +266,7 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertFalse(os.path.exists(image_cached_path))
@ -293,7 +294,7 @@ class BaseCacheMiddlewareTest(object):
response, content = http.request(path, 'POST',
headers=headers,
body=jsonutils.dumps(image_entity))
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
image_id = data['id']
@ -304,7 +305,7 @@ class BaseCacheMiddlewareTest(object):
response, content = http.request(path, 'PUT',
headers=headers,
body=image_data)
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
# Verify image not in cache
image_cached_path = os.path.join(self.api_server.image_cache_dir,
@ -318,7 +319,7 @@ class BaseCacheMiddlewareTest(object):
# Grab the image
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
# Now, we delete the image from the server and verify that
# the image cache no longer contains the deleted image
@ -326,7 +327,7 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
self.assertFalse(os.path.exists(image_cached_path))
@ -350,7 +351,7 @@ class BaseCacheMiddlewareTest(object):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
@ -365,7 +366,7 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Verify image in cache
image_cached_path = os.path.join(self.api_server.image_cache_dir,
@ -377,14 +378,14 @@ class BaseCacheMiddlewareTest(object):
path = path % ("127.0.0.1", self.api_port, image_id)
http = httplib2.Http()
response, content = http.request(path, 'POST')
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
# Download the image with v1. Ensure it is forbidden
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
# Download the image with v2. This succeeds because
# we are in admin context.
@ -392,28 +393,28 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Reactivate the image using v2
path = "http://%s:%d/v2/images/%s/actions/reactivate"
path = path % ("127.0.0.1", self.api_port, image_id)
http = httplib2.Http()
response, content = http.request(path, 'POST')
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
# Download the image with v1. Ensure it is allowed
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Download the image with v2. Ensure it is allowed
path = "http://%s:%d/v2/images/%s/file" % ("127.0.0.1", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Now, we delete the image from the server and verify that
# the image cache no longer contains the deleted image
@ -421,7 +422,7 @@ class BaseCacheMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertFalse(os.path.exists(image_cached_path))
@ -436,7 +437,7 @@ class BaseCacheManageMiddlewareTest(object):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('images', data)
self.assertEqual(0, len(data['images']))
@ -453,7 +454,7 @@ class BaseCacheManageMiddlewareTest(object):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
@ -469,7 +470,7 @@ class BaseCacheManageMiddlewareTest(object):
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('cached_images', data)
@ -493,13 +494,13 @@ class BaseCacheManageMiddlewareTest(object):
image_id1)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Verify image now in cache
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('cached_images', data)
@ -516,27 +517,27 @@ class BaseCacheManageMiddlewareTest(object):
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
# Verify an unprivileged user cannot delete images from the cache
path = "http://%s:%d/v1/cached_images/%s" % ("127.0.0.1",
self.api_port, image_id1)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
# Verify an unprivileged user cannot delete all cached images
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
# Verify an unprivileged user cannot queue an image
path = "http://%s:%d/v1/queued_images/%s" % ("127.0.0.1",
self.api_port, image_id2)
http = httplib2.Http()
response, content = http.request(path, 'PUT')
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
self.stop_servers()
@ -561,13 +562,13 @@ class BaseCacheManageMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Verify image now in cache
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('cached_images', data)
@ -593,13 +594,13 @@ class BaseCacheManageMiddlewareTest(object):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Verify image hits increased in output of manage GET
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('cached_images', data)
@ -637,14 +638,14 @@ class BaseCacheManageMiddlewareTest(object):
ids[x])
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status,
self.assertEqual(http_client.OK, response.status,
"Failed to find image %s" % ids[x])
# Verify images now in cache
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('cached_images', data)
@ -661,12 +662,12 @@ class BaseCacheManageMiddlewareTest(object):
self.api_port, ids[2])
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('cached_images', data)
@ -679,12 +680,12 @@ class BaseCacheManageMiddlewareTest(object):
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('cached_images', data)
@ -714,13 +715,13 @@ class BaseCacheManageMiddlewareTest(object):
self.api_port, ids[x])
http = httplib2.Http()
response, content = http.request(path, 'PUT')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# Delete all queued images
path = "http://%s:%d/v1/queued_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
num_deleted = data['num_deleted']
@ -730,7 +731,7 @@ class BaseCacheManageMiddlewareTest(object):
path = "http://%s:%d/v1/queued_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
num_deleted = data['num_deleted']
@ -785,7 +786,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
self.api_port, ids[0])
http = httplib2.Http()
response, content = http.request(path, 'PUT')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.verify_no_cached_images()
@ -801,7 +802,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertIn('cached_images', data)

View File

@ -18,6 +18,7 @@
import eventlet.patcher
import httplib2
from six.moves import http_client
import webob.dec
import webob.exc
@ -46,14 +47,14 @@ class ExceptionTestApp(object):
elif path == "/rate-limit-retry":
request.response.retry_after = 10
request.response.status = 413
request.response.status = http_client.REQUEST_ENTITY_TOO_LARGE
elif path == "/service-unavailable":
request.response = webob.exc.HTTPServiceUnavailable()
elif path == "/service-unavailable-retry":
request.response.retry_after = 10
request.response.status = 503
request.response.status = http_client.SERVICE_UNAVAILABLE
elif path == "/expectation-failed":
request.response = webob.exc.HTTPExpectationFailed()
@ -134,4 +135,4 @@ class TestClientExceptions(functional.FunctionalTest):
('127.0.0.1', self.port))
response, content = http.request(path, 'GET')
self.assertNotIn(b'ServerError', content)
self.assertEqual(500, response.status)
self.assertEqual(http_client.INTERNAL_SERVER_ERROR, response.status)

View File

@ -16,6 +16,7 @@
"""Functional test cases testing glance client redirect-following."""
import eventlet.patcher
from six.moves import http_client as http
import webob.dec
import webob.exc
@ -97,7 +98,7 @@ class TestClientRedirects(functional.FunctionalTest):
Test GET with no redirect
"""
response = self.client.do_request("GET", "/")
self.assertEqual(200, response.status)
self.assertEqual(http.OK, response.status)
self.assertEqual("root", response.read())
def test_get_with_one_redirect(self):
@ -105,7 +106,7 @@ class TestClientRedirects(functional.FunctionalTest):
Test GET with one 302 FOUND redirect
"""
response = self.client.do_request("GET", "/302")
self.assertEqual(200, response.status)
self.assertEqual(http.OK, response.status)
self.assertEqual("success_from_host_one", response.read())
def test_get_with_one_redirect_query_string(self):
@ -114,7 +115,7 @@ class TestClientRedirects(functional.FunctionalTest):
"""
response = self.client.do_request("GET", "/302",
params={'with_qs': 'yes'})
self.assertEqual(200, response.status)
self.assertEqual(http.OK, response.status)
self.assertEqual("success_with_qs", response.read())
def test_get_with_max_redirects(self):
@ -131,7 +132,7 @@ class TestClientRedirects(functional.FunctionalTest):
Test POST with 302 redirect
"""
response = self.client.do_request("POST", "/302")
self.assertEqual(200, response.status)
self.assertEqual(http.OK, response.status)
self.assertEqual("success_from_host_one", response.read())
def test_redirect_to_new_host(self):
@ -141,9 +142,9 @@ class TestClientRedirects(functional.FunctionalTest):
url = "/redirect-to-%d" % self.port_two
response = self.client.do_request("POST", url)
self.assertEqual(200, response.status)
self.assertEqual(http.OK, response.status)
self.assertEqual("success_from_host_two", response.read())
response = self.client.do_request("POST", "/success")
self.assertEqual(200, response.status)
self.assertEqual(http.OK, response.status)
self.assertEqual("success_from_host_one", response.read())

View File

@ -15,6 +15,7 @@
"""Tests cors middleware."""
import httplib2
from six.moves import http_client
from glance.tests import functional
@ -43,7 +44,7 @@ class TestCORSMiddleware(functional.FunctionalTest):
'Access-Control-Request-Method': 'GET'
})
self.assertEqual(200, r_headers.status)
self.assertEqual(http_client.OK, r_headers.status)
self.assertIn('access-control-allow-origin', r_headers)
self.assertEqual('http://valid.example.com',
r_headers['access-control-allow-origin'])
@ -57,7 +58,7 @@ class TestCORSMiddleware(functional.FunctionalTest):
'Access-Control-Request-Method': 'GET'
})
self.assertEqual(200, r_headers.status)
self.assertEqual(http_client.OK, r_headers.status)
self.assertNotIn('access-control-allow-origin', r_headers)
def test_valid_cors_get_request(self):
@ -68,7 +69,7 @@ class TestCORSMiddleware(functional.FunctionalTest):
'Origin': 'http://valid.example.com'
})
self.assertEqual(200, r_headers.status)
self.assertEqual(http_client.OK, r_headers.status)
self.assertIn('access-control-allow-origin', r_headers)
self.assertEqual('http://valid.example.com',
r_headers['access-control-allow-origin'])
@ -81,5 +82,5 @@ class TestCORSMiddleware(functional.FunctionalTest):
'Origin': 'http://invalid.example.com'
})
self.assertEqual(200, r_headers.status)
self.assertEqual(http_client.OK, r_headers.status)
self.assertNotIn('access-control-allow-origin', r_headers)

View File

@ -18,6 +18,7 @@
import tempfile
import httplib2
from six.moves import http_client
from glance.tests import functional
from glance.tests import utils
@ -37,7 +38,7 @@ class HealthcheckMiddlewareTest(functional.FunctionalTest):
response, content = self.request()
self.assertEqual('OK', content)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.stop_servers()
@ -49,6 +50,6 @@ class HealthcheckMiddlewareTest(functional.FunctionalTest):
response, content = self.request()
self.assertEqual('DISABLED BY FILE', content)
self.assertEqual(503, response.status)
self.assertEqual(http_client.SERVICE_UNAVAILABLE, response.status)
self.stop_servers()

View File

@ -19,6 +19,7 @@ import os
import stat
import httplib2
from six.moves import http_client as http
from glance.tests import functional
@ -89,7 +90,7 @@ class TestLogging(functional.FunctionalTest):
path = "http://%s:%d/" % ("127.0.0.1", self.api_port)
response, content = httplib2.Http().request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(http.MULTIPLE_CHOICES, response.status)
self.assertNotEmptyFile(self.api_server.log_file)

View File

@ -19,6 +19,7 @@ import time
import psutil
import requests
from six.moves import http_client as http
from glance.tests import functional
from glance.tests.utils import execute
@ -143,7 +144,7 @@ class TestReload(functional.FunctionalTest):
# This recycles the existing socket
path = self._url('http', '/')
response = requests.get(path)
self.assertEqual(300, response.status_code)
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
del response # close socket so that process audit is reliable
pre_pids['api'] = self._get_children('api')
@ -163,7 +164,7 @@ class TestReload(functional.FunctionalTest):
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
path = self._url('https', '/')
response = requests.get(path, verify=ca_file)
self.assertEqual(300, response.status_code)
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
del response
# Test https restart
@ -181,7 +182,7 @@ class TestReload(functional.FunctionalTest):
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
path = self._url('https', '/')
response = requests.get(path, verify=ca_file)
self.assertEqual(300, response.status_code)
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
del response
# Test changing the https bind_host
@ -199,7 +200,7 @@ class TestReload(functional.FunctionalTest):
path = self._url('https', '/')
response = requests.get(path, verify=ca_file)
self.assertEqual(300, response.status_code)
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
del response
# Test https -> http
@ -218,7 +219,7 @@ class TestReload(functional.FunctionalTest):
path = self._url('http', '/')
response = requests.get(path)
self.assertEqual(300, response.status_code)
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
del response
# Test changing the http bind_host
@ -236,7 +237,7 @@ class TestReload(functional.FunctionalTest):
path = self._url('http', '/')
response = requests.get(path)
self.assertEqual(300, response.status_code)
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
del response
# Test logging configuration change

View File

@ -20,6 +20,7 @@ import time
import httplib2
from oslo_serialization import jsonutils
from oslo_utils import units
from six.moves import http_client
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
@ -60,16 +61,16 @@ class TestScrubber(functional.FunctionalTest):
metadata_encryption_key='')
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
response, content = self._send_http_request(path, 'POST', body='XXX')
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('active', image['status'])
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
image['id'])
response, content = self._send_http_request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
response, content = self._send_http_request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('pending_delete', response['x-image-meta-status'])
self.wait_for_scrub(path)
@ -106,7 +107,7 @@ class TestScrubber(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', body='XXX',
headers=headers)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('active', image['status'])
image_id = image['id']
@ -115,10 +116,10 @@ class TestScrubber(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE', headers=base_headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
response, content = http.request(path, 'HEAD', headers=base_headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('pending_delete', response['x-image-meta-status'])
self.wait_for_scrub(path, headers=base_headers)
@ -136,17 +137,17 @@ class TestScrubber(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
response, content = self._send_http_request(path, 'POST', body='XXX')
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('active', image['status'])
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
image['id'])
response, content = self._send_http_request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
response, content = self._send_http_request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('pending_delete', response['x-image-meta-status'])
# wait for the scrub time on the image to pass
@ -193,7 +194,7 @@ class TestScrubber(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', body='XXX',
headers=headers)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('active', image['status'])
image_id = image['id']
@ -202,10 +203,10 @@ class TestScrubber(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE', headers=base_headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
response, content = http.request(path, 'HEAD', headers=base_headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('pending_delete', response['x-image-meta-status'])
# wait for the scrub time on the image to pass
@ -240,7 +241,7 @@ class TestScrubber(functional.FunctionalTest):
# add an image
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
response, content = self._send_http_request(path, 'POST', body='XXX')
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('active', image['status'])
@ -248,11 +249,11 @@ class TestScrubber(functional.FunctionalTest):
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
image['id'])
response, content = self._send_http_request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# ensure the image is marked pending delete
response, content = self._send_http_request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('pending_delete', response['x-image-meta-status'])
# Remove the file from the backend.

View File

@ -16,6 +16,7 @@
import os
import httplib2
from six.moves import http_client as http
from glance.tests import functional
@ -79,4 +80,4 @@ class TestSSL(functional.FunctionalTest):
path = "https://%s:%d/versions" % ("127.0.0.1", self.api_port)
https = httplib2.Http(ca_certs=self.ca_file)
response, content = https.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http.OK, response.status)

View File

@ -22,6 +22,7 @@ import sys
from oslo_serialization import jsonutils
from oslo_utils import units
from six.moves import http_client
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
@ -37,7 +38,7 @@ class TestApi(functional.FunctionalTest):
"""Functional tests using httplib2 against the API server"""
def _check_image_create(self, headers, status=201,
def _check_image_create(self, headers, status=http_client.CREATED,
image_data="*" * FIVE_KB):
# performs image_create request, checks the response and returns
# content
@ -56,7 +57,7 @@ class TestApi(functional.FunctionalTest):
# checksum can be no longer that 32 characters (String(32))
headers['X-Image-Meta-Checksum'] = 'x' * 42
content = self._check_image_create(headers, 400)
content = self._check_image_create(headers, http_client.BAD_REQUEST)
self.assertIn("Invalid checksum", content)
# test positive case as well
headers['X-Image-Meta-Checksum'] = hashlib.md5(image_data).hexdigest()
@ -71,11 +72,13 @@ class TestApi(functional.FunctionalTest):
headers = minimal_headers('Image1')
# check that long numbers result in 400
headers['X-Image-Meta-%s' % param] = str(sys.maxint + 1)
content = self._check_image_create(headers, 400)
content = self._check_image_create(headers,
http_client.BAD_REQUEST)
self.assertIn("'%s' value out of range" % param, content)
# check that integers over 4 byte result in 400
headers['X-Image-Meta-%s' % param] = str(2 ** 31)
content = self._check_image_create(headers, 400)
content = self._check_image_create(headers,
http_client.BAD_REQUEST)
self.assertIn("'%s' value out of range" % param, content)
# verify positive case as well
headers['X-Image-Meta-%s' % param] = str((2 ** 31) - 1)
@ -165,7 +168,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('{"images": []}', content)
# 1. GET /images/detail
@ -173,7 +176,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('{"images": []}', content)
# 2. POST /images with public image named Image1
@ -184,7 +187,7 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
image_id = data['image']['id']
self.assertEqual(hashlib.md5(image_data).hexdigest(),
@ -199,7 +202,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual("Image1", response['x-image-meta-name'])
# 4. GET image
@ -208,7 +211,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
expected_image_headers = {
'x-image-meta-id': image_id,
@ -246,7 +249,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
expected_result = {"images": [
{"container_format": "ovf",
@ -262,7 +265,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
expected_image = {
"status": "active",
@ -293,7 +296,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'PUT', headers=headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertEqual("x86_64", data['image']['properties']['arch'])
self.assertEqual("Ubuntu", data['image']['properties']['distro'])
@ -307,14 +310,15 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'PUT', headers=headers)
self.assertEqual(413, response.status)
self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE,
response.status)
# 9. GET /images/detail
# Verify image and all its metadata
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
expected_image = {
"status": "active",
@ -343,11 +347,11 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'PUT', headers=headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)['images'][0]
self.assertEqual(1, len(data['properties']))
self.assertEqual("x86_64", data['properties']['arch'])
@ -359,12 +363,12 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'PUT', headers=headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)['images'][0]
self.assertEqual(2, len(data['properties']))
self.assertEqual("x86_64", data['properties']['arch'])
@ -376,21 +380,21 @@ class TestApi(functional.FunctionalTest):
("127.0.0.1", self.api_port, image_id))
http = httplib2.Http()
response, content = http.request(path, 'PUT')
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
# 13. Add member to image
path = ("http://%s:%d/v1/images/%s/members/pattiewhite" %
("127.0.0.1", self.api_port, image_id))
http = httplib2.Http()
response, content = http.request(path, 'PUT')
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
# 14. List image members
path = ("http://%s:%d/v1/images/%s/members" %
("127.0.0.1", self.api_port, image_id))
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
data = jsonutils.loads(content)
self.assertEqual(2, len(data['members']))
self.assertEqual('pattieblack', data['members'][0]['member_id'])
@ -401,7 +405,7 @@ class TestApi(functional.FunctionalTest):
("127.0.0.1", self.api_port, image_id))
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
# 16. Attempt to replace members with an overlimit amount
# Adding 11 image members should fail since configured limit is 10
@ -414,7 +418,8 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
body = jsonutils.dumps(dict(memberships=memberships))
response, content = http.request(path, 'PUT', body=body)
self.assertEqual(413, response.status)
self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE,
response.status)
# 17. Attempt to add a member while at limit
# Adding an 11th member should fail since configured limit is 10
@ -427,13 +432,14 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
body = jsonutils.dumps(dict(memberships=memberships))
response, content = http.request(path, 'PUT', body=body)
self.assertEqual(204, response.status)
self.assertEqual(http_client.NO_CONTENT, response.status)
path = ("http://%s:%d/v1/images/%s/members/fail_me" %
("127.0.0.1", self.api_port, image_id))
http = httplib2.Http()
response, content = http.request(path, 'PUT')
self.assertEqual(413, response.status)
self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE,
response.status)
# 18. POST /images with another public image named Image2
# attribute and three custom properties, "distro", "arch" & "foo".
@ -447,7 +453,7 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
image2_id = data['image']['id']
self.assertEqual(hashlib.md5(image_data).hexdigest(),
@ -465,7 +471,7 @@ class TestApi(functional.FunctionalTest):
image2_id)
http = httplib2.Http()
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual("Image2", response['x-image-meta-name'])
# 20. GET /images
@ -473,7 +479,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
images = jsonutils.loads(content)['images']
self.assertEqual(2, len(images))
self.assertEqual(image2_id, images[0]['id'])
@ -485,7 +491,7 @@ class TestApi(functional.FunctionalTest):
"127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
images = jsonutils.loads(content)['images']
self.assertEqual(2, len(images))
self.assertEqual(image2_id, images[0]['id'])
@ -497,7 +503,7 @@ class TestApi(functional.FunctionalTest):
"127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
images = jsonutils.loads(content)['images']
self.assertEqual(0, len(images))
@ -507,7 +513,7 @@ class TestApi(functional.FunctionalTest):
self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
images = jsonutils.loads(content)['images']
self.assertEqual(0, len(images))
@ -517,7 +523,7 @@ class TestApi(functional.FunctionalTest):
self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
images = jsonutils.loads(content)['images']
self.assertEqual(1, len(images))
self.assertEqual(image2_id, images[0]['id'])
@ -528,7 +534,7 @@ class TestApi(functional.FunctionalTest):
self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
images = jsonutils.loads(content)['images']
self.assertEqual(1, len(images))
self.assertEqual(image_id, images[0]['id'])
@ -539,7 +545,7 @@ class TestApi(functional.FunctionalTest):
self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
images = jsonutils.loads(content)['images']
self.assertEqual(1, len(images))
self.assertEqual(image2_id, images[0]['id'])
@ -549,14 +555,14 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# 28. Try to list members of deleted image
path = ("http://%s:%d/v1/images/%s/members" %
("127.0.0.1", self.api_port, image_id))
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(404, response.status)
self.assertEqual(http_client.NOT_FOUND, response.status)
# 29. Try to update member of deleted image
path = ("http://%s:%d/v1/images/%s/members" %
@ -565,35 +571,35 @@ class TestApi(functional.FunctionalTest):
fixture = [{'member_id': 'pattieblack', 'can_share': 'false'}]
body = jsonutils.dumps(dict(memberships=fixture))
response, content = http.request(path, 'PUT', body=body)
self.assertEqual(404, response.status)
self.assertEqual(http_client.NOT_FOUND, response.status)
# 30. Try to add member to deleted image
path = ("http://%s:%d/v1/images/%s/members/chickenpattie" %
("127.0.0.1", self.api_port, image_id))
http = httplib2.Http()
response, content = http.request(path, 'PUT')
self.assertEqual(404, response.status)
self.assertEqual(http_client.NOT_FOUND, response.status)
# 31. Try to delete member of deleted image
path = ("http://%s:%d/v1/images/%s/members/pattieblack" %
("127.0.0.1", self.api_port, image_id))
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(404, response.status)
self.assertEqual(http_client.NOT_FOUND, response.status)
# 32. DELETE image2
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
image2_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# 33. GET /images
# Verify no images are listed
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
images = jsonutils.loads(content)['images']
self.assertEqual(0, len(images))
@ -601,7 +607,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'HEAD')
self.assertEqual(405, response.status)
self.assertEqual(http_client.METHOD_NOT_ALLOWED, response.status)
self.assertEqual('GET', response.get('allow'))
self.stop_servers()
@ -633,7 +639,7 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
image_id = data['image']['id']
self.assertEqual(hashlib.md5(image_data).hexdigest(),
@ -648,7 +654,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual("Image1", response['x-image-meta-name'])
# 2. GET /images
@ -656,7 +662,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
expected_result = {"images": [
{"container_format": "ovf",
@ -672,7 +678,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# 4. GET image
# Verify that 403 HTTPForbidden exception is raised prior to
@ -683,7 +689,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
self.stop_servers()
@ -712,7 +718,7 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
image_id = data['image']['id']
self.assertEqual(hashlib.md5(image_data).hexdigest(),
@ -727,7 +733,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual("Image1", response['x-image-meta-name'])
# 2. GET /images
@ -735,7 +741,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
expected_result = {"images": [
{"container_format": "ovf",
@ -751,7 +757,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# 4. GET image
# Verify that 404 HTTPNotFound exception is raised
@ -759,7 +765,7 @@ class TestApi(functional.FunctionalTest):
image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(404, response.status)
self.assertEqual(http_client.NOT_FOUND, response.status)
self.stop_servers()
@ -776,7 +782,7 @@ class TestApi(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
response, content = http.request(path, 'POST', headers=headers,
body=None)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('queued', image['status'])
@ -786,18 +792,18 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
headers = {'X-Image-Meta-Status': 'active'}
response, content = http.request(path, 'PUT', headers=headers)
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('queued', response['x-image-meta-status'])
# We allow 'setting' to the same status
http = httplib2.Http()
headers = {'X-Image-Meta-Status': 'queued'}
response, content = http.request(path, 'PUT', headers=headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('queued', response['x-image-meta-status'])
# Make image active
@ -805,7 +811,7 @@ class TestApi(functional.FunctionalTest):
headers = {'Content-Type': 'application/octet-stream'}
response, content = http.request(path, 'PUT', headers=headers,
body='data')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('active', image['status'])
@ -813,18 +819,18 @@ class TestApi(functional.FunctionalTest):
http = httplib2.Http()
headers = {'X-Image-Meta-Status': 'queued'}
response, content = http.request(path, 'PUT', headers=headers)
self.assertEqual(403, response.status)
self.assertEqual(http_client.FORBIDDEN, response.status)
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('active', response['x-image-meta-status'])
# We allow 'setting' to the same status
http = httplib2.Http()
headers = {'X-Image-Meta-Status': 'active'}
response, content = http.request(path, 'PUT', headers=headers)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('active', response['x-image-meta-status'])
# Create a 'queued' image, ensure 'status' header is ignored
@ -834,7 +840,7 @@ class TestApi(functional.FunctionalTest):
'X-Image-Meta-Status': 'active'}
response, content = http.request(path, 'POST', headers=headers,
body=None)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('queued', image['status'])
@ -847,7 +853,7 @@ class TestApi(functional.FunctionalTest):
'X-Image-Meta-Container-Format': 'bare'}
response, content = http.request(path, 'POST', headers=headers,
body='data')
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
image = jsonutils.loads(content)['image']
self.assertEqual('active', image['status'])
self.stop_servers()

View File

@ -26,6 +26,7 @@ import time
import httplib2
from oslo_serialization import jsonutils
from oslo_utils import units
from six.moves import http_client
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
@ -66,7 +67,7 @@ class TestCopyToFile(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status, content)
self.assertEqual(http_client.CREATED, response.status, content)
data = jsonutils.loads(content)
original_image_id = data['image']['id']
@ -82,7 +83,7 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(201, response.status, content)
self.assertEqual(http_client.CREATED, response.status, content)
data = jsonutils.loads(content)
copy_image_id = data['image']['id']
@ -97,7 +98,7 @@ class TestCopyToFile(functional.FunctionalTest):
time.sleep(0.01)
http = httplib2.Http()
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
if response['x-image-meta-status'] == expected_status:
return
self.fail('unexpected image status %s' %
@ -106,7 +107,7 @@ class TestCopyToFile(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(str(FIVE_KB), response['content-length'])
self.assertEqual("*" * FIVE_KB, content)
@ -120,7 +121,7 @@ class TestCopyToFile(functional.FunctionalTest):
original_image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# GET image again to make sure the existence of the original
# image in from_store is not depended on
@ -128,7 +129,7 @@ class TestCopyToFile(functional.FunctionalTest):
copy_image_id)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(str(FIVE_KB), response['content-length'])
self.assertEqual("*" * FIVE_KB, content)
@ -142,7 +143,7 @@ class TestCopyToFile(functional.FunctionalTest):
copy_image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.stop_servers()
@ -173,7 +174,7 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(201, response.status, content)
self.assertEqual(http_client.CREATED, response.status, content)
data = jsonutils.loads(content)
copy_image_id = data['image']['id']
@ -187,7 +188,7 @@ class TestCopyToFile(functional.FunctionalTest):
time.sleep(0.01)
http = httplib2.Http()
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
if response['x-image-meta-status'] == expected_status:
return
self.fail('unexpected image status %s' %
@ -198,7 +199,7 @@ class TestCopyToFile(functional.FunctionalTest):
# GET image and make sure image content is as expected
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(str(FIVE_KB), response['content-length'])
self.assertEqual("*" * FIVE_KB, content)
@ -208,7 +209,7 @@ class TestCopyToFile(functional.FunctionalTest):
# DELETE copied image
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.stop_servers()
@ -234,7 +235,7 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(404, response.status, content)
self.assertEqual(http_client.NOT_FOUND, response.status, content)
expected = 'HTTP datastore could not find image at URI.'
self.assertIn(expected, content)
@ -264,7 +265,7 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(400, response.status, content)
self.assertEqual(http_client.BAD_REQUEST, response.status, content)
expected = 'External sources are not supported: \'%s\'' % copy_from
msg = 'expected "%s" in "%s"' % (expected, content)
@ -290,7 +291,7 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(400, response.status, content)
self.assertEqual(http_client.BAD_REQUEST, response.status, content)
expected = 'External sources are not supported: \'swift+config://xxx\''
msg = 'expected "%s" in "%s"' % (expected, content)

View File

@ -18,6 +18,7 @@ import os
import httplib2
from oslo_serialization import jsonutils
from oslo_utils import units
from six.moves import http_client
from glance.tests import functional
from glance.tests.utils import minimal_headers
@ -57,7 +58,7 @@ class TestMiscellaneous(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = jsonutils.loads(content)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
@ -75,7 +76,7 @@ class TestMiscellaneous(functional.FunctionalTest):
data['image']['id'])
http = httplib2.Http()
response, content = http.request(path, 'HEAD')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual("Image1", response['x-image-meta-name'])
# 4. GET /images/1
@ -83,7 +84,7 @@ class TestMiscellaneous(functional.FunctionalTest):
path = "http://%s:%d/v1/images/1" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(404, response.status)
self.assertEqual(http_client.NOT_FOUND, response.status)
self.stop_servers()
@ -106,7 +107,7 @@ class TestMiscellaneous(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual('{"images": []}', content)
headers = {'Content-Type': 'application/octet-stream',

View File

@ -17,6 +17,7 @@ import time
import httplib2
import psutil
from six.moves import http_client
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
@ -39,7 +40,7 @@ class TestMultiprocessing(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(b'{"images": []}', content)
self.stop_servers()

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,7 @@ import uuid
from oslo_serialization import jsonutils
import requests
from six.moves import http_client as http
from glance.tests import functional
@ -50,7 +51,7 @@ class TestNamespaces(functional.FunctionalTest):
# Namespace should not exist
path = self._url('/v2/metadefs/namespaces/MyNamespace')
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create a namespace
path = self._url('/v2/metadefs/namespaces')
@ -63,7 +64,7 @@ class TestNamespaces(functional.FunctionalTest):
}
)
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
namespace_loc_header = response.headers['Location']
# Returned namespace should match the created namespace with default
@ -98,11 +99,11 @@ class TestNamespaces(functional.FunctionalTest):
# Attempt to insert a duplicate
response = requests.post(path, headers=headers, data=data)
self.assertEqual(409, response.status_code)
self.assertEqual(http.CONFLICT, response.status_code)
# Get the namespace using the returned Location header
response = requests.get(namespace_loc_header, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
namespace = jsonutils.loads(response.text)
self.assertEqual(namespace_name, namespace['namespace'])
self.assertNotIn('object', namespace)
@ -126,7 +127,7 @@ class TestNamespaces(functional.FunctionalTest):
}
)
response = requests.put(path, headers=headers, data=data)
self.assertEqual(200, response.status_code, response.text)
self.assertEqual(http.OK, response.status_code, response.text)
# Returned namespace should reflect the changes
namespace = jsonutils.loads(response.text)
@ -140,7 +141,7 @@ class TestNamespaces(functional.FunctionalTest):
# Updates should persist across requests
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
namespace = jsonutils.loads(response.text)
self.assertEqual('MyNamespace-UPDATED', namespace['namespace'])
self.assertEqual('display_name-UPDATED', namespace['display_name'])
@ -152,7 +153,7 @@ class TestNamespaces(functional.FunctionalTest):
# Deletion should not work on protected namespaces
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
response = requests.delete(path, headers=self._headers())
self.assertEqual(403, response.status_code)
self.assertEqual(http.FORBIDDEN, response.status_code)
# Unprotect namespace for deletion
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
@ -168,23 +169,23 @@ class TestNamespaces(functional.FunctionalTest):
}
data = jsonutils.dumps(doc)
response = requests.put(path, headers=headers, data=data)
self.assertEqual(200, response.status_code, response.text)
self.assertEqual(http.OK, response.status_code, response.text)
# Deletion should work. Deleting namespace MyNamespace
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
response = requests.delete(path, headers=self._headers())
self.assertEqual(204, response.status_code)
self.assertEqual(http.NO_CONTENT, response.status_code)
# Namespace should not exist
path = self._url('/v2/metadefs/namespaces/MyNamespace')
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
def test_metadef_dont_accept_illegal_bodies(self):
# Namespace should not exist
path = self._url('/v2/metadefs/namespaces/bodytest')
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create a namespace
path = self._url('/v2/metadefs/namespaces')
@ -197,7 +198,7 @@ class TestNamespaces(functional.FunctionalTest):
}
)
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# Test all the urls that supply data
data_urls = [
@ -217,7 +218,7 @@ class TestNamespaces(functional.FunctionalTest):
path = self._url(value)
data = jsonutils.dumps(["body"])
response = requests.get(path, headers=self._headers(), data=data)
self.assertEqual(400, response.status_code)
self.assertEqual(http.BAD_REQUEST, response.status_code)
# Put the namespace into the url
test_urls = [
@ -238,4 +239,4 @@ class TestNamespaces(functional.FunctionalTest):
data = jsonutils.dumps(["body"])
response = getattr(requests, method)(
path, headers=self._headers(), data=data)
self.assertEqual(400, response.status_code)
self.assertEqual(http.BAD_REQUEST, response.status_code)

View File

@ -17,6 +17,7 @@ import uuid
from oslo_serialization import jsonutils
import requests
from six.moves import http_client as http
from glance.tests import functional
@ -49,7 +50,7 @@ class TestMetadefObjects(functional.FunctionalTest):
# Namespace should not exist
path = self._url('/v2/metadefs/namespaces/MyNamespace')
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create a namespace
path = self._url('/v2/metadefs/namespaces')
@ -65,12 +66,12 @@ class TestMetadefObjects(functional.FunctionalTest):
}
)
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# Metadata objects should not exist
path = self._url('/v2/metadefs/namespaces/MyNamespace/objects/object1')
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create a object
path = self._url('/v2/metadefs/namespaces/MyNamespace/objects')
@ -105,18 +106,18 @@ class TestMetadefObjects(functional.FunctionalTest):
}
)
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# Attempt to insert a duplicate
response = requests.post(path, headers=headers, data=data)
self.assertEqual(409, response.status_code)
self.assertEqual(http.CONFLICT, response.status_code)
# Get the metadata object created above
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
(namespace_name, metadata_object_name))
response = requests.get(path,
headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
metadata_object = jsonutils.loads(response.text)
self.assertEqual("object1", metadata_object['name'])
@ -216,7 +217,7 @@ class TestMetadefObjects(functional.FunctionalTest):
}
)
response = requests.put(path, headers=headers, data=data)
self.assertEqual(200, response.status_code, response.text)
self.assertEqual(http.OK, response.status_code, response.text)
# Returned metadata_object should reflect the changes
metadata_object = jsonutils.loads(response.text)
@ -263,10 +264,10 @@ class TestMetadefObjects(functional.FunctionalTest):
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
(namespace_name, metadata_object_name))
response = requests.delete(path, headers=self._headers())
self.assertEqual(204, response.status_code)
self.assertEqual(http.NO_CONTENT, response.status_code)
# metadata_object object1 should not exist
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
(namespace_name, metadata_object_name))
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)

View File

@ -17,6 +17,7 @@ import uuid
from oslo_serialization import jsonutils
import requests
from six.moves import http_client as http
from glance.tests import functional
@ -49,7 +50,7 @@ class TestNamespaceProperties(functional.FunctionalTest):
# Namespace should not exist
path = self._url('/v2/metadefs/namespaces/MyNamespace')
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create a namespace
path = self._url('/v2/metadefs/namespaces')
@ -72,13 +73,13 @@ class TestNamespaceProperties(functional.FunctionalTest):
]
})
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# Property1 should not exist
path = self._url('/v2/metadefs/namespaces/MyNamespace/properties'
'/property1')
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create a property
path = self._url('/v2/metadefs/namespaces/MyNamespace/properties')
@ -97,17 +98,17 @@ class TestNamespaceProperties(functional.FunctionalTest):
}
)
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# Attempt to insert a duplicate
response = requests.post(path, headers=headers, data=data)
self.assertEqual(409, response.status_code)
self.assertEqual(http.CONFLICT, response.status_code)
# Get the property created above
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
(namespace_name, property_name))
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
property_object = jsonutils.loads(response.text)
self.assertEqual("integer", property_object['type'])
self.assertEqual("property1", property_object['title'])
@ -122,7 +123,7 @@ class TestNamespaceProperties(functional.FunctionalTest):
namespace_name, property_name, '='.join(['?resource_type',
resource_type_name])))
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Get the property with prefix and specific resource type association
property_name_with_prefix = ''.join([resource_type_prefix,
@ -131,7 +132,7 @@ class TestNamespaceProperties(functional.FunctionalTest):
namespace_name, property_name_with_prefix, '='.join([
'?resource_type', resource_type_name])))
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
property_object = jsonutils.loads(response.text)
self.assertEqual("integer", property_object['type'])
self.assertEqual("property1", property_object['title'])
@ -188,7 +189,7 @@ class TestNamespaceProperties(functional.FunctionalTest):
}
)
response = requests.put(path, headers=headers, data=data)
self.assertEqual(200, response.status_code, response.text)
self.assertEqual(http.OK, response.status_code, response.text)
# Returned property should reflect the changes
property_object = jsonutils.loads(response.text)
@ -215,10 +216,10 @@ class TestNamespaceProperties(functional.FunctionalTest):
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
(namespace_name, property_name))
response = requests.delete(path, headers=self._headers())
self.assertEqual(204, response.status_code)
self.assertEqual(http.NO_CONTENT, response.status_code)
# property1 should not exist
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
(namespace_name, property_name))
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)

View File

@ -17,6 +17,7 @@ from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import encodeutils
import six
from six.moves import http_client as http
import webob.exc
from wsme.rest import json
@ -183,13 +184,13 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
def create(self, response, result):
resource_type_json = json.tojson(ResourceTypeAssociation, result)
response.status_int = 201
response.status_int = http.CREATED
body = jsonutils.dumps(resource_type_json, ensure_ascii=False)
response.unicode_body = six.text_type(body)
response.content_type = 'application/json'
def delete(self, response, result):
response.status_int = 204
response.status_int = http.NO_CONTENT
def _get_base_properties():

View File

@ -17,6 +17,7 @@ import uuid
from oslo_serialization import jsonutils
import requests
from six.moves import http_client as http
from glance.tests import functional
@ -49,7 +50,7 @@ class TestMetadefTags(functional.FunctionalTest):
# Namespace should not exist
path = self._url('/v2/metadefs/namespaces/MyNamespace')
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create a namespace
path = self._url('/v2/metadefs/namespaces')
@ -64,24 +65,24 @@ class TestMetadefTags(functional.FunctionalTest):
"owner": "The Test Owner"}
)
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# Metadata tag should not exist
metadata_tag_name = "tag1"
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
(namespace_name, metadata_tag_name))
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create the metadata tag
headers = self._headers({'content-type': 'application/json'})
response = requests.post(path, headers=headers)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# Get the metadata tag created above
response = requests.get(path,
headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
metadata_tag = jsonutils.loads(response.text)
self.assertEqual(metadata_tag_name, metadata_tag['name'])
@ -108,7 +109,7 @@ class TestMetadefTags(functional.FunctionalTest):
# Try to create a duplicate metadata tag
headers = self._headers({'content-type': 'application/json'})
response = requests.post(path, headers=headers)
self.assertEqual(409, response.status_code)
self.assertEqual(http.CONFLICT, response.status_code)
# The metadata_tag should be mutable
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
@ -122,7 +123,7 @@ class TestMetadefTags(functional.FunctionalTest):
}
)
response = requests.put(path, headers=headers, data=data)
self.assertEqual(200, response.status_code, response.text)
self.assertEqual(http.OK, response.status_code, response.text)
# Returned metadata_tag should reflect the changes
metadata_tag = jsonutils.loads(response.text)
@ -132,20 +133,20 @@ class TestMetadefTags(functional.FunctionalTest):
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
(namespace_name, metadata_tag_name))
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
self.assertEqual('tag1-UPDATED', metadata_tag['name'])
# Deletion of metadata_tag_name
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
(namespace_name, metadata_tag_name))
response = requests.delete(path, headers=self._headers())
self.assertEqual(204, response.status_code)
self.assertEqual(http.NO_CONTENT, response.status_code)
# metadata_tag_name should not exist
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
(namespace_name, metadata_tag_name))
response = requests.get(path, headers=self._headers())
self.assertEqual(404, response.status_code)
self.assertEqual(http.NOT_FOUND, response.status_code)
# Create multiple tags.
path = self._url('/v2/metadefs/namespaces/%s/tags' %
@ -155,11 +156,11 @@ class TestMetadefTags(functional.FunctionalTest):
{"tags": [{"name": "tag1"}, {"name": "tag2"}, {"name": "tag3"}]}
)
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# List out the three new tags.
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
tags = jsonutils.loads(response.text)['tags']
self.assertEqual(3, len(tags))
@ -168,10 +169,10 @@ class TestMetadefTags(functional.FunctionalTest):
{"tags": [{"name": "tag4"}, {"name": "tag5"}, {"name": "tag4"}]}
)
response = requests.post(path, headers=headers, data=data)
self.assertEqual(409, response.status_code)
self.assertEqual(http.CONFLICT, response.status_code)
# Verify the previous 3 still exist
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
tags = jsonutils.loads(response.text)['tags']
self.assertEqual(3, len(tags))

View File

@ -15,6 +15,7 @@
from oslo_serialization import jsonutils
import requests
from six.moves import http_client as http
from glance.tests import functional
@ -30,7 +31,7 @@ class TestSchemas(functional.FunctionalTest):
# Ensure the image link works and custom properties are loaded
path = 'http://%s:%d/v2/schemas/image' % ('127.0.0.1', self.api_port)
response = requests.get(path)
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
image_schema = jsonutils.loads(response.text)
expected = set([
'id',
@ -60,7 +61,7 @@ class TestSchemas(functional.FunctionalTest):
# Ensure the images link works and agrees with the image schema
path = 'http://%s:%d/v2/schemas/images' % ('127.0.0.1', self.api_port)
response = requests.get(path)
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
images_schema = jsonutils.loads(response.text)
item_schema = images_schema['properties']['images']['items']
self.assertEqual(item_schema, image_schema)

View File

@ -18,6 +18,7 @@ import uuid
from oslo_serialization import jsonutils
import requests
from six.moves import http_client as http
from glance.tests import functional
@ -55,14 +56,14 @@ class TestTasks(functional.FunctionalTest):
# Task list should be empty
path = self._url('/v2/tasks')
response = requests.get(path, headers=self._headers(roles))
self.assertEqual(403, response.status_code)
self.assertEqual(http.FORBIDDEN, response.status_code)
def test_task_lifecycle(self):
self.start_servers(**self.__dict__.copy())
# Task list should be empty
path = self._url('/v2/tasks')
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
tasks = jsonutils.loads(response.text)['tasks']
self.assertEqual(0, len(tasks))
@ -82,7 +83,7 @@ class TestTasks(functional.FunctionalTest):
}
})
response = requests.post(path, headers=headers, data=data)
self.assertEqual(201, response.status_code)
self.assertEqual(http.CREATED, response.status_code)
# Returned task entity should have a generated id and status
task = jsonutils.loads(response.text)
@ -121,7 +122,7 @@ class TestTasks(functional.FunctionalTest):
# Tasks list should now have one entry
path = self._url('/v2/tasks')
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
self.assertEqual(http.OK, response.status_code)
tasks = jsonutils.loads(response.text)['tasks']
self.assertEqual(1, len(tasks))
self.assertEqual(task_id, tasks[0]['id'])
@ -129,7 +130,7 @@ class TestTasks(functional.FunctionalTest):
# Attempt to delete a task
path = self._url('/v2/tasks/%s' % tasks[0]['id'])
response = requests.delete(path, headers=self._headers())
self.assertEqual(405, response.status_code)
self.assertEqual(http.METHOD_NOT_ALLOWED, response.status_code)
self.assertIsNotNone(response.headers.get('Allow'))
self.assertEqual('GET', response.headers.get('Allow'))

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,7 @@
from oslo_config import cfg
from oslo_serialization import jsonutils
from six.moves import http_client
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
@ -43,7 +44,7 @@ class TestPropertyQuotaViolations(base.ApiTest):
def _get(self, image_id=""):
path = ('/v2/images/%s' % image_id).rstrip('/')
rsp, content = self.http.request(path, 'GET', headers=self._headers())
self.assertEqual(200, rsp.status)
self.assertEqual(http_client.OK, rsp.status)
content = jsonutils.loads(content)
return content
@ -52,7 +53,7 @@ class TestPropertyQuotaViolations(base.ApiTest):
headers = self._headers({'content-type': 'application/json'})
rsp, content = self.http.request(path, 'POST', headers=headers,
body=jsonutils.dumps(body))
self.assertEqual(201, rsp.status)
self.assertEqual(http_client.CREATED, rsp.status)
return jsonutils.loads(content)
def _patch(self, image_id, body, expected_status):
@ -91,15 +92,17 @@ class TestPropertyQuotaViolations(base.ApiTest):
self.config(image_property_quota=2)
patch_body = [{'op': 'replace', 'path': '/k_4', 'value': 'v_4.new'}]
image = jsonutils.loads(self._patch(image_id, patch_body, 200))
image = jsonutils.loads(self._patch(image_id, patch_body,
http_client.OK))
self.assertEqual('v_4.new', image['k_4'])
patch_body = [{'op': 'remove', 'path': '/k_7'}]
image = jsonutils.loads(self._patch(image_id, patch_body, 200))
image = jsonutils.loads(self._patch(image_id, patch_body,
http_client.OK))
self.assertNotIn('k_7', image)
patch_body = [{'op': 'add', 'path': '/k_100', 'value': 'v_100'}]
self._patch(image_id, patch_body, 413)
self._patch(image_id, patch_body, http_client.REQUEST_ENTITY_TOO_LARGE)
image = self._get(image_id)
self.assertNotIn('k_100', image)
@ -107,7 +110,7 @@ class TestPropertyQuotaViolations(base.ApiTest):
{'op': 'remove', 'path': '/k_5'},
{'op': 'add', 'path': '/k_100', 'value': 'v_100'},
]
self._patch(image_id, patch_body, 413)
self._patch(image_id, patch_body, http_client.REQUEST_ENTITY_TOO_LARGE)
image = self._get(image_id)
self.assertNotIn('k_100', image)
self.assertIn('k_5', image)
@ -119,7 +122,8 @@ class TestPropertyQuotaViolations(base.ApiTest):
{'op': 'add', 'path': '/k_99', 'value': 'v_99'}]
to_rm = ['k_%d' % i for i in range(orig_property_quota) if i != 7]
patch_body.extend([{'op': 'remove', 'path': '/%s' % k} for k in to_rm])
image = jsonutils.loads(self._patch(image_id, patch_body, 200))
image = jsonutils.loads(self._patch(image_id, patch_body,
http_client.OK))
self.assertEqual('v_99', image['k_99'])
self.assertEqual('v_100', image['k_100'])
for k in to_rm:

View File

@ -15,6 +15,7 @@
import eventlet
from oslo_serialization import jsonutils as json
from six.moves import http_client
from glance.api.v2 import tasks
from glance.common import timeutils
@ -73,7 +74,7 @@ class TestTasksApi(base.ApiTest):
headers=minimal_task_headers())
content_dict = json.loads(content)
self.assertEqual(200, res.status)
self.assertEqual(http_client.OK, res.status)
res_tasks = content_dict['tasks']
if len(res_tasks) != 0:
for task in res_tasks:
@ -104,7 +105,7 @@ class TestTasksApi(base.ApiTest):
headers=headers,
body=body_content)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
task = json.loads(content)
task_id = task['id']
@ -124,7 +125,7 @@ class TestTasksApi(base.ApiTest):
headers=minimal_task_headers())
content_dict = json.loads(content)
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertFalse(content_dict['tasks'])
# 1. GET /tasks/{task_id}
@ -134,7 +135,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(404, response.status)
self.assertEqual(http_client.NOT_FOUND, response.status)
# 2. POST /tasks
# Create a new task
@ -147,7 +148,7 @@ class TestTasksApi(base.ApiTest):
path = "/v2/tasks/%s" % task_id
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
# NOTE(sabari): wait for all task executions to finish before checking
# task status.
@ -159,7 +160,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertIsNotNone(content)
data = json.loads(content)
@ -182,7 +183,7 @@ class TestTasksApi(base.ApiTest):
path = "/v2/schemas/task"
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
schema = tasks.get_task_schema()
expected_schema = schema.minimal()
@ -195,7 +196,7 @@ class TestTasksApi(base.ApiTest):
path = "/v2/schemas/tasks"
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
schema = tasks.get_collection_schema()
expected_schema = schema.minimal()
@ -218,7 +219,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(
path, 'POST', headers=minimal_task_headers(task_owner),
body=body_content)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = json.loads(content)
task_id = data['id']
@ -239,7 +240,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(
path, 'POST', headers=minimal_task_headers(task_owner),
body=body_content)
self.assertEqual(400, response.status)
self.assertEqual(http_client.BAD_REQUEST, response.status)
# 1. POST /tasks
# Create a new task with invalid input for type 'import'
@ -252,7 +253,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(
path, 'POST', headers=minimal_task_headers(task_owner),
body=body_content)
self.assertEqual(400, response.status)
self.assertEqual(http_client.BAD_REQUEST, response.status)
# NOTE(nikhil): wait for all task executions to finish before exiting
# else there is a risk of running into deadlock
@ -266,7 +267,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
content_dict = json.loads(content)
self.assertFalse(content_dict['tasks'])
@ -288,7 +289,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
content_dict = json.loads(content)
self.assertEqual(2, len(content_dict['tasks']))
@ -301,7 +302,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
content_dict = json.loads(content)
self.assertEqual(1, len(content_dict['tasks']))
@ -314,7 +315,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
content_dict = json.loads(content)
self.assertEqual(1, len(content_dict['tasks']))
@ -327,7 +328,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
content_dict = json.loads(content)
self.assertEqual(2, len(content_dict['tasks']))
@ -349,7 +350,7 @@ class TestTasksApi(base.ApiTest):
path = "/v2/tasks"
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
tasks = json.loads(content)
self.assertFalse(tasks['tasks'])
@ -372,7 +373,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
tasks = json.loads(content)['tasks']
@ -385,7 +386,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
actual_tasks = json.loads(content)['tasks']
@ -400,7 +401,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
actual_tasks = json.loads(content)['tasks']
@ -415,7 +416,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
actual_tasks = json.loads(content)['tasks']
@ -432,7 +433,7 @@ class TestTasksApi(base.ApiTest):
path = "/v2/tasks"
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
tasks = json.loads(content)
self.assertFalse(tasks['tasks'])
@ -456,7 +457,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
actual_tasks = json.loads(content)['tasks']
@ -471,7 +472,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
expected_task_owners = [TENANT1, TENANT2, TENANT3]
expected_task_owners.sort()
@ -487,7 +488,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
actual_tasks = json.loads(content)['tasks']
self.assertEqual(2, len(actual_tasks))
@ -503,7 +504,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path, 'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
actual_tasks = json.loads(content)['tasks']
@ -524,7 +525,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(
path, 'POST', headers=minimal_task_headers(task_owner),
body=body_content)
self.assertEqual(201, response.status)
self.assertEqual(http_client.CREATED, response.status)
data = json.loads(content)
task_id = data['id']
@ -535,7 +536,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path,
'DELETE',
headers=minimal_task_headers())
self.assertEqual(405, response.status)
self.assertEqual(http_client.METHOD_NOT_ALLOWED, response.status)
self.assertEqual('GET', response.webob_resp.headers.get('Allow'))
self.assertEqual(('GET',), response.webob_resp.allow)
self.assertEqual(('GET',), response.allow)
@ -546,7 +547,7 @@ class TestTasksApi(base.ApiTest):
response, content = self.http.request(path,
'GET',
headers=minimal_task_headers())
self.assertEqual(200, response.status)
self.assertEqual(http_client.OK, response.status)
self.assertIsNotNone(content)
# NOTE(nikhil): wait for all task executions to finish before exiting

View File

@ -15,6 +15,7 @@
from oslo_utils import encodeutils
import six
from six.moves import http_client as http
from glance.common import exception
from glance.tests import utils as test_utils
@ -38,12 +39,13 @@ class GlanceExceptionTestCase(test_utils.BaseTestCase):
class FakeGlanceException(exception.GlanceException):
message = "default message: %(code)s"
exc = FakeGlanceException(code=500)
exc = FakeGlanceException(code=http.INTERNAL_SERVER_ERROR)
self.assertEqual("default message: 500",
encodeutils.exception_to_unicode(exc))
def test_specified_error_msg_with_kwargs(self):
msg = exception.GlanceException('test: %(code)s', code=500)
msg = exception.GlanceException('test: %(code)s',
code=http.INTERNAL_SERVER_ERROR)
self.assertIn('test: 500', encodeutils.exception_to_unicode(msg))
def test_non_unicode_error_msg(self):

View File

@ -20,6 +20,7 @@ from oslo_serialization import jsonutils
from oslo_utils import encodeutils
import routes
import six
from six.moves import http_client as http
import webob
from glance.common import exception
@ -154,27 +155,27 @@ class TestRPCController(base.IsolatedUnitTest):
# Body is not a list, it should fail
req.body = jsonutils.dump_as_bytes({})
res = req.get_response(api)
self.assertEqual(400, res.status_int)
self.assertEqual(http.BAD_REQUEST, res.status_int)
# cmd is not dict, it should fail.
req.body = jsonutils.dump_as_bytes([None])
res = req.get_response(api)
self.assertEqual(400, res.status_int)
self.assertEqual(http.BAD_REQUEST, res.status_int)
# No command key, it should fail.
req.body = jsonutils.dump_as_bytes([{}])
res = req.get_response(api)
self.assertEqual(400, res.status_int)
self.assertEqual(http.BAD_REQUEST, res.status_int)
# kwargs not dict, it should fail.
req.body = jsonutils.dump_as_bytes([{"command": "test", "kwargs": 2}])
res = req.get_response(api)
self.assertEqual(400, res.status_int)
self.assertEqual(http.BAD_REQUEST, res.status_int)
# Command does not exist, it should fail.
req.body = jsonutils.dump_as_bytes([{"command": "test"}])
res = req.get_response(api)
self.assertEqual(404, res.status_int)
self.assertEqual(http.NOT_FOUND, res.status_int)
def test_rpc_exception_propagation(self):
api = create_api()
@ -184,7 +185,7 @@ class TestRPCController(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes([{"command": "raise_value_error"}])
res = req.get_response(api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
returned = jsonutils.loads(res.body)[0]
err_cls = 'builtins.ValueError' if six.PY3 else 'exceptions.ValueError'
@ -192,7 +193,7 @@ class TestRPCController(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes([{"command": "raise_weird_error"}])
res = req.get_response(api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
returned = jsonutils.loads(res.body)[0]
self.assertEqual('glance.common.exception.RPCError',
@ -281,7 +282,7 @@ class TestRPCJSONSerializer(test_utils.BaseTestCase):
fixture = {"key": "value"}
response = webob.Response()
rpc.RPCJSONSerializer().default(response, fixture)
self.assertEqual(200, response.status_int)
self.assertEqual(http.OK, response.status_int)
content_types = [h for h in response.headerlist
if h[0] == 'Content-Type']
self.assertEqual(1, len(content_types))

View File

@ -27,6 +27,7 @@ from oslo_concurrency import processutils
from oslo_serialization import jsonutils
import routes
import six
from six.moves import http_client as http
import webob
from glance.api.v1 import router as router_v1
@ -188,7 +189,7 @@ class RequestTest(test_utils.BaseTestCase):
req = webob.Request.blank(uri)
req.method = method
res = req.get_response(api)
self.assertEqual(405, res.status_int)
self.assertEqual(http.METHOD_NOT_ALLOWED, res.status_int)
"""Makes sure v2 unallowed methods return 405"""
unallowed_methods = [
@ -217,13 +218,13 @@ class RequestTest(test_utils.BaseTestCase):
req = webob.Request.blank(uri)
req.method = method
res = req.get_response(api)
self.assertEqual(405, res.status_int)
self.assertEqual(http.METHOD_NOT_ALLOWED, res.status_int)
# Makes sure not implemented methods return 405
req = webob.Request.blank('/schemas/image')
req.method = 'NonexistentMethod'
res = req.get_response(api)
self.assertEqual(405, res.status_int)
self.assertEqual(http.METHOD_NOT_ALLOWED, res.status_int)
class ResourceTest(test_utils.BaseTestCase):
@ -317,7 +318,7 @@ class ResourceTest(test_utils.BaseTestCase):
response = resource.__call__(request)
self.assertIsInstance(response, webob.exc.HTTPForbidden)
self.assertEqual(403, response.status_code)
self.assertEqual(http.FORBIDDEN, response.status_code)
def test_call_raises_exception(self):
class FakeController(object):
@ -336,7 +337,7 @@ class ResourceTest(test_utils.BaseTestCase):
response = resource.__call__(request)
self.assertIsInstance(response, webob.exc.HTTPInternalServerError)
self.assertEqual(500, response.status_code)
self.assertEqual(http.INTERNAL_SERVER_ERROR, response.status_code)
@mock.patch.object(wsgi, 'translate_exception')
def test_resource_call_error_handle_localized(self,
@ -433,7 +434,7 @@ class JSONResponseSerializerTest(test_utils.BaseTestCase):
fixture = {"key": "value"}
response = webob.Response()
wsgi.JSONResponseSerializer().default(response, fixture)
self.assertEqual(200, response.status_int)
self.assertEqual(http.OK, response.status_int)
content_types = [h for h in response.headerlist
if h[0] == 'Content-Type']
self.assertEqual(1, len(content_types))

View File

@ -16,6 +16,7 @@
from oslo_serialization import jsonutils
from oslotest import moxstubout
from six.moves import http_client as http
import webob
from glance.api import authorization
@ -196,7 +197,7 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase):
"""
def fake_do_request(*args, **kwargs):
resp = webob.Response()
resp.status = 400
resp.status = http.BAD_REQUEST
return FakeResponse(resp), ""
self.stubs.Set(auth.KeystoneStrategy, '_do_request', fake_do_request)
@ -218,7 +219,7 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase):
"""
def fake_do_request(*args, **kwargs):
resp = webob.Response()
resp.status = 400
resp.status = http.BAD_REQUEST
return FakeResponse(resp), ""
self.stubs.Set(auth.KeystoneStrategy, '_do_request', fake_do_request)
@ -246,9 +247,9 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase):
if (headers.get('X-Auth-User') != 'user1' or
headers.get('X-Auth-Key') != 'pass'):
resp.status = 401
resp.status = http.UNAUTHORIZED
else:
resp.status = 200
resp.status = http.OK
resp.headers.update({"x-image-management-url": "example.com"})
return FakeResponse(resp), ""
@ -334,9 +335,9 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase):
if (username != 'user1' or password != 'pass' or
tenant != 'tenant-ok'):
resp.status = 401
resp.status = http.UNAUTHORIZED
else:
resp.status = 200
resp.status = http.OK
body = mock_token.token
return FakeResponse(resp), jsonutils.dumps(body)

View File

@ -15,6 +15,7 @@
from oslo_policy import policy
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import http_client as http
from six.moves import range
import testtools
import webob
@ -614,7 +615,7 @@ class TestCacheMiddlewareProcessResponse(base.IsolatedUnitTest):
resp = webob.Response(headers=headers)
cache_filter = ProcessRequestTestCacheFilter()
actual = cache_filter.get_status_code(resp)
self.assertEqual(200, actual)
self.assertEqual(http.OK, actual)
def test_process_response(self):
def fake_fetch_request_info(*args, **kwargs):

View File

@ -22,6 +22,7 @@ import mock
from oslo_serialization import jsonutils
import six
from six import moves
from six.moves import http_client as http
import webob
from glance.cmd import replicator as glance_replicator
@ -126,11 +127,12 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
def test_rest_errors(self):
c = glance_replicator.ImageService(FakeHTTPConnection(), 'noauth')
for code, exc in [(400, webob.exc.HTTPBadRequest),
(401, webob.exc.HTTPUnauthorized),
(403, webob.exc.HTTPForbidden),
(409, webob.exc.HTTPConflict),
(500, webob.exc.HTTPInternalServerError)]:
for code, exc in [(http.BAD_REQUEST, webob.exc.HTTPBadRequest),
(http.UNAUTHORIZED, webob.exc.HTTPUnauthorized),
(http.FORBIDDEN, webob.exc.HTTPForbidden),
(http.CONFLICT, webob.exc.HTTPConflict),
(http.INTERNAL_SERVER_ERROR,
webob.exc.HTTPInternalServerError)]:
c.conn.prime_request('GET',
('v1/images/'
'5dcddce0-cba5-4f18-9cf4-9853c7b207a6'), '',
@ -145,12 +147,12 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
resp = {'images': [IMG_RESPONSE_ACTIVE, IMG_RESPONSE_QUEUED]}
c.conn.prime_request('GET', 'v1/images/detail?is_public=None', '',
{'x-auth-token': 'noauth'},
200, jsonutils.dumps(resp), {})
http.OK, jsonutils.dumps(resp), {})
c.conn.prime_request('GET',
('v1/images/detail?marker=%s&is_public=None'
% IMG_RESPONSE_QUEUED['id']),
'', {'x-auth-token': 'noauth'},
200, jsonutils.dumps({'images': []}), {})
http.OK, jsonutils.dumps({'images': []}), {})
imgs = list(c.get_images())
self.assertEqual(2, len(imgs))
@ -163,7 +165,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
c.conn.prime_request('GET',
'v1/images/%s' % IMG_RESPONSE_ACTIVE['id'],
'', {'x-auth-token': 'noauth'},
200, image_contents, IMG_RESPONSE_ACTIVE)
http.OK, image_contents, IMG_RESPONSE_ACTIVE)
body = c.get_image(IMG_RESPONSE_ACTIVE['id'])
self.assertEqual(image_contents, body.read())
@ -187,7 +189,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
c.conn.prime_request('HEAD',
'v1/images/%s' % IMG_RESPONSE_ACTIVE['id'],
'', {'x-auth-token': 'noauth'},
200, '', IMG_RESPONSE_ACTIVE)
http.OK, '', IMG_RESPONSE_ACTIVE)
header = c.get_image_meta(IMG_RESPONSE_ACTIVE['id'])
self.assertIn('id', header)
@ -222,7 +224,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
c.conn.prime_request('POST', 'v1/images',
image_body, image_meta_with_proto,
200, '', IMG_RESPONSE_ACTIVE)
http.OK, '', IMG_RESPONSE_ACTIVE)
headers, body = c.add_image(IMG_RESPONSE_ACTIVE, image_body)
self.assertEqual(IMG_RESPONSE_ACTIVE, headers)
@ -237,7 +239,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
image_meta_headers['x-auth-token'] = 'noauth'
image_meta_headers['Content-Type'] = 'application/octet-stream'
c.conn.prime_request('PUT', 'v1/images/%s' % image_meta['id'],
'', image_meta_headers, 200, '', '')
'', image_meta_headers, http.OK, '', '')
headers, body = c.add_image_meta(image_meta)
@ -292,10 +294,10 @@ class FakeImageService(object):
return {}
def add_image_meta(self, meta):
return {'status': 200}, None
return {'status': http.OK}, None
def add_image(self, meta, data):
return {'status': 200}, None
return {'status': http.OK}, None
def get_image_service():

View File

@ -14,6 +14,7 @@
# under the License.
from oslo_serialization import jsonutils
from six.moves import http_client as http
import webob
from glance.api.middleware import version_negotiation
@ -31,7 +32,7 @@ class VersionsTest(base.IsolatedUnitTest):
req.accept = 'application/json'
self.config(bind_host='127.0.0.1', bind_port=9292)
res = versions.Controller().index(req)
self.assertEqual(300, res.status_int)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = [
@ -86,7 +87,7 @@ class VersionsTest(base.IsolatedUnitTest):
self.config(bind_host='127.0.0.1', bind_port=9292,
public_endpoint='https://example.com:9292')
res = versions.Controller().index(req)
self.assertEqual(300, res.status_int)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = [
@ -140,7 +141,7 @@ class VersionsTest(base.IsolatedUnitTest):
environ = webob.request.environ_from_url('http://localhost:9292')
req = WsgiRequest(environ)
res = versions.Controller().index(req)
self.assertEqual(300, res.status_int)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = [
@ -195,7 +196,7 @@ class VersionsTest(base.IsolatedUnitTest):
environ['HTTP_X_FORWARDED_PROTO'] = "https"
req = WsgiRequest(environ)
res = versions.Controller().index(req)
self.assertEqual(300, res.status_int)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = [

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@ import os
import uuid
from mock import patch
from six.moves import http_client as http
from six.moves import reload_module
import testtools
@ -913,7 +914,7 @@ class TestRegistryV1ClientApi(base.IsolatedUnitTest):
class FakeResponse(object):
status = 202
status = http.ACCEPTED
def getheader(*args, **kwargs):
return None

View File

@ -18,6 +18,7 @@ from cursive import exception as cursive_exception
import glance_store
import mock
import six
from six.moves import http_client as http
import webob
import glance.api.policy
@ -662,5 +663,5 @@ class TestImageDataSerializer(test_utils.BaseTestCase):
response = webob.Response()
response.request = request
self.serializer.upload(response, {})
self.assertEqual(204, response.status_int)
self.assertEqual(http.NO_CONTENT, response.status_int)
self.assertEqual('0', response.headers['Content-Length'])

View File

@ -18,6 +18,7 @@ import datetime
import glance_store
from oslo_config import cfg
from oslo_serialization import jsonutils
from six.moves import http_client as http
import webob
import glance.api.v2.image_members
@ -346,7 +347,7 @@ class TestImageMembersController(test_utils.BaseTestCase):
image_id = UUID2
res = self.controller.delete(request, image_id, member_id)
self.assertEqual(b'', res.body)
self.assertEqual(204, res.status_code)
self.assertEqual(http.NO_CONTENT, res.status_code)
found_member = self.db.image_member_find(
request.context, image_id=image_id, member=member_id)
self.assertEqual([], found_member)

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from six.moves import http_client as http
import webob
import glance.api.v2.image_tags
@ -96,9 +97,9 @@ class TestImagesSerializer(test_utils.BaseTestCase):
def test_create_tag(self):
response = webob.Response()
self.serializer.update(response, None)
self.assertEqual(204, response.status_int)
self.assertEqual(http.NO_CONTENT, response.status_int)
def test_delete_tag(self):
response = webob.Response()
self.serializer.delete(response, None)
self.assertEqual(204, response.status_int)
self.assertEqual(http.NO_CONTENT, response.status_int)

View File

@ -20,6 +20,7 @@ import glance_store as store
import mock
from oslo_serialization import jsonutils
import six
from six.moves import http_client as http
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
import testtools
@ -3257,12 +3258,12 @@ class TestImagesSerializer(test_utils.BaseTestCase):
request = webob.Request.blank(url)
response = webob.Response(request=request)
result = {'images': self.fixtures}
self.assertEqual(200, response.status_int)
self.assertEqual(http.OK, response.status_int)
# The image index should work though the user is forbidden
result['images'][0].locations = ImageLocations()
self.serializer.index(response, result)
self.assertEqual(200, response.status_int)
self.assertEqual(http.OK, response.status_int)
def test_show_full_fixture(self):
expected = {
@ -3343,7 +3344,7 @@ class TestImagesSerializer(test_utils.BaseTestCase):
}
response = webob.Response()
self.serializer.create(response, self.fixtures[0])
self.assertEqual(201, response.status_int)
self.assertEqual(http.CREATED, response.status_int)
actual = jsonutils.loads(response.body)
actual['tags'] = sorted(actual['tags'])
self.assertEqual(expected, actual)
@ -3502,7 +3503,7 @@ class TestImagesSerializerWithUnicode(test_utils.BaseTestCase):
}
response = webob.Response()
self.serializer.create(response, self.fixtures[0])
self.assertEqual(201, response.status_int)
self.assertEqual(http.CREATED, response.status_int)
actual = jsonutils.loads(response.body)
actual['tags'] = sorted(actual['tags'])
self.assertEqual(expected, actual)

View File

@ -21,6 +21,7 @@ import uuid
from oslo_serialization import jsonutils
import routes
import six
from six.moves import http_client as http
import webob
import glance.api.common
@ -128,7 +129,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
image = res_dict
for k, v in six.iteritems(fixture):
@ -164,7 +165,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(1, len(images))
@ -232,7 +233,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
# should be sorted by created_at desc, id desc
@ -269,7 +270,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(2, len(images))
@ -302,7 +303,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -335,7 +336,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(2, len(images))
@ -368,7 +369,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -401,7 +402,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(2, len(images))
@ -434,7 +435,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -498,7 +499,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
images = jsonutils.loads(res.body)[0]
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
self._compare_images_and_uuids([UUID4], images)
@ -546,7 +547,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
res_dict = jsonutils.loads(res.body)[0]
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = res_dict
self._compare_images_and_uuids([UUID2], images)
@ -589,7 +590,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
res_dict = jsonutils.loads(res.body)[0]
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = res_dict
self.assertEqual(2, len(images))
@ -623,7 +624,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(2, len(images))
self.assertEqual(extra_id, images[0]['id'])
@ -636,7 +637,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -647,7 +648,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -658,7 +659,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -669,7 +670,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(1, len(images))
self.assertEqual(extra_id, images[0]['id'])
@ -681,7 +682,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -692,7 +693,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -703,7 +704,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(images))
@ -766,7 +767,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
res_dict = jsonutils.loads(res.body)[0]
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
images = res_dict
# (flaper87)registry's v1 forced is_public to True
@ -823,7 +824,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -872,7 +873,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -920,7 +921,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -969,7 +970,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1014,7 +1015,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1066,7 +1067,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1118,7 +1119,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1185,7 +1186,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1199,7 +1200,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1266,7 +1267,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1280,7 +1281,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1294,7 +1295,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1308,7 +1309,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
}]
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
images = res_dict
@ -1332,7 +1333,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
@ -1360,7 +1361,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
@ -1384,7 +1385,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
@ -1407,7 +1408,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
@ -1430,7 +1431,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
@ -1453,7 +1454,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
res_dict = jsonutils.loads(res.body)[0]
@ -1480,7 +1481,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
self.assertEqual(error_cls, res_dict['_error']['cls'])
return res_dict
def _expect_ok(self, command, kwargs, method, expected_status=200):
def _expect_ok(self, command, kwargs, method, expected_status=http.OK):
code, res_dict = self._send_request(command, kwargs)
self.assertEqual(expected_status, code)
return res_dict
@ -1555,7 +1556,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
res_dict = jsonutils.loads(res.body)[0]
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
orig_num_images = len(res_dict)
@ -1567,7 +1568,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
# Verify one less image
cmd = [{
@ -1577,7 +1578,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
res_dict = jsonutils.loads(res.body)[0]
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
new_num_images = len(res_dict)
self.assertEqual(new_num_images, orig_num_images - 1)
@ -1595,7 +1596,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
deleted_image = jsonutils.loads(res.body)[0]
self.assertEqual(image['id'], deleted_image['id'])
@ -1613,7 +1614,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dump_as_bytes(cmd)
res = req.get_response(self.api)
self.assertEqual(200, res.status_int)
self.assertEqual(http.OK, res.status_int)
memb_list = jsonutils.loads(res.body)[0]
self.assertEqual(0, len(memb_list))

View File

@ -20,6 +20,7 @@ import uuid
import mock
from oslo_config import cfg
from oslo_serialization import jsonutils
from six.moves import http_client as http
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
from six.moves import range
import webob
@ -811,7 +812,7 @@ class TestTasksSerializer(test_utils.BaseTestCase):
self.serializer.create(response, self.fixtures[3])
serialized_task = jsonutils.loads(response.body)
self.assertEqual(201, response.status_int)
self.assertEqual(http.CREATED, response.status_int)
self.assertEqual(self.fixtures[3].task_id,
serialized_task['id'])
self.assertEqual(self.fixtures[3].task_input,
@ -825,7 +826,7 @@ class TestTasksSerializer(test_utils.BaseTestCase):
self.serializer.create(response, self.fixtures[0])
serialized_task = jsonutils.loads(response.body)
self.assertEqual(201, response.status_int)
self.assertEqual(http.CREATED, response.status_int)
self.assertEqual(self.fixtures[0].task_id,
serialized_task['id'])
self.assertEqual(self.fixtures[0].task_input,
@ -838,7 +839,7 @@ class TestTasksSerializer(test_utils.BaseTestCase):
self.serializer.create(response, self.fixtures[1])
serialized_task = jsonutils.loads(response.body)
self.assertEqual(201, response.status_int)
self.assertEqual(http.CREATED, response.status_int)
self.assertEqual(self.fixtures[1].task_id,
serialized_task['id'])
self.assertEqual(self.fixtures[1].task_input,

View File

@ -31,6 +31,7 @@ from oslo_serialization import jsonutils
from oslotest import moxstubout
import six
from six.moves import BaseHTTPServer
from six.moves import http_client as http
import testtools
import webob
@ -437,7 +438,7 @@ def start_http_server(image_id, image_data):
def _get_http_handler_class(fixture):
class StaticHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_response(http.OK)
self.send_header('Content-Length', str(len(fixture)))
self.end_headers()
self.wfile.write(fixture)
@ -447,9 +448,9 @@ def start_http_server(image_id, image_data):
# reserve non_existing_image_path for the cases where we expect
# 404 from the server
if 'non_existing_image_path' in self.path:
self.send_response(404)
self.send_response(http.NOT_FOUND)
else:
self.send_response(200)
self.send_response(http.OK)
self.send_header('Content-Length', str(len(fixture)))
self.end_headers()
return
@ -574,7 +575,8 @@ class FakeAuthMiddleware(wsgi.Middleware):
class FakeHTTPResponse(object):
def __init__(self, status=200, headers=None, data=None, *args, **kwargs):
def __init__(self, status=http.OK, headers=None, data=None,
*args, **kwargs):
data = data or b'I am a teapot, short and stout\n'
self.data = six.BytesIO(data)
self.read = self.data.read