Extracted HTTP response codes to constants in tests
There are several places in the source code where HTTP response codes are used as numeric values. These values are used from six.moves and the numeric values are replaced by constants. All of the used status codes were replaced with symbolic constants from six.moves.http_client. More about six.moves.http_client can be found at [2], under the table "Supported renames:". Also, this change improves code readibility. This patchset does not extract numeric values from the code itself, but it can be found at [1]. [1]: Ib9e26dcea927e96e65c626c18421621d3a29a64d [2]: https://pythonhosted.org/six/#module-six.moves Change-Id: Idfc7b043552f428f01ac3e47b270ee0639a8f5bc Closes-Bug: #1520159
This commit is contained in:
parent
9bd264cd03
commit
8a8e5bf56c
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ class TestRegistryURLVisibility(functional.FunctionalTest):
|
|||||||
path = self._url('/rpc')
|
path = self._url('/rpc')
|
||||||
response = requests.post(path, headers=self._headers(),
|
response = requests.post(path, headers=self._headers(),
|
||||||
data=self.req_body)
|
data=self.req_body)
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
def test_v2_enabled(self):
|
def test_v2_enabled(self):
|
||||||
@ -51,5 +52,5 @@ class TestRegistryURLVisibility(functional.FunctionalTest):
|
|||||||
path = self._url('/rpc')
|
path = self._url('/rpc')
|
||||||
response = requests.post(path, headers=self._headers(),
|
response = requests.post(path, headers=self._headers(),
|
||||||
data=self.req_body)
|
data=self.req_body)
|
||||||
self.assertEqual(200, response.status_code)
|
self.assertEqual(http.OK, response.status_code)
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
@ -19,6 +19,7 @@ import mock
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import requests
|
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 glare
|
||||||
from glance.api.glare.v0_1 import router
|
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)
|
super(TestArtifacts, self).start_servers(**kwargs)
|
||||||
|
|
||||||
def _create_artifact(self, type_name, type_version='1.0', data=None,
|
def _create_artifact(self, type_name, type_version='1.0', data=None,
|
||||||
status=201):
|
status=http.CREATED):
|
||||||
# create an artifact first
|
# create an artifact first
|
||||||
artifact_data = data or {'name': 'artifact-1',
|
artifact_data = data or {'name': 'artifact-1',
|
||||||
'version': '12'}
|
'version': '12'}
|
||||||
@ -190,7 +191,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
type_version),
|
type_version),
|
||||||
artifact_data, status=status)
|
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):
|
headers=None):
|
||||||
if not headers:
|
if not headers:
|
||||||
headers = self._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,
|
response = getattr(requests, method)(self._url(url), headers=headers,
|
||||||
data=data)
|
data=data)
|
||||||
self.assertEqual(status, response.status_code)
|
self.assertEqual(status, response.status_code)
|
||||||
if status >= 400:
|
if status >= http.BAD_REQUEST:
|
||||||
return response.text
|
return response.text
|
||||||
if "application/json" in response.headers["content-type"]:
|
if "application/json" in response.headers["content-type"]:
|
||||||
return jsonutils.loads(response.text)
|
return jsonutils.loads(response.text)
|
||||||
return 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):
|
headers=None):
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {'Content-Type': 'application/json'}
|
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,
|
return self._check_artifact_method("post", url, data, status=status,
|
||||||
headers=headers)
|
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)
|
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())
|
response = requests.delete(self._url(url), headers=self._headers())
|
||||||
self.assertEqual(status, response.status_code)
|
self.assertEqual(status, response.status_code)
|
||||||
return response.text
|
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'}):
|
headers={'Content-Type': 'application/json'}):
|
||||||
return self._check_artifact_method("patch", url, data, status=status,
|
return self._check_artifact_method("patch", url, data, status=status,
|
||||||
headers=headers)
|
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'}):
|
headers={'Content-Type': 'application/json'}):
|
||||||
return self._check_artifact_method("put", url, data, status=status,
|
return self._check_artifact_method("put", url, data, status=status,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
@ -268,7 +269,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
'/noprop/v1.0/drafts')["artifacts"]
|
'/noprop/v1.0/drafts')["artifacts"]
|
||||||
self.assertEqual(1, len(list_creating))
|
self.assertEqual(1, len(list_creating))
|
||||||
bad_version = self._check_artifact_get('/noprop/v1.0bad',
|
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)
|
self.assertIn("Invalid version string: u'1.0bad'", bad_version)
|
||||||
|
|
||||||
def test_list_artifacts_with_pagination(self):
|
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
|
a wrong version should result in
|
||||||
400 BadRequest 'No such plugin has been loaded'
|
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",
|
self.assertIn("No plugin for 'noprop v 0.0.9' has been loaded",
|
||||||
msg)
|
msg)
|
||||||
|
|
||||||
@ -386,11 +387,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
artifact_id = art['id']
|
artifact_id = art['id']
|
||||||
# 'hui' is invalid show level
|
# 'hui' is invalid show level
|
||||||
self._check_artifact_get(
|
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):
|
def test_get_artifact_no_such_id(self):
|
||||||
msg = self._check_artifact_get(
|
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)
|
self.assertIn('No artifact found with ID', msg)
|
||||||
|
|
||||||
def test_get_artifact_present_id_wrong_type(self):
|
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')
|
art2 = self._create_artifact('noprop')
|
||||||
# ok id and type_name but bad type_version should result in 404
|
# ok id and type_name but bad type_version should result in 404
|
||||||
self._check_artifact_get('/noprop/v0.5/%s' % str(art2['id']),
|
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
|
# try to access art2 by supplying art1.type and art2.id
|
||||||
self._check_artifact_get('/withprops/%s' % str(art2['id']),
|
self._check_artifact_get('/withprops/%s' % str(art2['id']),
|
||||||
status=404)
|
status=http.NOT_FOUND)
|
||||||
self._check_artifact_get('/noprop/%s' % str(art1['id']), status=404)
|
self._check_artifact_get('/noprop/%s' % str(art1['id']),
|
||||||
|
status=http.NOT_FOUND)
|
||||||
|
|
||||||
def test_delete_artifact(self):
|
def test_delete_artifact(self):
|
||||||
artifact_data = {'name': 'artifact-1',
|
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)
|
art1 = self._create_artifact('withprops', data=artifact_data)
|
||||||
self._check_artifact_delete('/withprops/v1.0/%s' % art1['id'])
|
self._check_artifact_delete('/withprops/v1.0/%s' % art1['id'])
|
||||||
art1_deleted = self._check_artifact_get('/withprops/%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)
|
self.assertIn('No artifact found with ID', art1_deleted)
|
||||||
|
|
||||||
def test_delete_artifact_no_such_id(self):
|
def test_delete_artifact_no_such_id(self):
|
||||||
self._check_artifact_delete('/noprop/v1/%s' % str(uuid.uuid4()),
|
self._check_artifact_delete('/noprop/v1/%s' % str(uuid.uuid4()),
|
||||||
status=404)
|
status=http.NOT_FOUND)
|
||||||
|
|
||||||
@unittest.skip("Test is unstable")
|
@unittest.skip("Test is unstable")
|
||||||
def test_delete_artifact_with_dependency(self):
|
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']))
|
self.assertEqual(1, len(art_updated['depends_on_list']))
|
||||||
# try to delete an artifact prior to its dependency
|
# try to delete an artifact prior to its dependency
|
||||||
res = self._check_artifact_delete('/withprops/v1/%s' % art['id'],
|
res = self._check_artifact_delete('/withprops/v1/%s' % art['id'],
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"Dependency property 'depends_on' has to be deleted first", res)
|
"Dependency property 'depends_on' has to be deleted first", res)
|
||||||
# delete a dependency
|
# delete a dependency
|
||||||
@ -450,7 +453,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
data=[{'op': 'remove', 'path': '/depends_on'}])
|
data=[{'op': 'remove', 'path': '/depends_on'}])
|
||||||
# try to delete prior to deleting artifact_list dependencies
|
# try to delete prior to deleting artifact_list dependencies
|
||||||
res = self._check_artifact_delete('/withprops/v1/%s' % art['id'],
|
res = self._check_artifact_delete('/withprops/v1/%s' % art['id'],
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"Dependency property 'depends_on_list' has to be deleted first",
|
"Dependency property 'depends_on_list' has to be deleted first",
|
||||||
res)
|
res)
|
||||||
@ -466,7 +469,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
headers = self._headers({'Content-Type': 'application/octet-stream'})
|
headers = self._headers({'Content-Type': 'application/octet-stream'})
|
||||||
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data='ZZZZZ', status=200)
|
data='ZZZZZ', status=http.OK)
|
||||||
self._check_artifact_delete('/withblob/v1/%s' % art['id'])
|
self._check_artifact_delete('/withblob/v1/%s' % art['id'])
|
||||||
|
|
||||||
def test_update_nonexistent_property_by_replace_op(self):
|
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' %
|
result = self._check_artifact_patch('/withprops/v1/%s' %
|
||||||
art['id'],
|
art['id'],
|
||||||
data=data,
|
data=data,
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn('400 Bad Request', result)
|
self.assertIn('400 Bad Request', result)
|
||||||
self.assertIn('Artifact has no property nonexistent_property', 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' %
|
result = self._check_artifact_patch('/withprops/v1/%s' %
|
||||||
art['id'],
|
art['id'],
|
||||||
data=data,
|
data=data,
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn('400 Bad Request', result)
|
self.assertIn('400 Bad Request', result)
|
||||||
self.assertIn('Artifact has no property nonexistent_property', 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'}]
|
'path': '/dict_prop/foo'}]
|
||||||
art_updated = self._check_artifact_patch('/withprops/v1/%s'
|
art_updated = self._check_artifact_patch('/withprops/v1/%s'
|
||||||
% art['id'],
|
% art['id'],
|
||||||
data=data, status=400)
|
data=data,
|
||||||
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn("The provided path 'dict_prop/foo' is invalid",
|
self.assertIn("The provided path 'dict_prop/foo' is invalid",
|
||||||
art_updated)
|
art_updated)
|
||||||
|
|
||||||
@ -564,7 +568,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
data = [{'op': 'remove', 'path': '/dict_prop/bar_list'}]
|
data = [{'op': 'remove', 'path': '/dict_prop/bar_list'}]
|
||||||
art_updated = self._check_artifact_patch('/withprops/v1/%s'
|
art_updated = self._check_artifact_patch('/withprops/v1/%s'
|
||||||
% art['id'],
|
% art['id'],
|
||||||
data=data, status=400)
|
data=data,
|
||||||
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn("The provided path 'dict_prop/bar_list' is invalid",
|
self.assertIn("The provided path 'dict_prop/bar_list' is invalid",
|
||||||
art_updated)
|
art_updated)
|
||||||
|
|
||||||
@ -654,7 +659,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
art_updated = self._check_artifact_patch('/withprops/v1/%s'
|
art_updated = self._check_artifact_patch('/withprops/v1/%s'
|
||||||
% art['id'],
|
% art['id'],
|
||||||
data=bad_index_data,
|
data=bad_index_data,
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn("The provided path 'prop_list/11' is invalid",
|
self.assertIn("The provided path 'prop_list/11' is invalid",
|
||||||
art_updated)
|
art_updated)
|
||||||
|
|
||||||
@ -723,7 +728,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
data = [{'op': 'remove', 'value': 'some value',
|
data = [{'op': 'remove', 'value': 'some value',
|
||||||
'path': '/non-existent-path/and-another'}]
|
'path': '/non-existent-path/and-another'}]
|
||||||
art_updated = self._check_artifact_patch(
|
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)
|
self.assertIn('Artifact has no property', art_updated)
|
||||||
|
|
||||||
def test_update_replace_non_existent_artifact_properties(self):
|
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',
|
data = [{'op': 'replace', 'value': 'some value',
|
||||||
'path': '/non-existent-path/and-another'}]
|
'path': '/non-existent-path/and-another'}]
|
||||||
art_updated = self._check_artifact_patch(
|
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)
|
self.assertIn('Artifact has no property', art_updated)
|
||||||
|
|
||||||
def test_update_artifact_remove_property(self):
|
def test_update_artifact_remove_property(self):
|
||||||
@ -756,7 +763,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
self.assertIsNone(art[prop])
|
self.assertIsNone(art[prop])
|
||||||
data = [{'op': 'replace', 'value': 123, 'path': '/prop1'}]
|
data = [{'op': 'replace', 'value': 123, 'path': '/prop1'}]
|
||||||
art_updated = self._check_artifact_patch(
|
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)
|
self.assertIn("Property 'prop1' may not have value '123'", art_updated)
|
||||||
|
|
||||||
def test_update_multiple_properties(self):
|
def test_update_multiple_properties(self):
|
||||||
@ -798,7 +805,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
'withprops',
|
'withprops',
|
||||||
data={"name": "name", "version": "42",
|
data={"name": "name", "version": "42",
|
||||||
"depends_on_list": [no_prop_art['id'],
|
"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)
|
self.assertIn("Items have to be unique", res)
|
||||||
|
|
||||||
def test_create_artifact_bad_dependency_format(self):
|
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(
|
art = self._check_artifact_post(
|
||||||
'/withprops/v1/drafts',
|
'/withprops/v1/drafts',
|
||||||
{"name": "name", "version": "42",
|
{"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)
|
self.assertIn('Not a valid value type', art)
|
||||||
art = self._check_artifact_post(
|
art = self._check_artifact_post(
|
||||||
'/withprops/v1.0/drafts',
|
'/withprops/v1.0/drafts',
|
||||||
{"name": "name", "version": "42",
|
{"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)
|
self.assertIn('object is not iterable', art)
|
||||||
|
|
||||||
def test_update_dependency(self):
|
def test_update_dependency(self):
|
||||||
@ -846,7 +854,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
'path': '/depends_on',
|
'path': '/depends_on',
|
||||||
'value': [with_prop_art['id']]}]
|
'value': [with_prop_art['id']]}]
|
||||||
not_updated = self._check_artifact_patch(
|
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',
|
self.assertIn('Artifact with a circular dependency can not be created',
|
||||||
not_updated)
|
not_updated)
|
||||||
|
|
||||||
@ -862,14 +871,15 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
self.assertNotEqual(0, len(art_updated['depends_on']))
|
self.assertNotEqual(0, len(art_updated['depends_on']))
|
||||||
# artifact can't be published if any dependency is in non-active state
|
# artifact can't be published if any dependency is in non-active state
|
||||||
res = self._check_artifact_post(
|
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)
|
self.assertIn("Not all dependencies are in 'active' state", res)
|
||||||
# after you publish the dependency -> artifact can be published
|
# after you publish the dependency -> artifact can be published
|
||||||
dep_published = self._check_artifact_post(
|
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'])
|
self.assertEqual('active', dep_published['state'])
|
||||||
art_published = self._check_artifact_post(
|
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'])
|
self.assertEqual('active', art_published['state'])
|
||||||
|
|
||||||
def test_no_mutable_change_in_published_state(self):
|
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'])
|
self.assertEqual(no_prop_other['id'], art_updated['depends_on']['id'])
|
||||||
# publish dependency
|
# publish dependency
|
||||||
dep_published = self._check_artifact_post(
|
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'])
|
self.assertEqual('active', dep_published['state'])
|
||||||
# publish artifact
|
# publish artifact
|
||||||
art_published = self._check_artifact_post(
|
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'])
|
self.assertEqual('active', art_published['state'])
|
||||||
# try to change dependency, should fail as already published
|
# try to change dependency, should fail as already published
|
||||||
res = self._check_artifact_patch(
|
res = self._check_artifact_patch(
|
||||||
'/withprops/v1/%s' % art_published['id'],
|
'/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)
|
self.assertIn('Attempt to set value of immutable property', res)
|
||||||
|
|
||||||
def test_create_artifact_empty_body(self):
|
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):
|
def test_create_artifact_insufficient_arguments(self):
|
||||||
self._check_artifact_post('/noprop/v1.0/drafts',
|
self._check_artifact_post('/noprop/v1.0/drafts',
|
||||||
{'name': 'some name, no version'},
|
{'name': 'some name, no version'},
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
|
|
||||||
def test_create_artifact_no_such_version(self):
|
def test_create_artifact_no_such_version(self):
|
||||||
"""Creation impossible without specifying a correct version.
|
"""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'
|
400 BadRequest 'No such plugin has been loaded'
|
||||||
"""
|
"""
|
||||||
# make sure there is no such artifact noprop
|
# 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',
|
artifact_data = {'name': 'artifact-1',
|
||||||
'version': '12'}
|
'version': '12'}
|
||||||
msg = self._check_artifact_post('/noprop/v0.0.9/drafts',
|
msg = self._check_artifact_post('/noprop/v0.0.9/drafts',
|
||||||
artifact_data,
|
artifact_data,
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn("No plugin for 'noprop v 0.0.9' has been loaded",
|
self.assertIn("No plugin for 'noprop v 0.0.9' has been loaded",
|
||||||
msg)
|
msg)
|
||||||
|
|
||||||
@ -936,7 +947,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
"""
|
"""
|
||||||
artifact_data = {'name': 'artifact-1',
|
artifact_data = {'name': 'artifact-1',
|
||||||
'version': '12'}
|
'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):
|
def test_create_artifact_no_properties(self):
|
||||||
"""Create an artifact with minimum parameters"""
|
"""Create an artifact with minimum parameters"""
|
||||||
@ -1022,13 +1034,13 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
'prop1': 1}
|
'prop1': 1}
|
||||||
res = self._check_artifact_post('/withprops/v1.0/drafts',
|
res = self._check_artifact_post('/withprops/v1.0/drafts',
|
||||||
artifact_data,
|
artifact_data,
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn("Property 'prop1' may not have value '1'", res)
|
self.assertIn("Property 'prop1' may not have value '1'", res)
|
||||||
artifact_data.pop('prop1')
|
artifact_data.pop('prop1')
|
||||||
artifact_data['nosuchprop'] = "Random"
|
artifact_data['nosuchprop'] = "Random"
|
||||||
res = self._check_artifact_post('/withprops/v1.0/drafts',
|
res = self._check_artifact_post('/withprops/v1.0/drafts',
|
||||||
artifact_data,
|
artifact_data,
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn("Artifact has no property nosuchprop", res)
|
self.assertIn("Artifact has no property nosuchprop", res)
|
||||||
|
|
||||||
def test_create_public_artifact(self):
|
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'})
|
headers = self._headers({'Content-Type': 'application/octet-stream'})
|
||||||
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data='ZZZZZ', status=200)
|
data='ZZZZZ', status=http.OK)
|
||||||
|
|
||||||
def test_upload_file_with_invalid_content_type(self):
|
def test_upload_file_with_invalid_content_type(self):
|
||||||
art = self._create_artifact('withblob')
|
art = self._create_artifact('withblob')
|
||||||
data = {'data': 'jjjjjj'}
|
data = {'data': 'jjjjjj'}
|
||||||
res = self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
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)
|
self.assertIn('Invalid Content-Type for work with blob1', res)
|
||||||
|
|
||||||
res = self._check_artifact_post('/withblob/v1/%s/blob_list'
|
res = self._check_artifact_post('/withblob/v1/%s/blob_list'
|
||||||
% art['id'],
|
% art['id'],
|
||||||
data=data, status=400)
|
data=data, status=http.BAD_REQUEST)
|
||||||
self.assertIn('Invalid Content-Type for work with blob_list', res)
|
self.assertIn('Invalid Content-Type for work with blob_list', res)
|
||||||
|
|
||||||
def test_upload_list_files(self):
|
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'})
|
headers = self._headers({'Content-Type': 'application/octet-stream'})
|
||||||
self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'],
|
self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'],
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data='ZZZZZ', status=200)
|
data='ZZZZZ', status=http.OK)
|
||||||
self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'],
|
self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'],
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data='YYYYY', status=200)
|
data='YYYYY', status=http.OK)
|
||||||
|
|
||||||
def test_download_file(self):
|
def test_download_file(self):
|
||||||
# Download some data from an artifact
|
# 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'})
|
headers = self._headers({'Content-Type': 'application/octet-stream'})
|
||||||
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data='ZZZZZ', status=200)
|
data='ZZZZZ', status=http.OK)
|
||||||
|
|
||||||
art = self._check_artifact_get('/withblob/%s' % artifact_id)
|
art = self._check_artifact_get('/withblob/%s' % artifact_id)
|
||||||
self.assertEqual(artifact_id, art['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'})
|
headers = self._headers({'Content-Type': 'application/octet-stream'})
|
||||||
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data=iterate_string('ZZZZZ'), status=200)
|
data=iterate_string('ZZZZZ'), status=http.OK)
|
||||||
|
|
||||||
art = self._check_artifact_get('/withblob/%s' % artifact_id)
|
art = self._check_artifact_get('/withblob/%s' % artifact_id)
|
||||||
self.assertEqual(artifact_id, art['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
|
# append to list property via POST
|
||||||
upd = self._check_artifact_post(
|
upd = self._check_artifact_post(
|
||||||
'/withprops/v1.0/%s/prop_list' % art['id'], data={'data': [11]},
|
'/withprops/v1.0/%s/prop_list' % art['id'], data={'data': [11]},
|
||||||
status=200)
|
status=http.OK)
|
||||||
self.assertEqual([11], upd['prop_list'])
|
self.assertEqual([11], upd['prop_list'])
|
||||||
# append to list property via POST
|
# append to list property via POST
|
||||||
upd = self._check_artifact_post(
|
upd = self._check_artifact_post(
|
||||||
'/withprops/v1.0/%s/prop_list/-' % art['id'],
|
'/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'])
|
self.assertEqual([11, 10], upd['prop_list'])
|
||||||
|
|
||||||
def test_bad_update_property(self):
|
def test_bad_update_property(self):
|
||||||
@ -1227,22 +1239,23 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
# try to update nonexistent property
|
# try to update nonexistent property
|
||||||
upd = self._check_artifact_put(
|
upd = self._check_artifact_put(
|
||||||
'/withprops/v1.0/%s/nosuchprop' % art['id'],
|
'/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)
|
self.assertIn('Artifact has no property nosuchprop', upd)
|
||||||
# try to pass wrong property value
|
# try to pass wrong property value
|
||||||
upd = self._check_artifact_put(
|
upd = self._check_artifact_put(
|
||||||
'/withprops/v1.0/%s/tuple_prop' % art['id'],
|
'/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)
|
self.assertIn("Property 'tuple_prop[0]' may not have value", upd)
|
||||||
# try to pass bad body (not a valid json)
|
# try to pass bad body (not a valid json)
|
||||||
upd = self._check_artifact_put(
|
upd = self._check_artifact_put(
|
||||||
'/withprops/v1.0/%s/tuple_prop' % art['id'], data="not a json",
|
'/withprops/v1.0/%s/tuple_prop' % art['id'], data="not a json",
|
||||||
status=400)
|
status=http.BAD_REQUEST)
|
||||||
self.assertIn("Invalid json body", upd)
|
self.assertIn("Invalid json body", upd)
|
||||||
# try to pass json body invalid under schema
|
# try to pass json body invalid under schema
|
||||||
upd = self._check_artifact_put(
|
upd = self._check_artifact_put(
|
||||||
'/withprops/v1.0/%s/tuple_prop' % art['id'],
|
'/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)
|
self.assertIn("Invalid json body", upd)
|
||||||
|
|
||||||
def test_update_different_depths_levels(self):
|
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)
|
art = self._create_artifact('withprops', data=data)
|
||||||
upd = self._check_artifact_post(
|
upd = self._check_artifact_post(
|
||||||
'/withprops/v1.0/%s/dict_prop' % art['id'],
|
'/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'])
|
self.assertEqual({'foo': 'some value'}, upd['dict_prop'])
|
||||||
upd = self._check_artifact_post(
|
upd = self._check_artifact_post(
|
||||||
'/withprops/v1.0/%s/dict_prop/bar_list' % art['id'],
|
'/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]},
|
self.assertEqual({'foo': 'some value', 'bar_list': [5]},
|
||||||
upd['dict_prop'])
|
upd['dict_prop'])
|
||||||
upd = self._check_artifact_post(
|
upd = self._check_artifact_post(
|
||||||
'/withprops/v1.0/%s/dict_prop/bar_list/0' % art['id'],
|
'/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]},
|
self.assertEqual({'foo': 'some value', 'bar_list': [5, 15]},
|
||||||
upd['dict_prop'])
|
upd['dict_prop'])
|
||||||
# try to attempt dict_property by nonexistent path
|
# try to attempt dict_property by nonexistent path
|
||||||
upd = self._check_artifact_post(
|
upd = self._check_artifact_post(
|
||||||
'/withprops/v1.0/%s/dict_prop/bar_list/nosuchkey' % art['id'],
|
'/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):
|
def test_artifact_inaccessible_by_different_user(self):
|
||||||
data = {'name': 'an artifact',
|
data = {'name': 'an artifact',
|
||||||
'version': '42'}
|
'version': '42'}
|
||||||
art = self._create_artifact('withprops', data=data)
|
art = self._create_artifact('withprops', data=data)
|
||||||
self._set_user('user2')
|
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):
|
def test_artifact_accessible_by_admin(self):
|
||||||
data = {'name': 'an artifact',
|
data = {'name': 'an artifact',
|
||||||
'version': '42'}
|
'version': '42'}
|
||||||
art = self._create_artifact('withprops', data=data)
|
art = self._create_artifact('withprops', data=data)
|
||||||
self._set_user('admin')
|
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):
|
def test_public_artifact_accessible_by_different_user(self):
|
||||||
data = {'name': 'an artifact',
|
data = {'name': 'an artifact',
|
||||||
@ -1290,7 +1303,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
'/withprops/v1.0/%s' % art['id'],
|
'/withprops/v1.0/%s' % art['id'],
|
||||||
data=[{'op': 'replace', 'value': 'public', 'path': '/visibility'}])
|
data=[{'op': 'replace', 'value': 'public', 'path': '/visibility'}])
|
||||||
self._set_user('user2')
|
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):
|
def test_public_artifact_not_editable_by_different_user(self):
|
||||||
data = {'name': 'an artifact',
|
data = {'name': 'an artifact',
|
||||||
@ -1303,7 +1316,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
self._check_artifact_patch(
|
self._check_artifact_patch(
|
||||||
'/withprops/v1.0/%s' % art['id'],
|
'/withprops/v1.0/%s' % art['id'],
|
||||||
data=[{'op': 'replace', 'value': 'private',
|
data=[{'op': 'replace', 'value': 'private',
|
||||||
'path': '/visibility'}], status=403)
|
'path': '/visibility'}], status=http.FORBIDDEN)
|
||||||
|
|
||||||
def test_public_artifact_editable_by_admin(self):
|
def test_public_artifact_editable_by_admin(self):
|
||||||
data = {'name': 'an artifact',
|
data = {'name': 'an artifact',
|
||||||
@ -1316,7 +1329,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
self._check_artifact_patch(
|
self._check_artifact_patch(
|
||||||
'/withprops/v1.0/%s' % art['id'],
|
'/withprops/v1.0/%s' % art['id'],
|
||||||
data=[{'op': 'replace', 'value': 'private',
|
data=[{'op': 'replace', 'value': 'private',
|
||||||
'path': '/visibility'}], status=200)
|
'path': '/visibility'}], status=http.OK)
|
||||||
|
|
||||||
def test_list_artifact_types(self):
|
def test_list_artifact_types(self):
|
||||||
actual = {
|
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'
|
u'http://127.0.0.1:%d/v0.1/artifacts/withprops/v1.0'
|
||||||
% self.api_port}]}]}
|
% 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'])
|
response[u'artifact_types'].sort(key=lambda x: x[u'type_name'])
|
||||||
for artifact_type in response[u'artifact_types']:
|
for artifact_type in response[u'artifact_types']:
|
||||||
artifact_type[u'versions'].sort(key=lambda x: x[u'id'])
|
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'}
|
data = {'name': 'name1', 'version': '2.2'}
|
||||||
self._check_artifact_post('/withprops/v1.0/drafts',
|
self._check_artifact_post('/withprops/v1.0/drafts',
|
||||||
data=data,
|
data=data,
|
||||||
status=400,
|
status=http.BAD_REQUEST,
|
||||||
headers={'Content-Type': 'lalala'})
|
headers={'Content-Type': 'lalala'})
|
||||||
|
|
||||||
def test_filter_by_non_dict_props(self):
|
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))
|
self.assertEqual(2, len(result))
|
||||||
|
|
||||||
url = '/withprops/v1.0/drafts?version=latest'
|
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):
|
def test_filter_by_version_only(self):
|
||||||
data = {'name': 'art1',
|
data = {'name': 'art1',
|
||||||
@ -1942,7 +1955,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
|
|
||||||
result = self._check_artifact_patch(
|
result = self._check_artifact_patch(
|
||||||
'/withblob/v1.0/%s' % art['id'],
|
'/withblob/v1.0/%s' % art['id'],
|
||||||
status=400,
|
status=http.BAD_REQUEST,
|
||||||
data=[{'op': 'replace',
|
data=[{'op': 'replace',
|
||||||
'value': 'public',
|
'value': 'public',
|
||||||
'path': '/blob1'}])
|
'path': '/blob1'}])
|
||||||
@ -1950,7 +1963,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
|
|
||||||
result = self._check_artifact_patch(
|
result = self._check_artifact_patch(
|
||||||
'/withblob/v1.0/%s' % art['id'],
|
'/withblob/v1.0/%s' % art['id'],
|
||||||
status=400,
|
status=http.BAD_REQUEST,
|
||||||
data=[{'op': 'remove',
|
data=[{'op': 'remove',
|
||||||
'value': 'public',
|
'value': 'public',
|
||||||
'path': '/blob1'}])
|
'path': '/blob1'}])
|
||||||
@ -1958,7 +1971,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
|
|
||||||
result = self._check_artifact_patch(
|
result = self._check_artifact_patch(
|
||||||
'/withblob/v1.0/%s' % art['id'],
|
'/withblob/v1.0/%s' % art['id'],
|
||||||
status=400,
|
status=http.BAD_REQUEST,
|
||||||
data=[{'op': 'add',
|
data=[{'op': 'add',
|
||||||
'value': 'public',
|
'value': 'public',
|
||||||
'path': '/blob1'}])
|
'path': '/blob1'}])
|
||||||
@ -1970,7 +1983,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
'Use semver notation')
|
'Use semver notation')
|
||||||
for bad_version in bad_versions:
|
for bad_version in bad_versions:
|
||||||
url = '/withprops/v1.0/drafts?version=gt:%s' % bad_version
|
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)
|
self.assertIn(response_string % bad_version, result)
|
||||||
|
|
||||||
def test_circular_dependency(self):
|
def test_circular_dependency(self):
|
||||||
@ -1980,6 +1993,6 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
|||||||
|
|
||||||
upd = self._check_artifact_post(
|
upd = self._check_artifact_post(
|
||||||
'/withprops/v1.0/%s/depends_on' % art['id'],
|
'/withprops/v1.0/%s/depends_on' % art['id'],
|
||||||
data={'data': art['id']}, status=400)
|
data={'data': art['id']}, status=http.BAD_REQUEST)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'Artifact with a circular dependency can not be created', upd)
|
'Artifact with a circular dependency can not be created', upd)
|
||||||
|
@ -24,6 +24,7 @@ import threading
|
|||||||
|
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
from six.moves import BaseHTTPServer
|
from six.moves import BaseHTTPServer
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
|
|
||||||
FIVE_KB = 5 * units.Ki
|
FIVE_KB = 5 * units.Ki
|
||||||
@ -35,13 +36,13 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
Respond to an image HEAD request fake metadata
|
Respond to an image HEAD request fake metadata
|
||||||
"""
|
"""
|
||||||
if 'images' in self.path:
|
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-Type', 'application/octet-stream')
|
||||||
self.send_header('Content-Length', FIVE_KB)
|
self.send_header('Content-Length', FIVE_KB)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.send_error(404, 'File Not Found: %s' % self.path)
|
self.send_error(http.NOT_FOUND, 'File Not Found: %s' % self.path)
|
||||||
return
|
return
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
@ -49,7 +50,7 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
Respond to an image GET request with fake image content.
|
Respond to an image GET request with fake image content.
|
||||||
"""
|
"""
|
||||||
if 'images' in self.path:
|
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-Type', 'application/octet-stream')
|
||||||
self.send_header('Content-Length', FIVE_KB)
|
self.send_header('Content-Length', FIVE_KB)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
@ -58,7 +59,7 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
self.wfile.close()
|
self.wfile.close()
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.send_error(404, 'File Not Found: %s' % self.path)
|
self.send_error(http.NOT_FOUND, 'File Not Found: %s' % self.path)
|
||||||
return
|
return
|
||||||
|
|
||||||
def log_message(self, format, *args):
|
def log_message(self, format, *args):
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from six.moves import http_client
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ class TestApiVersions(functional.FunctionalTest):
|
|||||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(versions_json, content)
|
||||||
|
|
||||||
def test_v2_api_configuration(self):
|
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)
|
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(versions_json, content)
|
||||||
|
|
||||||
def test_v1_api_configuration(self):
|
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)
|
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(versions_json, content)
|
||||||
|
|
||||||
|
|
||||||
@ -201,7 +202,7 @@ class TestApiPaths(functional.FunctionalTest):
|
|||||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_images_path(self):
|
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)
|
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_v1_images_path(self):
|
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)
|
path = 'http://%s:%d/v1/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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):
|
def test_get_root_path_with_unknown_header(self):
|
||||||
"""Assert GET / with Accept: unknown header
|
"""Assert GET / with Accept: unknown header
|
||||||
@ -232,7 +233,7 @@ class TestApiPaths(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'unknown'}
|
headers = {'Accept': 'unknown'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_root_path_with_openstack_header(self):
|
def test_get_root_path_with_openstack_header(self):
|
||||||
@ -243,7 +244,7 @@ class TestApiPaths(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
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)
|
self.assertEqual(self.images_json, content)
|
||||||
|
|
||||||
def test_get_images_path_with_openstack_header(self):
|
def test_get_images_path_with_openstack_header(self):
|
||||||
@ -256,7 +257,7 @@ class TestApiPaths(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'application/vnd.openstack.compute-v1'}
|
headers = {'Accept': 'application/vnd.openstack.compute-v1'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_v10_images_path(self):
|
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)
|
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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):
|
def test_get_v1a_images_path(self):
|
||||||
"""Assert GET /v1.a/images with no Accept: header
|
"""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)
|
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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):
|
def test_get_va1_images_path(self):
|
||||||
"""Assert GET /va.1/images with no Accept: header
|
"""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)
|
path = 'http://%s:%d/va.1/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_versions_path(self):
|
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)
|
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
self.assertEqual(self.versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_versions_path_with_openstack_header(self):
|
def test_get_versions_path_with_openstack_header(self):
|
||||||
@ -306,7 +307,7 @@ class TestApiPaths(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_v1_versions_path(self):
|
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)
|
path = 'http://%s:%d/v1/versions' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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):
|
def test_get_versions_choices(self):
|
||||||
"""Verify version choices returned"""
|
"""Verify version choices returned"""
|
||||||
path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_images_path_with_openstack_v2_header(self):
|
def test_get_images_path_with_openstack_v2_header(self):
|
||||||
@ -336,7 +337,7 @@ class TestApiPaths(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'application/vnd.openstack.images-v10'}
|
headers = {'Accept': 'application/vnd.openstack.images-v10'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
def test_get_v12_images_path(self):
|
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)
|
path = 'http://%s:%d/v1.2/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
@ -23,6 +23,7 @@ import sys
|
|||||||
import httplib2
|
import httplib2
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
|
from six.moves import http_client
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
data['image']['checksum'])
|
data['image']['checksum'])
|
||||||
@ -144,7 +145,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
|||||||
ids[1])
|
ids[1])
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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]),
|
self.assertTrue(self.is_image_cached(ids[1]),
|
||||||
"%s is not cached." % ids[1])
|
"%s is not cached." % ids[1])
|
||||||
|
@ -29,6 +29,7 @@ import time
|
|||||||
import httplib2
|
import httplib2
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
|
from six.moves import http_client
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
data['image']['checksum'])
|
data['image']['checksum'])
|
||||||
@ -81,7 +82,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# Verify image now in cache
|
# Verify image now in cache
|
||||||
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
||||||
@ -111,7 +112,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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))
|
self.assertFalse(os.path.exists(image_cached_path))
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
response, content = http.request(path, 'POST',
|
response, content = http.request(path, 'POST',
|
||||||
headers=headers,
|
headers=headers,
|
||||||
body=jsonutils.dumps(image_entity))
|
body=jsonutils.dumps(image_entity))
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
image_id = data['id']
|
image_id = data['id']
|
||||||
|
|
||||||
@ -147,7 +148,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
response, content = http.request(path, 'PUT',
|
response, content = http.request(path, 'PUT',
|
||||||
headers=headers,
|
headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(204, response.status)
|
self.assertEqual(http_client.NO_CONTENT, response.status)
|
||||||
|
|
||||||
# Verify image not in cache
|
# Verify image not in cache
|
||||||
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
||||||
@ -157,7 +158,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
# Grab the image
|
# Grab the image
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# Verify image now in cache
|
# Verify image now in cache
|
||||||
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
||||||
@ -169,7 +170,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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))
|
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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers)
|
response, content = http.request(path, 'POST', headers=headers)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual(FIVE_KB, data['image']['size'])
|
self.assertEqual(FIVE_KB, data['image']['size'])
|
||||||
|
|
||||||
@ -206,13 +207,13 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
# Grab the image
|
# Grab the image
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# Grab the image again to ensure it can be served out from
|
||||||
# cache with the correct size
|
# cache with the correct size
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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.assertEqual(FIVE_KB, int(response['content-length']))
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
@ -233,7 +234,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
data['image']['checksum'])
|
data['image']['checksum'])
|
||||||
@ -257,7 +258,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# Now, we delete the image from the server and verify that
|
||||||
# the image cache no longer contains the deleted image
|
# the image cache no longer contains the deleted image
|
||||||
@ -265,7 +266,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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))
|
self.assertFalse(os.path.exists(image_cached_path))
|
||||||
|
|
||||||
@ -293,7 +294,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
response, content = http.request(path, 'POST',
|
response, content = http.request(path, 'POST',
|
||||||
headers=headers,
|
headers=headers,
|
||||||
body=jsonutils.dumps(image_entity))
|
body=jsonutils.dumps(image_entity))
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
image_id = data['id']
|
image_id = data['id']
|
||||||
|
|
||||||
@ -304,7 +305,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
response, content = http.request(path, 'PUT',
|
response, content = http.request(path, 'PUT',
|
||||||
headers=headers,
|
headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(204, response.status)
|
self.assertEqual(http_client.NO_CONTENT, response.status)
|
||||||
|
|
||||||
# Verify image not in cache
|
# Verify image not in cache
|
||||||
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
||||||
@ -318,7 +319,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
# Grab the image
|
# Grab the image
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# Now, we delete the image from the server and verify that
|
||||||
# the image cache no longer contains the deleted image
|
# the image cache no longer contains the deleted image
|
||||||
@ -326,7 +327,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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))
|
self.assertFalse(os.path.exists(image_cached_path))
|
||||||
|
|
||||||
@ -350,7 +351,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
data['image']['checksum'])
|
data['image']['checksum'])
|
||||||
@ -365,7 +366,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# Verify image in cache
|
# Verify image in cache
|
||||||
image_cached_path = os.path.join(self.api_server.image_cache_dir,
|
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)
|
path = path % ("127.0.0.1", self.api_port, image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST')
|
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
|
# Download the image with v1. Ensure it is forbidden
|
||||||
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# Download the image with v2. This succeeds because
|
||||||
# we are in admin context.
|
# we are in admin context.
|
||||||
@ -392,28 +393,28 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# Reactivate the image using v2
|
# Reactivate the image using v2
|
||||||
path = "http://%s:%d/v2/images/%s/actions/reactivate"
|
path = "http://%s:%d/v2/images/%s/actions/reactivate"
|
||||||
path = path % ("127.0.0.1", self.api_port, image_id)
|
path = path % ("127.0.0.1", self.api_port, image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST')
|
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
|
# Download the image with v1. Ensure it is allowed
|
||||||
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# Download the image with v2. Ensure it is allowed
|
||||||
path = "http://%s:%d/v2/images/%s/file" % ("127.0.0.1", self.api_port,
|
path = "http://%s:%d/v2/images/%s/file" % ("127.0.0.1", self.api_port,
|
||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# Now, we delete the image from the server and verify that
|
||||||
# the image cache no longer contains the deleted image
|
# the image cache no longer contains the deleted image
|
||||||
@ -421,7 +422,7 @@ class BaseCacheMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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))
|
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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('images', data)
|
self.assertIn('images', data)
|
||||||
self.assertEqual(0, len(data['images']))
|
self.assertEqual(0, len(data['images']))
|
||||||
@ -453,7 +454,7 @@ class BaseCacheManageMiddlewareTest(object):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
data['image']['checksum'])
|
data['image']['checksum'])
|
||||||
@ -469,7 +470,7 @@ class BaseCacheManageMiddlewareTest(object):
|
|||||||
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('cached_images', data)
|
self.assertIn('cached_images', data)
|
||||||
@ -493,13 +494,13 @@ class BaseCacheManageMiddlewareTest(object):
|
|||||||
image_id1)
|
image_id1)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# Verify image now in cache
|
# Verify image now in cache
|
||||||
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('cached_images', data)
|
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)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# Verify an unprivileged user cannot delete images from the cache
|
||||||
path = "http://%s:%d/v1/cached_images/%s" % ("127.0.0.1",
|
path = "http://%s:%d/v1/cached_images/%s" % ("127.0.0.1",
|
||||||
self.api_port, image_id1)
|
self.api_port, image_id1)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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
|
# Verify an unprivileged user cannot delete all cached images
|
||||||
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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
|
# Verify an unprivileged user cannot queue an image
|
||||||
path = "http://%s:%d/v1/queued_images/%s" % ("127.0.0.1",
|
path = "http://%s:%d/v1/queued_images/%s" % ("127.0.0.1",
|
||||||
self.api_port, image_id2)
|
self.api_port, image_id2)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT')
|
response, content = http.request(path, 'PUT')
|
||||||
self.assertEqual(403, response.status)
|
self.assertEqual(http_client.FORBIDDEN, response.status)
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
@ -561,13 +562,13 @@ class BaseCacheManageMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# Verify image now in cache
|
# Verify image now in cache
|
||||||
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('cached_images', data)
|
self.assertIn('cached_images', data)
|
||||||
@ -593,13 +594,13 @@ class BaseCacheManageMiddlewareTest(object):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# Verify image hits increased in output of manage GET
|
||||||
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('cached_images', data)
|
self.assertIn('cached_images', data)
|
||||||
@ -637,14 +638,14 @@ class BaseCacheManageMiddlewareTest(object):
|
|||||||
ids[x])
|
ids[x])
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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])
|
"Failed to find image %s" % ids[x])
|
||||||
|
|
||||||
# Verify images now in cache
|
# Verify images now in cache
|
||||||
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('cached_images', data)
|
self.assertIn('cached_images', data)
|
||||||
@ -661,12 +662,12 @@ class BaseCacheManageMiddlewareTest(object):
|
|||||||
self.api_port, ids[2])
|
self.api_port, ids[2])
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('cached_images', data)
|
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)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('cached_images', data)
|
self.assertIn('cached_images', data)
|
||||||
@ -714,13 +715,13 @@ class BaseCacheManageMiddlewareTest(object):
|
|||||||
self.api_port, ids[x])
|
self.api_port, ids[x])
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT')
|
response, content = http.request(path, 'PUT')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# Delete all queued images
|
# Delete all queued images
|
||||||
path = "http://%s:%d/v1/queued_images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/queued_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
response, content = http.request(path, 'DELETE')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
num_deleted = data['num_deleted']
|
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)
|
path = "http://%s:%d/v1/queued_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
response, content = http.request(path, 'DELETE')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
num_deleted = data['num_deleted']
|
num_deleted = data['num_deleted']
|
||||||
@ -785,7 +786,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
|||||||
self.api_port, ids[0])
|
self.api_port, ids[0])
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT')
|
response, content = http.request(path, 'PUT')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
self.verify_no_cached_images()
|
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)
|
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertIn('cached_images', data)
|
self.assertIn('cached_images', data)
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import eventlet.patcher
|
import eventlet.patcher
|
||||||
import httplib2
|
import httplib2
|
||||||
|
from six.moves import http_client
|
||||||
import webob.dec
|
import webob.dec
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
@ -46,14 +47,14 @@ class ExceptionTestApp(object):
|
|||||||
|
|
||||||
elif path == "/rate-limit-retry":
|
elif path == "/rate-limit-retry":
|
||||||
request.response.retry_after = 10
|
request.response.retry_after = 10
|
||||||
request.response.status = 413
|
request.response.status = http_client.REQUEST_ENTITY_TOO_LARGE
|
||||||
|
|
||||||
elif path == "/service-unavailable":
|
elif path == "/service-unavailable":
|
||||||
request.response = webob.exc.HTTPServiceUnavailable()
|
request.response = webob.exc.HTTPServiceUnavailable()
|
||||||
|
|
||||||
elif path == "/service-unavailable-retry":
|
elif path == "/service-unavailable-retry":
|
||||||
request.response.retry_after = 10
|
request.response.retry_after = 10
|
||||||
request.response.status = 503
|
request.response.status = http_client.SERVICE_UNAVAILABLE
|
||||||
|
|
||||||
elif path == "/expectation-failed":
|
elif path == "/expectation-failed":
|
||||||
request.response = webob.exc.HTTPExpectationFailed()
|
request.response = webob.exc.HTTPExpectationFailed()
|
||||||
@ -134,4 +135,4 @@ class TestClientExceptions(functional.FunctionalTest):
|
|||||||
('127.0.0.1', self.port))
|
('127.0.0.1', self.port))
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertNotIn(b'ServerError', content)
|
self.assertNotIn(b'ServerError', content)
|
||||||
self.assertEqual(500, response.status)
|
self.assertEqual(http_client.INTERNAL_SERVER_ERROR, response.status)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"""Functional test cases testing glance client redirect-following."""
|
"""Functional test cases testing glance client redirect-following."""
|
||||||
|
|
||||||
import eventlet.patcher
|
import eventlet.patcher
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob.dec
|
import webob.dec
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ class TestClientRedirects(functional.FunctionalTest):
|
|||||||
Test GET with no redirect
|
Test GET with no redirect
|
||||||
"""
|
"""
|
||||||
response = self.client.do_request("GET", "/")
|
response = self.client.do_request("GET", "/")
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http.OK, response.status)
|
||||||
self.assertEqual("root", response.read())
|
self.assertEqual("root", response.read())
|
||||||
|
|
||||||
def test_get_with_one_redirect(self):
|
def test_get_with_one_redirect(self):
|
||||||
@ -105,7 +106,7 @@ class TestClientRedirects(functional.FunctionalTest):
|
|||||||
Test GET with one 302 FOUND redirect
|
Test GET with one 302 FOUND redirect
|
||||||
"""
|
"""
|
||||||
response = self.client.do_request("GET", "/302")
|
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())
|
self.assertEqual("success_from_host_one", response.read())
|
||||||
|
|
||||||
def test_get_with_one_redirect_query_string(self):
|
def test_get_with_one_redirect_query_string(self):
|
||||||
@ -114,7 +115,7 @@ class TestClientRedirects(functional.FunctionalTest):
|
|||||||
"""
|
"""
|
||||||
response = self.client.do_request("GET", "/302",
|
response = self.client.do_request("GET", "/302",
|
||||||
params={'with_qs': 'yes'})
|
params={'with_qs': 'yes'})
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http.OK, response.status)
|
||||||
self.assertEqual("success_with_qs", response.read())
|
self.assertEqual("success_with_qs", response.read())
|
||||||
|
|
||||||
def test_get_with_max_redirects(self):
|
def test_get_with_max_redirects(self):
|
||||||
@ -131,7 +132,7 @@ class TestClientRedirects(functional.FunctionalTest):
|
|||||||
Test POST with 302 redirect
|
Test POST with 302 redirect
|
||||||
"""
|
"""
|
||||||
response = self.client.do_request("POST", "/302")
|
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())
|
self.assertEqual("success_from_host_one", response.read())
|
||||||
|
|
||||||
def test_redirect_to_new_host(self):
|
def test_redirect_to_new_host(self):
|
||||||
@ -141,9 +142,9 @@ class TestClientRedirects(functional.FunctionalTest):
|
|||||||
url = "/redirect-to-%d" % self.port_two
|
url = "/redirect-to-%d" % self.port_two
|
||||||
response = self.client.do_request("POST", url)
|
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())
|
self.assertEqual("success_from_host_two", response.read())
|
||||||
|
|
||||||
response = self.client.do_request("POST", "/success")
|
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())
|
self.assertEqual("success_from_host_one", response.read())
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"""Tests cors middleware."""
|
"""Tests cors middleware."""
|
||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
|
from six.moves import http_client
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ class TestCORSMiddleware(functional.FunctionalTest):
|
|||||||
'Access-Control-Request-Method': 'GET'
|
'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.assertIn('access-control-allow-origin', r_headers)
|
||||||
self.assertEqual('http://valid.example.com',
|
self.assertEqual('http://valid.example.com',
|
||||||
r_headers['access-control-allow-origin'])
|
r_headers['access-control-allow-origin'])
|
||||||
@ -57,7 +58,7 @@ class TestCORSMiddleware(functional.FunctionalTest):
|
|||||||
'Access-Control-Request-Method': 'GET'
|
'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)
|
self.assertNotIn('access-control-allow-origin', r_headers)
|
||||||
|
|
||||||
def test_valid_cors_get_request(self):
|
def test_valid_cors_get_request(self):
|
||||||
@ -68,7 +69,7 @@ class TestCORSMiddleware(functional.FunctionalTest):
|
|||||||
'Origin': 'http://valid.example.com'
|
'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.assertIn('access-control-allow-origin', r_headers)
|
||||||
self.assertEqual('http://valid.example.com',
|
self.assertEqual('http://valid.example.com',
|
||||||
r_headers['access-control-allow-origin'])
|
r_headers['access-control-allow-origin'])
|
||||||
@ -81,5 +82,5 @@ class TestCORSMiddleware(functional.FunctionalTest):
|
|||||||
'Origin': 'http://invalid.example.com'
|
'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)
|
self.assertNotIn('access-control-allow-origin', r_headers)
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
|
from six.moves import http_client
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
from glance.tests import utils
|
from glance.tests import utils
|
||||||
@ -37,7 +38,7 @@ class HealthcheckMiddlewareTest(functional.FunctionalTest):
|
|||||||
|
|
||||||
response, content = self.request()
|
response, content = self.request()
|
||||||
self.assertEqual('OK', content)
|
self.assertEqual('OK', content)
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
@ -49,6 +50,6 @@ class HealthcheckMiddlewareTest(functional.FunctionalTest):
|
|||||||
|
|
||||||
response, content = self.request()
|
response, content = self.request()
|
||||||
self.assertEqual('DISABLED BY FILE', content)
|
self.assertEqual('DISABLED BY FILE', content)
|
||||||
self.assertEqual(503, response.status)
|
self.assertEqual(http_client.SERVICE_UNAVAILABLE, response.status)
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
@ -19,6 +19,7 @@ import os
|
|||||||
import stat
|
import stat
|
||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ class TestLogging(functional.FunctionalTest):
|
|||||||
|
|
||||||
path = "http://%s:%d/" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/" % ("127.0.0.1", self.api_port)
|
||||||
response, content = httplib2.Http().request(path, 'GET')
|
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)
|
self.assertNotEmptyFile(self.api_server.log_file)
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import time
|
|||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
from glance.tests.utils import execute
|
from glance.tests.utils import execute
|
||||||
@ -143,7 +144,7 @@ class TestReload(functional.FunctionalTest):
|
|||||||
# This recycles the existing socket
|
# This recycles the existing socket
|
||||||
path = self._url('http', '/')
|
path = self._url('http', '/')
|
||||||
response = requests.get(path)
|
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
|
del response # close socket so that process audit is reliable
|
||||||
|
|
||||||
pre_pids['api'] = self._get_children('api')
|
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')
|
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
|
||||||
path = self._url('https', '/')
|
path = self._url('https', '/')
|
||||||
response = requests.get(path, verify=ca_file)
|
response = requests.get(path, verify=ca_file)
|
||||||
self.assertEqual(300, response.status_code)
|
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
|
||||||
del response
|
del response
|
||||||
|
|
||||||
# Test https restart
|
# Test https restart
|
||||||
@ -181,7 +182,7 @@ class TestReload(functional.FunctionalTest):
|
|||||||
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
|
ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
|
||||||
path = self._url('https', '/')
|
path = self._url('https', '/')
|
||||||
response = requests.get(path, verify=ca_file)
|
response = requests.get(path, verify=ca_file)
|
||||||
self.assertEqual(300, response.status_code)
|
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
|
||||||
del response
|
del response
|
||||||
|
|
||||||
# Test changing the https bind_host
|
# Test changing the https bind_host
|
||||||
@ -199,7 +200,7 @@ class TestReload(functional.FunctionalTest):
|
|||||||
|
|
||||||
path = self._url('https', '/')
|
path = self._url('https', '/')
|
||||||
response = requests.get(path, verify=ca_file)
|
response = requests.get(path, verify=ca_file)
|
||||||
self.assertEqual(300, response.status_code)
|
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
|
||||||
del response
|
del response
|
||||||
|
|
||||||
# Test https -> http
|
# Test https -> http
|
||||||
@ -218,7 +219,7 @@ class TestReload(functional.FunctionalTest):
|
|||||||
|
|
||||||
path = self._url('http', '/')
|
path = self._url('http', '/')
|
||||||
response = requests.get(path)
|
response = requests.get(path)
|
||||||
self.assertEqual(300, response.status_code)
|
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
|
||||||
del response
|
del response
|
||||||
|
|
||||||
# Test changing the http bind_host
|
# Test changing the http bind_host
|
||||||
@ -236,7 +237,7 @@ class TestReload(functional.FunctionalTest):
|
|||||||
|
|
||||||
path = self._url('http', '/')
|
path = self._url('http', '/')
|
||||||
response = requests.get(path)
|
response = requests.get(path)
|
||||||
self.assertEqual(300, response.status_code)
|
self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
|
||||||
del response
|
del response
|
||||||
|
|
||||||
# Test logging configuration change
|
# Test logging configuration change
|
||||||
|
@ -20,6 +20,7 @@ import time
|
|||||||
import httplib2
|
import httplib2
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
|
from six.moves import http_client
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
@ -60,16 +61,16 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
metadata_encryption_key='')
|
metadata_encryption_key='')
|
||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
response, content = self._send_http_request(path, 'POST', body='XXX')
|
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']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('active', image['status'])
|
self.assertEqual('active', image['status'])
|
||||||
|
|
||||||
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
||||||
image['id'])
|
image['id'])
|
||||||
response, content = self._send_http_request(path, 'DELETE')
|
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')
|
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.assertEqual('pending_delete', response['x-image-meta-status'])
|
||||||
|
|
||||||
self.wait_for_scrub(path)
|
self.wait_for_scrub(path)
|
||||||
@ -106,7 +107,7 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', body='XXX',
|
response, content = http.request(path, 'POST', body='XXX',
|
||||||
headers=headers)
|
headers=headers)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
image = jsonutils.loads(content)['image']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('active', image['status'])
|
self.assertEqual('active', image['status'])
|
||||||
image_id = image['id']
|
image_id = image['id']
|
||||||
@ -115,10 +116,10 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE', headers=base_headers)
|
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)
|
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.assertEqual('pending_delete', response['x-image-meta-status'])
|
||||||
|
|
||||||
self.wait_for_scrub(path, headers=base_headers)
|
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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
response, content = self._send_http_request(path, 'POST', body='XXX')
|
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']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('active', image['status'])
|
self.assertEqual('active', image['status'])
|
||||||
|
|
||||||
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
||||||
image['id'])
|
image['id'])
|
||||||
response, content = self._send_http_request(path, 'DELETE')
|
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')
|
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.assertEqual('pending_delete', response['x-image-meta-status'])
|
||||||
|
|
||||||
# wait for the scrub time on the image to pass
|
# wait for the scrub time on the image to pass
|
||||||
@ -193,7 +194,7 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', body='XXX',
|
response, content = http.request(path, 'POST', body='XXX',
|
||||||
headers=headers)
|
headers=headers)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
image = jsonutils.loads(content)['image']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('active', image['status'])
|
self.assertEqual('active', image['status'])
|
||||||
image_id = image['id']
|
image_id = image['id']
|
||||||
@ -202,10 +203,10 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE', headers=base_headers)
|
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)
|
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.assertEqual('pending_delete', response['x-image-meta-status'])
|
||||||
|
|
||||||
# wait for the scrub time on the image to pass
|
# wait for the scrub time on the image to pass
|
||||||
@ -240,7 +241,7 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
# add an image
|
# add an image
|
||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
response, content = self._send_http_request(path, 'POST', body='XXX')
|
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']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('active', image['status'])
|
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,
|
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
||||||
image['id'])
|
image['id'])
|
||||||
response, content = self._send_http_request(path, 'DELETE')
|
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
|
# ensure the image is marked pending delete
|
||||||
response, content = self._send_http_request(path, 'HEAD')
|
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.assertEqual('pending_delete', response['x-image-meta-status'])
|
||||||
|
|
||||||
# Remove the file from the backend.
|
# Remove the file from the backend.
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
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)
|
path = "https://%s:%d/versions" % ("127.0.0.1", self.api_port)
|
||||||
https = httplib2.Http(ca_certs=self.ca_file)
|
https = httplib2.Http(ca_certs=self.ca_file)
|
||||||
response, content = https.request(path, 'GET')
|
response, content = https.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http.OK, response.status)
|
||||||
|
@ -22,6 +22,7 @@ import sys
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
|
from six.moves import http_client
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
|
|
||||||
"""Functional tests using httplib2 against the API server"""
|
"""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):
|
image_data="*" * FIVE_KB):
|
||||||
# performs image_create request, checks the response and returns
|
# performs image_create request, checks the response and returns
|
||||||
# content
|
# content
|
||||||
@ -56,7 +57,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
|
|
||||||
# checksum can be no longer that 32 characters (String(32))
|
# checksum can be no longer that 32 characters (String(32))
|
||||||
headers['X-Image-Meta-Checksum'] = 'x' * 42
|
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)
|
self.assertIn("Invalid checksum", content)
|
||||||
# test positive case as well
|
# test positive case as well
|
||||||
headers['X-Image-Meta-Checksum'] = hashlib.md5(image_data).hexdigest()
|
headers['X-Image-Meta-Checksum'] = hashlib.md5(image_data).hexdigest()
|
||||||
@ -71,11 +72,13 @@ class TestApi(functional.FunctionalTest):
|
|||||||
headers = minimal_headers('Image1')
|
headers = minimal_headers('Image1')
|
||||||
# check that long numbers result in 400
|
# check that long numbers result in 400
|
||||||
headers['X-Image-Meta-%s' % param] = str(sys.maxint + 1)
|
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)
|
self.assertIn("'%s' value out of range" % param, content)
|
||||||
# check that integers over 4 byte result in 400
|
# check that integers over 4 byte result in 400
|
||||||
headers['X-Image-Meta-%s' % param] = str(2 ** 31)
|
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)
|
self.assertIn("'%s' value out of range" % param, content)
|
||||||
# verify positive case as well
|
# verify positive case as well
|
||||||
headers['X-Image-Meta-%s' % param] = str((2 ** 31) - 1)
|
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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
self.assertEqual('{"images": []}', content)
|
self.assertEqual('{"images": []}', content)
|
||||||
|
|
||||||
# 1. GET /images/detail
|
# 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)
|
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
self.assertEqual('{"images": []}', content)
|
self.assertEqual('{"images": []}', content)
|
||||||
|
|
||||||
# 2. POST /images with public image named Image1
|
# 2. POST /images with public image named Image1
|
||||||
@ -184,7 +187,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
image_id = data['image']['id']
|
image_id = data['image']['id']
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
@ -199,7 +202,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'HEAD')
|
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'])
|
self.assertEqual("Image1", response['x-image-meta-name'])
|
||||||
|
|
||||||
# 4. GET image
|
# 4. GET image
|
||||||
@ -208,7 +211,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
expected_image_headers = {
|
expected_image_headers = {
|
||||||
'x-image-meta-id': image_id,
|
'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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
expected_result = {"images": [
|
expected_result = {"images": [
|
||||||
{"container_format": "ovf",
|
{"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)
|
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
expected_image = {
|
expected_image = {
|
||||||
"status": "active",
|
"status": "active",
|
||||||
@ -293,7 +296,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT', headers=headers)
|
response, content = http.request(path, 'PUT', headers=headers)
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual("x86_64", data['image']['properties']['arch'])
|
self.assertEqual("x86_64", data['image']['properties']['arch'])
|
||||||
self.assertEqual("Ubuntu", data['image']['properties']['distro'])
|
self.assertEqual("Ubuntu", data['image']['properties']['distro'])
|
||||||
@ -307,14 +310,15 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT', headers=headers)
|
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
|
# 9. GET /images/detail
|
||||||
# Verify image and all its metadata
|
# Verify image and all its metadata
|
||||||
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
expected_image = {
|
expected_image = {
|
||||||
"status": "active",
|
"status": "active",
|
||||||
@ -343,11 +347,11 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT', headers=headers)
|
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)
|
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
data = jsonutils.loads(content)['images'][0]
|
data = jsonutils.loads(content)['images'][0]
|
||||||
self.assertEqual(1, len(data['properties']))
|
self.assertEqual(1, len(data['properties']))
|
||||||
self.assertEqual("x86_64", data['properties']['arch'])
|
self.assertEqual("x86_64", data['properties']['arch'])
|
||||||
@ -359,12 +363,12 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT', headers=headers)
|
response, content = http.request(path, 'PUT', headers=headers)
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
|
|
||||||
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
data = jsonutils.loads(content)['images'][0]
|
data = jsonutils.loads(content)['images'][0]
|
||||||
self.assertEqual(2, len(data['properties']))
|
self.assertEqual(2, len(data['properties']))
|
||||||
self.assertEqual("x86_64", data['properties']['arch'])
|
self.assertEqual("x86_64", data['properties']['arch'])
|
||||||
@ -376,21 +380,21 @@ class TestApi(functional.FunctionalTest):
|
|||||||
("127.0.0.1", self.api_port, image_id))
|
("127.0.0.1", self.api_port, image_id))
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT')
|
response, content = http.request(path, 'PUT')
|
||||||
self.assertEqual(204, response.status)
|
self.assertEqual(http_client.NO_CONTENT, response.status)
|
||||||
|
|
||||||
# 13. Add member to image
|
# 13. Add member to image
|
||||||
path = ("http://%s:%d/v1/images/%s/members/pattiewhite" %
|
path = ("http://%s:%d/v1/images/%s/members/pattiewhite" %
|
||||||
("127.0.0.1", self.api_port, image_id))
|
("127.0.0.1", self.api_port, image_id))
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT')
|
response, content = http.request(path, 'PUT')
|
||||||
self.assertEqual(204, response.status)
|
self.assertEqual(http_client.NO_CONTENT, response.status)
|
||||||
|
|
||||||
# 14. List image members
|
# 14. List image members
|
||||||
path = ("http://%s:%d/v1/images/%s/members" %
|
path = ("http://%s:%d/v1/images/%s/members" %
|
||||||
("127.0.0.1", self.api_port, image_id))
|
("127.0.0.1", self.api_port, image_id))
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual(2, len(data['members']))
|
self.assertEqual(2, len(data['members']))
|
||||||
self.assertEqual('pattieblack', data['members'][0]['member_id'])
|
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))
|
("127.0.0.1", self.api_port, image_id))
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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
|
# 16. Attempt to replace members with an overlimit amount
|
||||||
# Adding 11 image members should fail since configured limit is 10
|
# Adding 11 image members should fail since configured limit is 10
|
||||||
@ -414,7 +418,8 @@ class TestApi(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
body = jsonutils.dumps(dict(memberships=memberships))
|
body = jsonutils.dumps(dict(memberships=memberships))
|
||||||
response, content = http.request(path, 'PUT', body=body)
|
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
|
# 17. Attempt to add a member while at limit
|
||||||
# Adding an 11th member should fail since configured limit is 10
|
# Adding an 11th member should fail since configured limit is 10
|
||||||
@ -427,13 +432,14 @@ class TestApi(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
body = jsonutils.dumps(dict(memberships=memberships))
|
body = jsonutils.dumps(dict(memberships=memberships))
|
||||||
response, content = http.request(path, 'PUT', body=body)
|
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" %
|
path = ("http://%s:%d/v1/images/%s/members/fail_me" %
|
||||||
("127.0.0.1", self.api_port, image_id))
|
("127.0.0.1", self.api_port, image_id))
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT')
|
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
|
# 18. POST /images with another public image named Image2
|
||||||
# attribute and three custom properties, "distro", "arch" & "foo".
|
# attribute and three custom properties, "distro", "arch" & "foo".
|
||||||
@ -447,7 +453,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
image2_id = data['image']['id']
|
image2_id = data['image']['id']
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
@ -465,7 +471,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image2_id)
|
image2_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'HEAD')
|
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'])
|
self.assertEqual("Image2", response['x-image-meta-name'])
|
||||||
|
|
||||||
# 20. GET /images
|
# 20. GET /images
|
||||||
@ -473,7 +479,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
images = jsonutils.loads(content)['images']
|
images = jsonutils.loads(content)['images']
|
||||||
self.assertEqual(2, len(images))
|
self.assertEqual(2, len(images))
|
||||||
self.assertEqual(image2_id, images[0]['id'])
|
self.assertEqual(image2_id, images[0]['id'])
|
||||||
@ -485,7 +491,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
"127.0.0.1", self.api_port)
|
"127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
images = jsonutils.loads(content)['images']
|
images = jsonutils.loads(content)['images']
|
||||||
self.assertEqual(2, len(images))
|
self.assertEqual(2, len(images))
|
||||||
self.assertEqual(image2_id, images[0]['id'])
|
self.assertEqual(image2_id, images[0]['id'])
|
||||||
@ -497,7 +503,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
"127.0.0.1", self.api_port)
|
"127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
images = jsonutils.loads(content)['images']
|
images = jsonutils.loads(content)['images']
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -507,7 +513,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
self.api_port)
|
self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
images = jsonutils.loads(content)['images']
|
images = jsonutils.loads(content)['images']
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -517,7 +523,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
self.api_port)
|
self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
images = jsonutils.loads(content)['images']
|
images = jsonutils.loads(content)['images']
|
||||||
self.assertEqual(1, len(images))
|
self.assertEqual(1, len(images))
|
||||||
self.assertEqual(image2_id, images[0]['id'])
|
self.assertEqual(image2_id, images[0]['id'])
|
||||||
@ -528,7 +534,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
self.api_port)
|
self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
images = jsonutils.loads(content)['images']
|
images = jsonutils.loads(content)['images']
|
||||||
self.assertEqual(1, len(images))
|
self.assertEqual(1, len(images))
|
||||||
self.assertEqual(image_id, images[0]['id'])
|
self.assertEqual(image_id, images[0]['id'])
|
||||||
@ -539,7 +545,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
self.api_port)
|
self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
images = jsonutils.loads(content)['images']
|
images = jsonutils.loads(content)['images']
|
||||||
self.assertEqual(1, len(images))
|
self.assertEqual(1, len(images))
|
||||||
self.assertEqual(image2_id, images[0]['id'])
|
self.assertEqual(image2_id, images[0]['id'])
|
||||||
@ -549,14 +555,14 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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
|
# 28. Try to list members of deleted image
|
||||||
path = ("http://%s:%d/v1/images/%s/members" %
|
path = ("http://%s:%d/v1/images/%s/members" %
|
||||||
("127.0.0.1", self.api_port, image_id))
|
("127.0.0.1", self.api_port, image_id))
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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
|
# 29. Try to update member of deleted image
|
||||||
path = ("http://%s:%d/v1/images/%s/members" %
|
path = ("http://%s:%d/v1/images/%s/members" %
|
||||||
@ -565,35 +571,35 @@ class TestApi(functional.FunctionalTest):
|
|||||||
fixture = [{'member_id': 'pattieblack', 'can_share': 'false'}]
|
fixture = [{'member_id': 'pattieblack', 'can_share': 'false'}]
|
||||||
body = jsonutils.dumps(dict(memberships=fixture))
|
body = jsonutils.dumps(dict(memberships=fixture))
|
||||||
response, content = http.request(path, 'PUT', body=body)
|
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
|
# 30. Try to add member to deleted image
|
||||||
path = ("http://%s:%d/v1/images/%s/members/chickenpattie" %
|
path = ("http://%s:%d/v1/images/%s/members/chickenpattie" %
|
||||||
("127.0.0.1", self.api_port, image_id))
|
("127.0.0.1", self.api_port, image_id))
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'PUT')
|
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
|
# 31. Try to delete member of deleted image
|
||||||
path = ("http://%s:%d/v1/images/%s/members/pattieblack" %
|
path = ("http://%s:%d/v1/images/%s/members/pattieblack" %
|
||||||
("127.0.0.1", self.api_port, image_id))
|
("127.0.0.1", self.api_port, image_id))
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
response, content = http.request(path, 'DELETE')
|
||||||
self.assertEqual(404, response.status)
|
self.assertEqual(http_client.NOT_FOUND, response.status)
|
||||||
|
|
||||||
# 32. DELETE image2
|
# 32. DELETE image2
|
||||||
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
|
||||||
image2_id)
|
image2_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
response, content = http.request(path, 'DELETE')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# 33. GET /images
|
# 33. GET /images
|
||||||
# Verify no images are listed
|
# Verify no images are listed
|
||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
images = jsonutils.loads(content)['images']
|
images = jsonutils.loads(content)['images']
|
||||||
self.assertEqual(0, len(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)
|
path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'HEAD')
|
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.assertEqual('GET', response.get('allow'))
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
@ -633,7 +639,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
image_id = data['image']['id']
|
image_id = data['image']['id']
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
@ -648,7 +654,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'HEAD')
|
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'])
|
self.assertEqual("Image1", response['x-image-meta-name'])
|
||||||
|
|
||||||
# 2. GET /images
|
# 2. GET /images
|
||||||
@ -656,7 +662,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
expected_result = {"images": [
|
expected_result = {"images": [
|
||||||
{"container_format": "ovf",
|
{"container_format": "ovf",
|
||||||
@ -672,7 +678,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
response, content = http.request(path, 'DELETE')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# 4. GET image
|
# 4. GET image
|
||||||
# Verify that 403 HTTPForbidden exception is raised prior to
|
# Verify that 403 HTTPForbidden exception is raised prior to
|
||||||
@ -683,7 +689,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(403, response.status)
|
self.assertEqual(http_client.FORBIDDEN, response.status)
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
@ -712,7 +718,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
image_id = data['image']['id']
|
image_id = data['image']['id']
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
@ -727,7 +733,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'HEAD')
|
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'])
|
self.assertEqual("Image1", response['x-image-meta-name'])
|
||||||
|
|
||||||
# 2. GET /images
|
# 2. GET /images
|
||||||
@ -735,7 +741,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
expected_result = {"images": [
|
expected_result = {"images": [
|
||||||
{"container_format": "ovf",
|
{"container_format": "ovf",
|
||||||
@ -751,7 +757,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
response, content = http.request(path, 'DELETE')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
# 4. GET image
|
# 4. GET image
|
||||||
# Verify that 404 HTTPNotFound exception is raised
|
# Verify that 404 HTTPNotFound exception is raised
|
||||||
@ -759,7 +765,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
image_id)
|
image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(404, response.status)
|
self.assertEqual(http_client.NOT_FOUND, response.status)
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
@ -776,7 +782,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=None)
|
body=None)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
image = jsonutils.loads(content)['image']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('queued', image['status'])
|
self.assertEqual('queued', image['status'])
|
||||||
|
|
||||||
@ -786,18 +792,18 @@ class TestApi(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'X-Image-Meta-Status': 'active'}
|
headers = {'X-Image-Meta-Status': 'active'}
|
||||||
response, content = http.request(path, 'PUT', headers=headers)
|
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')
|
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'])
|
self.assertEqual('queued', response['x-image-meta-status'])
|
||||||
|
|
||||||
# We allow 'setting' to the same status
|
# We allow 'setting' to the same status
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'X-Image-Meta-Status': 'queued'}
|
headers = {'X-Image-Meta-Status': 'queued'}
|
||||||
response, content = http.request(path, 'PUT', headers=headers)
|
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')
|
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'])
|
self.assertEqual('queued', response['x-image-meta-status'])
|
||||||
|
|
||||||
# Make image active
|
# Make image active
|
||||||
@ -805,7 +811,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
headers = {'Content-Type': 'application/octet-stream'}
|
headers = {'Content-Type': 'application/octet-stream'}
|
||||||
response, content = http.request(path, 'PUT', headers=headers,
|
response, content = http.request(path, 'PUT', headers=headers,
|
||||||
body='data')
|
body='data')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
image = jsonutils.loads(content)['image']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('active', image['status'])
|
self.assertEqual('active', image['status'])
|
||||||
|
|
||||||
@ -813,18 +819,18 @@ class TestApi(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'X-Image-Meta-Status': 'queued'}
|
headers = {'X-Image-Meta-Status': 'queued'}
|
||||||
response, content = http.request(path, 'PUT', headers=headers)
|
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')
|
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'])
|
self.assertEqual('active', response['x-image-meta-status'])
|
||||||
|
|
||||||
# We allow 'setting' to the same status
|
# We allow 'setting' to the same status
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'X-Image-Meta-Status': 'active'}
|
headers = {'X-Image-Meta-Status': 'active'}
|
||||||
response, content = http.request(path, 'PUT', headers=headers)
|
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')
|
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'])
|
self.assertEqual('active', response['x-image-meta-status'])
|
||||||
|
|
||||||
# Create a 'queued' image, ensure 'status' header is ignored
|
# Create a 'queued' image, ensure 'status' header is ignored
|
||||||
@ -834,7 +840,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
'X-Image-Meta-Status': 'active'}
|
'X-Image-Meta-Status': 'active'}
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=None)
|
body=None)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
image = jsonutils.loads(content)['image']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('queued', image['status'])
|
self.assertEqual('queued', image['status'])
|
||||||
|
|
||||||
@ -847,7 +853,7 @@ class TestApi(functional.FunctionalTest):
|
|||||||
'X-Image-Meta-Container-Format': 'bare'}
|
'X-Image-Meta-Container-Format': 'bare'}
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body='data')
|
body='data')
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
image = jsonutils.loads(content)['image']
|
image = jsonutils.loads(content)['image']
|
||||||
self.assertEqual('active', image['status'])
|
self.assertEqual('active', image['status'])
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
@ -26,6 +26,7 @@ import time
|
|||||||
import httplib2
|
import httplib2
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
|
from six.moves import http_client
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status, content)
|
self.assertEqual(http_client.CREATED, response.status, content)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
|
|
||||||
original_image_id = data['image']['id']
|
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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers)
|
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)
|
data = jsonutils.loads(content)
|
||||||
|
|
||||||
copy_image_id = data['image']['id']
|
copy_image_id = data['image']['id']
|
||||||
@ -97,7 +98,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'HEAD')
|
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:
|
if response['x-image-meta-status'] == expected_status:
|
||||||
return
|
return
|
||||||
self.fail('unexpected image status %s' %
|
self.fail('unexpected image status %s' %
|
||||||
@ -106,7 +107,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
|
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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(str(FIVE_KB), response['content-length'])
|
||||||
|
|
||||||
self.assertEqual("*" * FIVE_KB, content)
|
self.assertEqual("*" * FIVE_KB, content)
|
||||||
@ -120,7 +121,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
original_image_id)
|
original_image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
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
|
# GET image again to make sure the existence of the original
|
||||||
# image in from_store is not depended on
|
# image in from_store is not depended on
|
||||||
@ -128,7 +129,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
copy_image_id)
|
copy_image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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(str(FIVE_KB), response['content-length'])
|
||||||
|
|
||||||
self.assertEqual("*" * FIVE_KB, content)
|
self.assertEqual("*" * FIVE_KB, content)
|
||||||
@ -142,7 +143,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
copy_image_id)
|
copy_image_id)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
response, content = http.request(path, 'DELETE')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
@ -173,7 +174,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers)
|
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)
|
data = jsonutils.loads(content)
|
||||||
|
|
||||||
copy_image_id = data['image']['id']
|
copy_image_id = data['image']['id']
|
||||||
@ -187,7 +188,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'HEAD')
|
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:
|
if response['x-image-meta-status'] == expected_status:
|
||||||
return
|
return
|
||||||
self.fail('unexpected image status %s' %
|
self.fail('unexpected image status %s' %
|
||||||
@ -198,7 +199,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
# GET image and make sure image content is as expected
|
# GET image and make sure image content is as expected
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
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(str(FIVE_KB), response['content-length'])
|
||||||
self.assertEqual("*" * FIVE_KB, content)
|
self.assertEqual("*" * FIVE_KB, content)
|
||||||
@ -208,7 +209,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
# DELETE copied image
|
# DELETE copied image
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'DELETE')
|
response, content = http.request(path, 'DELETE')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
@ -234,7 +235,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
|||||||
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers)
|
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.'
|
expected = 'HTTP datastore could not find image at URI.'
|
||||||
self.assertIn(expected, content)
|
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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers)
|
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
|
expected = 'External sources are not supported: \'%s\'' % copy_from
|
||||||
msg = 'expected "%s" in "%s"' % (expected, content)
|
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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers)
|
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\''
|
expected = 'External sources are not supported: \'swift+config://xxx\''
|
||||||
msg = 'expected "%s" in "%s"' % (expected, content)
|
msg = 'expected "%s" in "%s"' % (expected, content)
|
||||||
|
@ -18,6 +18,7 @@ import os
|
|||||||
import httplib2
|
import httplib2
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
|
from six.moves import http_client
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
from glance.tests.utils import minimal_headers
|
from glance.tests.utils import minimal_headers
|
||||||
@ -57,7 +58,7 @@ class TestMiscellaneous(functional.FunctionalTest):
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'POST', headers=headers,
|
response, content = http.request(path, 'POST', headers=headers,
|
||||||
body=image_data)
|
body=image_data)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
data = jsonutils.loads(content)
|
data = jsonutils.loads(content)
|
||||||
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
self.assertEqual(hashlib.md5(image_data).hexdigest(),
|
||||||
data['image']['checksum'])
|
data['image']['checksum'])
|
||||||
@ -75,7 +76,7 @@ class TestMiscellaneous(functional.FunctionalTest):
|
|||||||
data['image']['id'])
|
data['image']['id'])
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'HEAD')
|
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'])
|
self.assertEqual("Image1", response['x-image-meta-name'])
|
||||||
|
|
||||||
# 4. GET /images/1
|
# 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)
|
path = "http://%s:%d/v1/images/1" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(404, response.status)
|
self.assertEqual(http_client.NOT_FOUND, response.status)
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ class TestMiscellaneous(functional.FunctionalTest):
|
|||||||
|
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
self.assertEqual('{"images": []}', content)
|
self.assertEqual('{"images": []}', content)
|
||||||
|
|
||||||
headers = {'Content-Type': 'application/octet-stream',
|
headers = {'Content-Type': 'application/octet-stream',
|
||||||
|
@ -17,6 +17,7 @@ import time
|
|||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
import psutil
|
import psutil
|
||||||
|
from six.moves import http_client
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
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)
|
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
self.assertEqual(b'{"images": []}', content)
|
self.assertEqual(b'{"images": []}', content)
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,7 @@ import uuid
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
# Namespace should not exist
|
# Namespace should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
|
||||||
# Create a namespace
|
# Create a namespace
|
||||||
path = self._url('/v2/metadefs/namespaces')
|
path = self._url('/v2/metadefs/namespaces')
|
||||||
@ -63,7 +64,7 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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']
|
namespace_loc_header = response.headers['Location']
|
||||||
|
|
||||||
# Returned namespace should match the created namespace with default
|
# Returned namespace should match the created namespace with default
|
||||||
@ -98,11 +99,11 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
|
|
||||||
# Attempt to insert a duplicate
|
# Attempt to insert a duplicate
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Get the namespace using the returned Location header
|
||||||
response = requests.get(namespace_loc_header, headers=self._headers())
|
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)
|
namespace = jsonutils.loads(response.text)
|
||||||
self.assertEqual(namespace_name, namespace['namespace'])
|
self.assertEqual(namespace_name, namespace['namespace'])
|
||||||
self.assertNotIn('object', namespace)
|
self.assertNotIn('object', namespace)
|
||||||
@ -126,7 +127,7 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = requests.put(path, headers=headers, data=data)
|
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
|
# Returned namespace should reflect the changes
|
||||||
namespace = jsonutils.loads(response.text)
|
namespace = jsonutils.loads(response.text)
|
||||||
@ -140,7 +141,7 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
# Updates should persist across requests
|
# Updates should persist across requests
|
||||||
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
|
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
|
||||||
response = requests.get(path, headers=self._headers())
|
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)
|
namespace = jsonutils.loads(response.text)
|
||||||
self.assertEqual('MyNamespace-UPDATED', namespace['namespace'])
|
self.assertEqual('MyNamespace-UPDATED', namespace['namespace'])
|
||||||
self.assertEqual('display_name-UPDATED', namespace['display_name'])
|
self.assertEqual('display_name-UPDATED', namespace['display_name'])
|
||||||
@ -152,7 +153,7 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
# Deletion should not work on protected namespaces
|
# Deletion should not work on protected namespaces
|
||||||
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
|
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
|
||||||
response = requests.delete(path, headers=self._headers())
|
response = requests.delete(path, headers=self._headers())
|
||||||
self.assertEqual(403, response.status_code)
|
self.assertEqual(http.FORBIDDEN, response.status_code)
|
||||||
|
|
||||||
# Unprotect namespace for deletion
|
# Unprotect namespace for deletion
|
||||||
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
|
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
|
||||||
@ -168,23 +169,23 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
data = jsonutils.dumps(doc)
|
data = jsonutils.dumps(doc)
|
||||||
response = requests.put(path, headers=headers, data=data)
|
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
|
# Deletion should work. Deleting namespace MyNamespace
|
||||||
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
|
path = self._url('/v2/metadefs/namespaces/%s' % namespace_name)
|
||||||
response = requests.delete(path, headers=self._headers())
|
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
|
# Namespace should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
||||||
response = requests.get(path, headers=self._headers())
|
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):
|
def test_metadef_dont_accept_illegal_bodies(self):
|
||||||
# Namespace should not exist
|
# Namespace should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/bodytest')
|
path = self._url('/v2/metadefs/namespaces/bodytest')
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
|
||||||
# Create a namespace
|
# Create a namespace
|
||||||
path = self._url('/v2/metadefs/namespaces')
|
path = self._url('/v2/metadefs/namespaces')
|
||||||
@ -197,7 +198,7 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Test all the urls that supply data
|
||||||
data_urls = [
|
data_urls = [
|
||||||
@ -217,7 +218,7 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
path = self._url(value)
|
path = self._url(value)
|
||||||
data = jsonutils.dumps(["body"])
|
data = jsonutils.dumps(["body"])
|
||||||
response = requests.get(path, headers=self._headers(), data=data)
|
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
|
# Put the namespace into the url
|
||||||
test_urls = [
|
test_urls = [
|
||||||
@ -238,4 +239,4 @@ class TestNamespaces(functional.FunctionalTest):
|
|||||||
data = jsonutils.dumps(["body"])
|
data = jsonutils.dumps(["body"])
|
||||||
response = getattr(requests, method)(
|
response = getattr(requests, method)(
|
||||||
path, headers=self._headers(), data=data)
|
path, headers=self._headers(), data=data)
|
||||||
self.assertEqual(400, response.status_code)
|
self.assertEqual(http.BAD_REQUEST, response.status_code)
|
||||||
|
@ -17,6 +17,7 @@ import uuid
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ class TestMetadefObjects(functional.FunctionalTest):
|
|||||||
# Namespace should not exist
|
# Namespace should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
|
||||||
# Create a namespace
|
# Create a namespace
|
||||||
path = self._url('/v2/metadefs/namespaces')
|
path = self._url('/v2/metadefs/namespaces')
|
||||||
@ -65,12 +66,12 @@ class TestMetadefObjects(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Metadata objects should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace/objects/object1')
|
path = self._url('/v2/metadefs/namespaces/MyNamespace/objects/object1')
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
|
||||||
# Create a object
|
# Create a object
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace/objects')
|
path = self._url('/v2/metadefs/namespaces/MyNamespace/objects')
|
||||||
@ -105,18 +106,18 @@ class TestMetadefObjects(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Attempt to insert a duplicate
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Get the metadata object created above
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
|
||||||
(namespace_name, metadata_object_name))
|
(namespace_name, metadata_object_name))
|
||||||
response = requests.get(path,
|
response = requests.get(path,
|
||||||
headers=self._headers())
|
headers=self._headers())
|
||||||
self.assertEqual(200, response.status_code)
|
self.assertEqual(http.OK, response.status_code)
|
||||||
metadata_object = jsonutils.loads(response.text)
|
metadata_object = jsonutils.loads(response.text)
|
||||||
self.assertEqual("object1", metadata_object['name'])
|
self.assertEqual("object1", metadata_object['name'])
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ class TestMetadefObjects(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = requests.put(path, headers=headers, data=data)
|
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
|
# Returned metadata_object should reflect the changes
|
||||||
metadata_object = jsonutils.loads(response.text)
|
metadata_object = jsonutils.loads(response.text)
|
||||||
@ -263,10 +264,10 @@ class TestMetadefObjects(functional.FunctionalTest):
|
|||||||
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
|
||||||
(namespace_name, metadata_object_name))
|
(namespace_name, metadata_object_name))
|
||||||
response = requests.delete(path, headers=self._headers())
|
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
|
# metadata_object object1 should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/objects/%s' %
|
||||||
(namespace_name, metadata_object_name))
|
(namespace_name, metadata_object_name))
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
@ -17,6 +17,7 @@ import uuid
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ class TestNamespaceProperties(functional.FunctionalTest):
|
|||||||
# Namespace should not exist
|
# Namespace should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
|
||||||
# Create a namespace
|
# Create a namespace
|
||||||
path = self._url('/v2/metadefs/namespaces')
|
path = self._url('/v2/metadefs/namespaces')
|
||||||
@ -72,13 +73,13 @@ class TestNamespaceProperties(functional.FunctionalTest):
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Property1 should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace/properties'
|
path = self._url('/v2/metadefs/namespaces/MyNamespace/properties'
|
||||||
'/property1')
|
'/property1')
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
|
||||||
# Create a property
|
# Create a property
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace/properties')
|
path = self._url('/v2/metadefs/namespaces/MyNamespace/properties')
|
||||||
@ -97,17 +98,17 @@ class TestNamespaceProperties(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Attempt to insert a duplicate
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Get the property created above
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
|
||||||
(namespace_name, property_name))
|
(namespace_name, property_name))
|
||||||
response = requests.get(path, headers=self._headers())
|
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)
|
property_object = jsonutils.loads(response.text)
|
||||||
self.assertEqual("integer", property_object['type'])
|
self.assertEqual("integer", property_object['type'])
|
||||||
self.assertEqual("property1", property_object['title'])
|
self.assertEqual("property1", property_object['title'])
|
||||||
@ -122,7 +123,7 @@ class TestNamespaceProperties(functional.FunctionalTest):
|
|||||||
namespace_name, property_name, '='.join(['?resource_type',
|
namespace_name, property_name, '='.join(['?resource_type',
|
||||||
resource_type_name])))
|
resource_type_name])))
|
||||||
response = requests.get(path, headers=self._headers())
|
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
|
# Get the property with prefix and specific resource type association
|
||||||
property_name_with_prefix = ''.join([resource_type_prefix,
|
property_name_with_prefix = ''.join([resource_type_prefix,
|
||||||
@ -131,7 +132,7 @@ class TestNamespaceProperties(functional.FunctionalTest):
|
|||||||
namespace_name, property_name_with_prefix, '='.join([
|
namespace_name, property_name_with_prefix, '='.join([
|
||||||
'?resource_type', resource_type_name])))
|
'?resource_type', resource_type_name])))
|
||||||
response = requests.get(path, headers=self._headers())
|
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)
|
property_object = jsonutils.loads(response.text)
|
||||||
self.assertEqual("integer", property_object['type'])
|
self.assertEqual("integer", property_object['type'])
|
||||||
self.assertEqual("property1", property_object['title'])
|
self.assertEqual("property1", property_object['title'])
|
||||||
@ -188,7 +189,7 @@ class TestNamespaceProperties(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = requests.put(path, headers=headers, data=data)
|
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
|
# Returned property should reflect the changes
|
||||||
property_object = jsonutils.loads(response.text)
|
property_object = jsonutils.loads(response.text)
|
||||||
@ -215,10 +216,10 @@ class TestNamespaceProperties(functional.FunctionalTest):
|
|||||||
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
|
||||||
(namespace_name, property_name))
|
(namespace_name, property_name))
|
||||||
response = requests.delete(path, headers=self._headers())
|
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
|
# property1 should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/properties/%s' %
|
||||||
(namespace_name, property_name))
|
(namespace_name, property_name))
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
@ -17,6 +17,7 @@ from oslo_log import log as logging
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import six
|
import six
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob.exc
|
import webob.exc
|
||||||
from wsme.rest import json
|
from wsme.rest import json
|
||||||
|
|
||||||
@ -183,13 +184,13 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
|||||||
|
|
||||||
def create(self, response, result):
|
def create(self, response, result):
|
||||||
resource_type_json = json.tojson(ResourceTypeAssociation, 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)
|
body = jsonutils.dumps(resource_type_json, ensure_ascii=False)
|
||||||
response.unicode_body = six.text_type(body)
|
response.unicode_body = six.text_type(body)
|
||||||
response.content_type = 'application/json'
|
response.content_type = 'application/json'
|
||||||
|
|
||||||
def delete(self, response, result):
|
def delete(self, response, result):
|
||||||
response.status_int = 204
|
response.status_int = http.NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
def _get_base_properties():
|
def _get_base_properties():
|
||||||
|
@ -17,6 +17,7 @@ import uuid
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ class TestMetadefTags(functional.FunctionalTest):
|
|||||||
# Namespace should not exist
|
# Namespace should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
path = self._url('/v2/metadefs/namespaces/MyNamespace')
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
|
||||||
# Create a namespace
|
# Create a namespace
|
||||||
path = self._url('/v2/metadefs/namespaces')
|
path = self._url('/v2/metadefs/namespaces')
|
||||||
@ -64,24 +65,24 @@ class TestMetadefTags(functional.FunctionalTest):
|
|||||||
"owner": "The Test Owner"}
|
"owner": "The Test Owner"}
|
||||||
)
|
)
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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 should not exist
|
||||||
metadata_tag_name = "tag1"
|
metadata_tag_name = "tag1"
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
||||||
(namespace_name, metadata_tag_name))
|
(namespace_name, metadata_tag_name))
|
||||||
response = requests.get(path, headers=self._headers())
|
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
|
# Create the metadata tag
|
||||||
headers = self._headers({'content-type': 'application/json'})
|
headers = self._headers({'content-type': 'application/json'})
|
||||||
response = requests.post(path, headers=headers)
|
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
|
# Get the metadata tag created above
|
||||||
response = requests.get(path,
|
response = requests.get(path,
|
||||||
headers=self._headers())
|
headers=self._headers())
|
||||||
self.assertEqual(200, response.status_code)
|
self.assertEqual(http.OK, response.status_code)
|
||||||
metadata_tag = jsonutils.loads(response.text)
|
metadata_tag = jsonutils.loads(response.text)
|
||||||
self.assertEqual(metadata_tag_name, metadata_tag['name'])
|
self.assertEqual(metadata_tag_name, metadata_tag['name'])
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ class TestMetadefTags(functional.FunctionalTest):
|
|||||||
# Try to create a duplicate metadata tag
|
# Try to create a duplicate metadata tag
|
||||||
headers = self._headers({'content-type': 'application/json'})
|
headers = self._headers({'content-type': 'application/json'})
|
||||||
response = requests.post(path, headers=headers)
|
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
|
# The metadata_tag should be mutable
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
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)
|
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
|
# Returned metadata_tag should reflect the changes
|
||||||
metadata_tag = jsonutils.loads(response.text)
|
metadata_tag = jsonutils.loads(response.text)
|
||||||
@ -132,20 +133,20 @@ class TestMetadefTags(functional.FunctionalTest):
|
|||||||
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
||||||
(namespace_name, metadata_tag_name))
|
(namespace_name, metadata_tag_name))
|
||||||
response = requests.get(path, headers=self._headers())
|
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'])
|
self.assertEqual('tag1-UPDATED', metadata_tag['name'])
|
||||||
|
|
||||||
# Deletion of metadata_tag_name
|
# Deletion of metadata_tag_name
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
||||||
(namespace_name, metadata_tag_name))
|
(namespace_name, metadata_tag_name))
|
||||||
response = requests.delete(path, headers=self._headers())
|
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
|
# metadata_tag_name should not exist
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
path = self._url('/v2/metadefs/namespaces/%s/tags/%s' %
|
||||||
(namespace_name, metadata_tag_name))
|
(namespace_name, metadata_tag_name))
|
||||||
response = requests.get(path, headers=self._headers())
|
response = requests.get(path, headers=self._headers())
|
||||||
self.assertEqual(404, response.status_code)
|
self.assertEqual(http.NOT_FOUND, response.status_code)
|
||||||
|
|
||||||
# Create multiple tags.
|
# Create multiple tags.
|
||||||
path = self._url('/v2/metadefs/namespaces/%s/tags' %
|
path = self._url('/v2/metadefs/namespaces/%s/tags' %
|
||||||
@ -155,11 +156,11 @@ class TestMetadefTags(functional.FunctionalTest):
|
|||||||
{"tags": [{"name": "tag1"}, {"name": "tag2"}, {"name": "tag3"}]}
|
{"tags": [{"name": "tag1"}, {"name": "tag2"}, {"name": "tag3"}]}
|
||||||
)
|
)
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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.
|
# List out the three new tags.
|
||||||
response = requests.get(path, headers=self._headers())
|
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']
|
tags = jsonutils.loads(response.text)['tags']
|
||||||
self.assertEqual(3, len(tags))
|
self.assertEqual(3, len(tags))
|
||||||
|
|
||||||
@ -168,10 +169,10 @@ class TestMetadefTags(functional.FunctionalTest):
|
|||||||
{"tags": [{"name": "tag4"}, {"name": "tag5"}, {"name": "tag4"}]}
|
{"tags": [{"name": "tag4"}, {"name": "tag5"}, {"name": "tag4"}]}
|
||||||
)
|
)
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Verify the previous 3 still exist
|
||||||
response = requests.get(path, headers=self._headers())
|
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']
|
tags = jsonutils.loads(response.text)['tags']
|
||||||
self.assertEqual(3, len(tags))
|
self.assertEqual(3, len(tags))
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ class TestSchemas(functional.FunctionalTest):
|
|||||||
# Ensure the image link works and custom properties are loaded
|
# Ensure the image link works and custom properties are loaded
|
||||||
path = 'http://%s:%d/v2/schemas/image' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/v2/schemas/image' % ('127.0.0.1', self.api_port)
|
||||||
response = requests.get(path)
|
response = requests.get(path)
|
||||||
self.assertEqual(200, response.status_code)
|
self.assertEqual(http.OK, response.status_code)
|
||||||
image_schema = jsonutils.loads(response.text)
|
image_schema = jsonutils.loads(response.text)
|
||||||
expected = set([
|
expected = set([
|
||||||
'id',
|
'id',
|
||||||
@ -60,7 +61,7 @@ class TestSchemas(functional.FunctionalTest):
|
|||||||
# Ensure the images link works and agrees with the image schema
|
# 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)
|
path = 'http://%s:%d/v2/schemas/images' % ('127.0.0.1', self.api_port)
|
||||||
response = requests.get(path)
|
response = requests.get(path)
|
||||||
self.assertEqual(200, response.status_code)
|
self.assertEqual(http.OK, response.status_code)
|
||||||
images_schema = jsonutils.loads(response.text)
|
images_schema = jsonutils.loads(response.text)
|
||||||
item_schema = images_schema['properties']['images']['items']
|
item_schema = images_schema['properties']['images']['items']
|
||||||
self.assertEqual(item_schema, image_schema)
|
self.assertEqual(item_schema, image_schema)
|
||||||
|
@ -18,6 +18,7 @@ import uuid
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
@ -55,14 +56,14 @@ class TestTasks(functional.FunctionalTest):
|
|||||||
# Task list should be empty
|
# Task list should be empty
|
||||||
path = self._url('/v2/tasks')
|
path = self._url('/v2/tasks')
|
||||||
response = requests.get(path, headers=self._headers(roles))
|
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):
|
def test_task_lifecycle(self):
|
||||||
self.start_servers(**self.__dict__.copy())
|
self.start_servers(**self.__dict__.copy())
|
||||||
# Task list should be empty
|
# Task list should be empty
|
||||||
path = self._url('/v2/tasks')
|
path = self._url('/v2/tasks')
|
||||||
response = requests.get(path, headers=self._headers())
|
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']
|
tasks = jsonutils.loads(response.text)['tasks']
|
||||||
self.assertEqual(0, len(tasks))
|
self.assertEqual(0, len(tasks))
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ class TestTasks(functional.FunctionalTest):
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
response = requests.post(path, headers=headers, data=data)
|
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
|
# Returned task entity should have a generated id and status
|
||||||
task = jsonutils.loads(response.text)
|
task = jsonutils.loads(response.text)
|
||||||
@ -121,7 +122,7 @@ class TestTasks(functional.FunctionalTest):
|
|||||||
# Tasks list should now have one entry
|
# Tasks list should now have one entry
|
||||||
path = self._url('/v2/tasks')
|
path = self._url('/v2/tasks')
|
||||||
response = requests.get(path, headers=self._headers())
|
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']
|
tasks = jsonutils.loads(response.text)['tasks']
|
||||||
self.assertEqual(1, len(tasks))
|
self.assertEqual(1, len(tasks))
|
||||||
self.assertEqual(task_id, tasks[0]['id'])
|
self.assertEqual(task_id, tasks[0]['id'])
|
||||||
@ -129,7 +130,7 @@ class TestTasks(functional.FunctionalTest):
|
|||||||
# Attempt to delete a task
|
# Attempt to delete a task
|
||||||
path = self._url('/v2/tasks/%s' % tasks[0]['id'])
|
path = self._url('/v2/tasks/%s' % tasks[0]['id'])
|
||||||
response = requests.delete(path, headers=self._headers())
|
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.assertIsNotNone(response.headers.get('Allow'))
|
||||||
self.assertEqual('GET', response.headers.get('Allow'))
|
self.assertEqual('GET', response.headers.get('Allow'))
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from six.moves import http_client
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ class TestPropertyQuotaViolations(base.ApiTest):
|
|||||||
def _get(self, image_id=""):
|
def _get(self, image_id=""):
|
||||||
path = ('/v2/images/%s' % image_id).rstrip('/')
|
path = ('/v2/images/%s' % image_id).rstrip('/')
|
||||||
rsp, content = self.http.request(path, 'GET', headers=self._headers())
|
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)
|
content = jsonutils.loads(content)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class TestPropertyQuotaViolations(base.ApiTest):
|
|||||||
headers = self._headers({'content-type': 'application/json'})
|
headers = self._headers({'content-type': 'application/json'})
|
||||||
rsp, content = self.http.request(path, 'POST', headers=headers,
|
rsp, content = self.http.request(path, 'POST', headers=headers,
|
||||||
body=jsonutils.dumps(body))
|
body=jsonutils.dumps(body))
|
||||||
self.assertEqual(201, rsp.status)
|
self.assertEqual(http_client.CREATED, rsp.status)
|
||||||
return jsonutils.loads(content)
|
return jsonutils.loads(content)
|
||||||
|
|
||||||
def _patch(self, image_id, body, expected_status):
|
def _patch(self, image_id, body, expected_status):
|
||||||
@ -91,15 +92,17 @@ class TestPropertyQuotaViolations(base.ApiTest):
|
|||||||
self.config(image_property_quota=2)
|
self.config(image_property_quota=2)
|
||||||
|
|
||||||
patch_body = [{'op': 'replace', 'path': '/k_4', 'value': 'v_4.new'}]
|
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'])
|
self.assertEqual('v_4.new', image['k_4'])
|
||||||
|
|
||||||
patch_body = [{'op': 'remove', 'path': '/k_7'}]
|
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)
|
self.assertNotIn('k_7', image)
|
||||||
|
|
||||||
patch_body = [{'op': 'add', 'path': '/k_100', 'value': 'v_100'}]
|
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)
|
image = self._get(image_id)
|
||||||
self.assertNotIn('k_100', image)
|
self.assertNotIn('k_100', image)
|
||||||
|
|
||||||
@ -107,7 +110,7 @@ class TestPropertyQuotaViolations(base.ApiTest):
|
|||||||
{'op': 'remove', 'path': '/k_5'},
|
{'op': 'remove', 'path': '/k_5'},
|
||||||
{'op': 'add', 'path': '/k_100', 'value': 'v_100'},
|
{'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)
|
image = self._get(image_id)
|
||||||
self.assertNotIn('k_100', image)
|
self.assertNotIn('k_100', image)
|
||||||
self.assertIn('k_5', image)
|
self.assertIn('k_5', image)
|
||||||
@ -119,7 +122,8 @@ class TestPropertyQuotaViolations(base.ApiTest):
|
|||||||
{'op': 'add', 'path': '/k_99', 'value': 'v_99'}]
|
{'op': 'add', 'path': '/k_99', 'value': 'v_99'}]
|
||||||
to_rm = ['k_%d' % i for i in range(orig_property_quota) if i != 7]
|
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])
|
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_99', image['k_99'])
|
||||||
self.assertEqual('v_100', image['k_100'])
|
self.assertEqual('v_100', image['k_100'])
|
||||||
for k in to_rm:
|
for k in to_rm:
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from oslo_serialization import jsonutils as json
|
from oslo_serialization import jsonutils as json
|
||||||
|
from six.moves import http_client
|
||||||
|
|
||||||
from glance.api.v2 import tasks
|
from glance.api.v2 import tasks
|
||||||
from glance.common import timeutils
|
from glance.common import timeutils
|
||||||
@ -73,7 +74,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
content_dict = json.loads(content)
|
content_dict = json.loads(content)
|
||||||
|
|
||||||
self.assertEqual(200, res.status)
|
self.assertEqual(http_client.OK, res.status)
|
||||||
res_tasks = content_dict['tasks']
|
res_tasks = content_dict['tasks']
|
||||||
if len(res_tasks) != 0:
|
if len(res_tasks) != 0:
|
||||||
for task in res_tasks:
|
for task in res_tasks:
|
||||||
@ -104,7 +105,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
body=body_content)
|
body=body_content)
|
||||||
|
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
|
|
||||||
task = json.loads(content)
|
task = json.loads(content)
|
||||||
task_id = task['id']
|
task_id = task['id']
|
||||||
@ -124,7 +125,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
content_dict = json.loads(content)
|
content_dict = json.loads(content)
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
self.assertFalse(content_dict['tasks'])
|
self.assertFalse(content_dict['tasks'])
|
||||||
|
|
||||||
# 1. GET /tasks/{task_id}
|
# 1. GET /tasks/{task_id}
|
||||||
@ -134,7 +135,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(404, response.status)
|
self.assertEqual(http_client.NOT_FOUND, response.status)
|
||||||
|
|
||||||
# 2. POST /tasks
|
# 2. POST /tasks
|
||||||
# Create a new task
|
# Create a new task
|
||||||
@ -147,7 +148,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
path = "/v2/tasks/%s" % task_id
|
path = "/v2/tasks/%s" % task_id
|
||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
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
|
# NOTE(sabari): wait for all task executions to finish before checking
|
||||||
# task status.
|
# task status.
|
||||||
@ -159,7 +160,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
self.assertIsNotNone(content)
|
self.assertIsNotNone(content)
|
||||||
|
|
||||||
data = json.loads(content)
|
data = json.loads(content)
|
||||||
@ -182,7 +183,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
path = "/v2/schemas/task"
|
path = "/v2/schemas/task"
|
||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
schema = tasks.get_task_schema()
|
schema = tasks.get_task_schema()
|
||||||
expected_schema = schema.minimal()
|
expected_schema = schema.minimal()
|
||||||
@ -195,7 +196,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
path = "/v2/schemas/tasks"
|
path = "/v2/schemas/tasks"
|
||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
schema = tasks.get_collection_schema()
|
schema = tasks.get_collection_schema()
|
||||||
expected_schema = schema.minimal()
|
expected_schema = schema.minimal()
|
||||||
@ -218,7 +219,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(
|
response, content = self.http.request(
|
||||||
path, 'POST', headers=minimal_task_headers(task_owner),
|
path, 'POST', headers=minimal_task_headers(task_owner),
|
||||||
body=body_content)
|
body=body_content)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
|
|
||||||
data = json.loads(content)
|
data = json.loads(content)
|
||||||
task_id = data['id']
|
task_id = data['id']
|
||||||
@ -239,7 +240,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(
|
response, content = self.http.request(
|
||||||
path, 'POST', headers=minimal_task_headers(task_owner),
|
path, 'POST', headers=minimal_task_headers(task_owner),
|
||||||
body=body_content)
|
body=body_content)
|
||||||
self.assertEqual(400, response.status)
|
self.assertEqual(http_client.BAD_REQUEST, response.status)
|
||||||
|
|
||||||
# 1. POST /tasks
|
# 1. POST /tasks
|
||||||
# Create a new task with invalid input for type 'import'
|
# Create a new task with invalid input for type 'import'
|
||||||
@ -252,7 +253,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(
|
response, content = self.http.request(
|
||||||
path, 'POST', headers=minimal_task_headers(task_owner),
|
path, 'POST', headers=minimal_task_headers(task_owner),
|
||||||
body=body_content)
|
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
|
# NOTE(nikhil): wait for all task executions to finish before exiting
|
||||||
# else there is a risk of running into deadlock
|
# else there is a risk of running into deadlock
|
||||||
@ -266,7 +267,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
content_dict = json.loads(content)
|
content_dict = json.loads(content)
|
||||||
self.assertFalse(content_dict['tasks'])
|
self.assertFalse(content_dict['tasks'])
|
||||||
@ -288,7 +289,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
content_dict = json.loads(content)
|
content_dict = json.loads(content)
|
||||||
self.assertEqual(2, len(content_dict['tasks']))
|
self.assertEqual(2, len(content_dict['tasks']))
|
||||||
@ -301,7 +302,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
content_dict = json.loads(content)
|
content_dict = json.loads(content)
|
||||||
self.assertEqual(1, len(content_dict['tasks']))
|
self.assertEqual(1, len(content_dict['tasks']))
|
||||||
@ -314,7 +315,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
content_dict = json.loads(content)
|
content_dict = json.loads(content)
|
||||||
self.assertEqual(1, len(content_dict['tasks']))
|
self.assertEqual(1, len(content_dict['tasks']))
|
||||||
@ -327,7 +328,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
|
|
||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
content_dict = json.loads(content)
|
content_dict = json.loads(content)
|
||||||
self.assertEqual(2, len(content_dict['tasks']))
|
self.assertEqual(2, len(content_dict['tasks']))
|
||||||
@ -349,7 +350,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
path = "/v2/tasks"
|
path = "/v2/tasks"
|
||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
tasks = json.loads(content)
|
tasks = json.loads(content)
|
||||||
self.assertFalse(tasks['tasks'])
|
self.assertFalse(tasks['tasks'])
|
||||||
|
|
||||||
@ -372,7 +373,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
tasks = json.loads(content)['tasks']
|
tasks = json.loads(content)['tasks']
|
||||||
|
|
||||||
@ -385,7 +386,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
actual_tasks = json.loads(content)['tasks']
|
actual_tasks = json.loads(content)['tasks']
|
||||||
|
|
||||||
@ -400,7 +401,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
actual_tasks = json.loads(content)['tasks']
|
actual_tasks = json.loads(content)['tasks']
|
||||||
|
|
||||||
@ -415,7 +416,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
actual_tasks = json.loads(content)['tasks']
|
actual_tasks = json.loads(content)['tasks']
|
||||||
|
|
||||||
@ -432,7 +433,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
path = "/v2/tasks"
|
path = "/v2/tasks"
|
||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
tasks = json.loads(content)
|
tasks = json.loads(content)
|
||||||
self.assertFalse(tasks['tasks'])
|
self.assertFalse(tasks['tasks'])
|
||||||
|
|
||||||
@ -456,7 +457,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
actual_tasks = json.loads(content)['tasks']
|
actual_tasks = json.loads(content)['tasks']
|
||||||
|
|
||||||
@ -471,7 +472,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
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 = [TENANT1, TENANT2, TENANT3]
|
||||||
expected_task_owners.sort()
|
expected_task_owners.sort()
|
||||||
@ -487,7 +488,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
actual_tasks = json.loads(content)['tasks']
|
actual_tasks = json.loads(content)['tasks']
|
||||||
self.assertEqual(2, len(actual_tasks))
|
self.assertEqual(2, len(actual_tasks))
|
||||||
@ -503,7 +504,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path, 'GET',
|
response, content = self.http.request(path, 'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
|
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
|
|
||||||
actual_tasks = json.loads(content)['tasks']
|
actual_tasks = json.loads(content)['tasks']
|
||||||
|
|
||||||
@ -524,7 +525,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(
|
response, content = self.http.request(
|
||||||
path, 'POST', headers=minimal_task_headers(task_owner),
|
path, 'POST', headers=minimal_task_headers(task_owner),
|
||||||
body=body_content)
|
body=body_content)
|
||||||
self.assertEqual(201, response.status)
|
self.assertEqual(http_client.CREATED, response.status)
|
||||||
|
|
||||||
data = json.loads(content)
|
data = json.loads(content)
|
||||||
task_id = data['id']
|
task_id = data['id']
|
||||||
@ -535,7 +536,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path,
|
response, content = self.http.request(path,
|
||||||
'DELETE',
|
'DELETE',
|
||||||
headers=minimal_task_headers())
|
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.headers.get('Allow'))
|
||||||
self.assertEqual(('GET',), response.webob_resp.allow)
|
self.assertEqual(('GET',), response.webob_resp.allow)
|
||||||
self.assertEqual(('GET',), response.allow)
|
self.assertEqual(('GET',), response.allow)
|
||||||
@ -546,7 +547,7 @@ class TestTasksApi(base.ApiTest):
|
|||||||
response, content = self.http.request(path,
|
response, content = self.http.request(path,
|
||||||
'GET',
|
'GET',
|
||||||
headers=minimal_task_headers())
|
headers=minimal_task_headers())
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(http_client.OK, response.status)
|
||||||
self.assertIsNotNone(content)
|
self.assertIsNotNone(content)
|
||||||
|
|
||||||
# NOTE(nikhil): wait for all task executions to finish before exiting
|
# NOTE(nikhil): wait for all task executions to finish before exiting
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import six
|
import six
|
||||||
|
from six.moves import http_client as http
|
||||||
|
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance.tests import utils as test_utils
|
from glance.tests import utils as test_utils
|
||||||
@ -38,12 +39,13 @@ class GlanceExceptionTestCase(test_utils.BaseTestCase):
|
|||||||
class FakeGlanceException(exception.GlanceException):
|
class FakeGlanceException(exception.GlanceException):
|
||||||
message = "default message: %(code)s"
|
message = "default message: %(code)s"
|
||||||
|
|
||||||
exc = FakeGlanceException(code=500)
|
exc = FakeGlanceException(code=http.INTERNAL_SERVER_ERROR)
|
||||||
self.assertEqual("default message: 500",
|
self.assertEqual("default message: 500",
|
||||||
encodeutils.exception_to_unicode(exc))
|
encodeutils.exception_to_unicode(exc))
|
||||||
|
|
||||||
def test_specified_error_msg_with_kwargs(self):
|
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))
|
self.assertIn('test: 500', encodeutils.exception_to_unicode(msg))
|
||||||
|
|
||||||
def test_non_unicode_error_msg(self):
|
def test_non_unicode_error_msg(self):
|
||||||
|
@ -21,6 +21,7 @@ from oslo_serialization import jsonutils
|
|||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import routes
|
import routes
|
||||||
import six
|
import six
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
@ -157,27 +158,27 @@ class TestRPCController(base.IsolatedUnitTest):
|
|||||||
# Body is not a list, it should fail
|
# Body is not a list, it should fail
|
||||||
req.body = jsonutils.dump_as_bytes({})
|
req.body = jsonutils.dump_as_bytes({})
|
||||||
res = req.get_response(api)
|
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.
|
# cmd is not dict, it should fail.
|
||||||
req.body = jsonutils.dump_as_bytes([None])
|
req.body = jsonutils.dump_as_bytes([None])
|
||||||
res = req.get_response(api)
|
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.
|
# No command key, it should fail.
|
||||||
req.body = jsonutils.dump_as_bytes([{}])
|
req.body = jsonutils.dump_as_bytes([{}])
|
||||||
res = req.get_response(api)
|
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.
|
# kwargs not dict, it should fail.
|
||||||
req.body = jsonutils.dump_as_bytes([{"command": "test", "kwargs": 2}])
|
req.body = jsonutils.dump_as_bytes([{"command": "test", "kwargs": 2}])
|
||||||
res = req.get_response(api)
|
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.
|
# Command does not exist, it should fail.
|
||||||
req.body = jsonutils.dump_as_bytes([{"command": "test"}])
|
req.body = jsonutils.dump_as_bytes([{"command": "test"}])
|
||||||
res = req.get_response(api)
|
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):
|
def test_rpc_exception_propagation(self):
|
||||||
api = create_api()
|
api = create_api()
|
||||||
@ -187,7 +188,7 @@ class TestRPCController(base.IsolatedUnitTest):
|
|||||||
|
|
||||||
req.body = jsonutils.dump_as_bytes([{"command": "raise_value_error"}])
|
req.body = jsonutils.dump_as_bytes([{"command": "raise_value_error"}])
|
||||||
res = req.get_response(api)
|
res = req.get_response(api)
|
||||||
self.assertEqual(200, res.status_int)
|
self.assertEqual(http.OK, res.status_int)
|
||||||
|
|
||||||
returned = jsonutils.loads(res.body)[0]
|
returned = jsonutils.loads(res.body)[0]
|
||||||
err_cls = 'builtins.ValueError' if six.PY3 else 'exceptions.ValueError'
|
err_cls = 'builtins.ValueError' if six.PY3 else 'exceptions.ValueError'
|
||||||
@ -195,7 +196,7 @@ class TestRPCController(base.IsolatedUnitTest):
|
|||||||
|
|
||||||
req.body = jsonutils.dump_as_bytes([{"command": "raise_weird_error"}])
|
req.body = jsonutils.dump_as_bytes([{"command": "raise_weird_error"}])
|
||||||
res = req.get_response(api)
|
res = req.get_response(api)
|
||||||
self.assertEqual(200, res.status_int)
|
self.assertEqual(http.OK, res.status_int)
|
||||||
|
|
||||||
returned = jsonutils.loads(res.body)[0]
|
returned = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual('glance.common.exception.RPCError',
|
self.assertEqual('glance.common.exception.RPCError',
|
||||||
@ -284,7 +285,7 @@ class TestRPCJSONSerializer(test_utils.BaseTestCase):
|
|||||||
fixture = {"key": "value"}
|
fixture = {"key": "value"}
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
rpc.RPCJSONSerializer().default(response, fixture)
|
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
|
content_types = [h for h in response.headerlist
|
||||||
if h[0] == 'Content-Type']
|
if h[0] == 'Content-Type']
|
||||||
self.assertEqual(1, len(content_types))
|
self.assertEqual(1, len(content_types))
|
||||||
|
@ -27,6 +27,7 @@ from oslo_concurrency import processutils
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import routes
|
import routes
|
||||||
import six
|
import six
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from glance.api.v1 import router as router_v1
|
from glance.api.v1 import router as router_v1
|
||||||
@ -188,7 +189,7 @@ class RequestTest(test_utils.BaseTestCase):
|
|||||||
req = webob.Request.blank(uri)
|
req = webob.Request.blank(uri)
|
||||||
req.method = method
|
req.method = method
|
||||||
res = req.get_response(api)
|
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"""
|
"""Makes sure v2 unallowed methods return 405"""
|
||||||
unallowed_methods = [
|
unallowed_methods = [
|
||||||
@ -217,13 +218,13 @@ class RequestTest(test_utils.BaseTestCase):
|
|||||||
req = webob.Request.blank(uri)
|
req = webob.Request.blank(uri)
|
||||||
req.method = method
|
req.method = method
|
||||||
res = req.get_response(api)
|
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
|
# Makes sure not implemented methods return 405
|
||||||
req = webob.Request.blank('/schemas/image')
|
req = webob.Request.blank('/schemas/image')
|
||||||
req.method = 'NonexistentMethod'
|
req.method = 'NonexistentMethod'
|
||||||
res = req.get_response(api)
|
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):
|
class ResourceTest(test_utils.BaseTestCase):
|
||||||
@ -317,7 +318,7 @@ class ResourceTest(test_utils.BaseTestCase):
|
|||||||
response = resource.__call__(request)
|
response = resource.__call__(request)
|
||||||
|
|
||||||
self.assertIsInstance(response, webob.exc.HTTPForbidden)
|
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):
|
def test_call_raises_exception(self):
|
||||||
class FakeController(object):
|
class FakeController(object):
|
||||||
@ -336,7 +337,7 @@ class ResourceTest(test_utils.BaseTestCase):
|
|||||||
response = resource.__call__(request)
|
response = resource.__call__(request)
|
||||||
|
|
||||||
self.assertIsInstance(response, webob.exc.HTTPInternalServerError)
|
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')
|
@mock.patch.object(wsgi, 'translate_exception')
|
||||||
def test_resource_call_error_handle_localized(self,
|
def test_resource_call_error_handle_localized(self,
|
||||||
@ -433,7 +434,7 @@ class JSONResponseSerializerTest(test_utils.BaseTestCase):
|
|||||||
fixture = {"key": "value"}
|
fixture = {"key": "value"}
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
wsgi.JSONResponseSerializer().default(response, fixture)
|
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
|
content_types = [h for h in response.headerlist
|
||||||
if h[0] == 'Content-Type']
|
if h[0] == 'Content-Type']
|
||||||
self.assertEqual(1, len(content_types))
|
self.assertEqual(1, len(content_types))
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslotest import moxstubout
|
from oslotest import moxstubout
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from glance.api import authorization
|
from glance.api import authorization
|
||||||
@ -196,7 +197,7 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase):
|
|||||||
"""
|
"""
|
||||||
def fake_do_request(*args, **kwargs):
|
def fake_do_request(*args, **kwargs):
|
||||||
resp = webob.Response()
|
resp = webob.Response()
|
||||||
resp.status = 400
|
resp.status = http.BAD_REQUEST
|
||||||
return FakeResponse(resp), ""
|
return FakeResponse(resp), ""
|
||||||
|
|
||||||
self.stubs.Set(auth.KeystoneStrategy, '_do_request', fake_do_request)
|
self.stubs.Set(auth.KeystoneStrategy, '_do_request', fake_do_request)
|
||||||
@ -218,7 +219,7 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase):
|
|||||||
"""
|
"""
|
||||||
def fake_do_request(*args, **kwargs):
|
def fake_do_request(*args, **kwargs):
|
||||||
resp = webob.Response()
|
resp = webob.Response()
|
||||||
resp.status = 400
|
resp.status = http.BAD_REQUEST
|
||||||
return FakeResponse(resp), ""
|
return FakeResponse(resp), ""
|
||||||
|
|
||||||
self.stubs.Set(auth.KeystoneStrategy, '_do_request', fake_do_request)
|
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
|
if (headers.get('X-Auth-User') != 'user1' or
|
||||||
headers.get('X-Auth-Key') != 'pass'):
|
headers.get('X-Auth-Key') != 'pass'):
|
||||||
resp.status = 401
|
resp.status = http.UNAUTHORIZED
|
||||||
else:
|
else:
|
||||||
resp.status = 200
|
resp.status = http.OK
|
||||||
resp.headers.update({"x-image-management-url": "example.com"})
|
resp.headers.update({"x-image-management-url": "example.com"})
|
||||||
|
|
||||||
return FakeResponse(resp), ""
|
return FakeResponse(resp), ""
|
||||||
@ -334,9 +335,9 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase):
|
|||||||
|
|
||||||
if (username != 'user1' or password != 'pass' or
|
if (username != 'user1' or password != 'pass' or
|
||||||
tenant != 'tenant-ok'):
|
tenant != 'tenant-ok'):
|
||||||
resp.status = 401
|
resp.status = http.UNAUTHORIZED
|
||||||
else:
|
else:
|
||||||
resp.status = 200
|
resp.status = http.OK
|
||||||
body = mock_token.token
|
body = mock_token.token
|
||||||
|
|
||||||
return FakeResponse(resp), jsonutils.dumps(body)
|
return FakeResponse(resp), jsonutils.dumps(body)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from oslo_policy import policy
|
from oslo_policy import policy
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
|
from six.moves import http_client as http
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
import testtools
|
import testtools
|
||||||
import webob
|
import webob
|
||||||
@ -614,7 +615,7 @@ class TestCacheMiddlewareProcessResponse(base.IsolatedUnitTest):
|
|||||||
resp = webob.Response(headers=headers)
|
resp = webob.Response(headers=headers)
|
||||||
cache_filter = ProcessRequestTestCacheFilter()
|
cache_filter = ProcessRequestTestCacheFilter()
|
||||||
actual = cache_filter.get_status_code(resp)
|
actual = cache_filter.get_status_code(resp)
|
||||||
self.assertEqual(200, actual)
|
self.assertEqual(http.OK, actual)
|
||||||
|
|
||||||
def test_process_response(self):
|
def test_process_response(self):
|
||||||
def fake_fetch_request_info(*args, **kwargs):
|
def fake_fetch_request_info(*args, **kwargs):
|
||||||
|
@ -22,6 +22,7 @@ import mock
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
import six
|
||||||
from six import moves
|
from six import moves
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from glance.cmd import replicator as glance_replicator
|
from glance.cmd import replicator as glance_replicator
|
||||||
@ -126,11 +127,12 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
|
|||||||
def test_rest_errors(self):
|
def test_rest_errors(self):
|
||||||
c = glance_replicator.ImageService(FakeHTTPConnection(), 'noauth')
|
c = glance_replicator.ImageService(FakeHTTPConnection(), 'noauth')
|
||||||
|
|
||||||
for code, exc in [(400, webob.exc.HTTPBadRequest),
|
for code, exc in [(http.BAD_REQUEST, webob.exc.HTTPBadRequest),
|
||||||
(401, webob.exc.HTTPUnauthorized),
|
(http.UNAUTHORIZED, webob.exc.HTTPUnauthorized),
|
||||||
(403, webob.exc.HTTPForbidden),
|
(http.FORBIDDEN, webob.exc.HTTPForbidden),
|
||||||
(409, webob.exc.HTTPConflict),
|
(http.CONFLICT, webob.exc.HTTPConflict),
|
||||||
(500, webob.exc.HTTPInternalServerError)]:
|
(http.INTERNAL_SERVER_ERROR,
|
||||||
|
webob.exc.HTTPInternalServerError)]:
|
||||||
c.conn.prime_request('GET',
|
c.conn.prime_request('GET',
|
||||||
('v1/images/'
|
('v1/images/'
|
||||||
'5dcddce0-cba5-4f18-9cf4-9853c7b207a6'), '',
|
'5dcddce0-cba5-4f18-9cf4-9853c7b207a6'), '',
|
||||||
@ -145,12 +147,12 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
|
|||||||
resp = {'images': [IMG_RESPONSE_ACTIVE, IMG_RESPONSE_QUEUED]}
|
resp = {'images': [IMG_RESPONSE_ACTIVE, IMG_RESPONSE_QUEUED]}
|
||||||
c.conn.prime_request('GET', 'v1/images/detail?is_public=None', '',
|
c.conn.prime_request('GET', 'v1/images/detail?is_public=None', '',
|
||||||
{'x-auth-token': 'noauth'},
|
{'x-auth-token': 'noauth'},
|
||||||
200, jsonutils.dumps(resp), {})
|
http.OK, jsonutils.dumps(resp), {})
|
||||||
c.conn.prime_request('GET',
|
c.conn.prime_request('GET',
|
||||||
('v1/images/detail?marker=%s&is_public=None'
|
('v1/images/detail?marker=%s&is_public=None'
|
||||||
% IMG_RESPONSE_QUEUED['id']),
|
% IMG_RESPONSE_QUEUED['id']),
|
||||||
'', {'x-auth-token': 'noauth'},
|
'', {'x-auth-token': 'noauth'},
|
||||||
200, jsonutils.dumps({'images': []}), {})
|
http.OK, jsonutils.dumps({'images': []}), {})
|
||||||
|
|
||||||
imgs = list(c.get_images())
|
imgs = list(c.get_images())
|
||||||
self.assertEqual(2, len(imgs))
|
self.assertEqual(2, len(imgs))
|
||||||
@ -163,7 +165,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
|
|||||||
c.conn.prime_request('GET',
|
c.conn.prime_request('GET',
|
||||||
'v1/images/%s' % IMG_RESPONSE_ACTIVE['id'],
|
'v1/images/%s' % IMG_RESPONSE_ACTIVE['id'],
|
||||||
'', {'x-auth-token': 'noauth'},
|
'', {'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'])
|
body = c.get_image(IMG_RESPONSE_ACTIVE['id'])
|
||||||
self.assertEqual(image_contents, body.read())
|
self.assertEqual(image_contents, body.read())
|
||||||
@ -187,7 +189,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
|
|||||||
c.conn.prime_request('HEAD',
|
c.conn.prime_request('HEAD',
|
||||||
'v1/images/%s' % IMG_RESPONSE_ACTIVE['id'],
|
'v1/images/%s' % IMG_RESPONSE_ACTIVE['id'],
|
||||||
'', {'x-auth-token': 'noauth'},
|
'', {'x-auth-token': 'noauth'},
|
||||||
200, '', IMG_RESPONSE_ACTIVE)
|
http.OK, '', IMG_RESPONSE_ACTIVE)
|
||||||
|
|
||||||
header = c.get_image_meta(IMG_RESPONSE_ACTIVE['id'])
|
header = c.get_image_meta(IMG_RESPONSE_ACTIVE['id'])
|
||||||
self.assertIn('id', header)
|
self.assertIn('id', header)
|
||||||
@ -222,7 +224,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
c.conn.prime_request('POST', 'v1/images',
|
c.conn.prime_request('POST', 'v1/images',
|
||||||
image_body, image_meta_with_proto,
|
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)
|
headers, body = c.add_image(IMG_RESPONSE_ACTIVE, image_body)
|
||||||
self.assertEqual(IMG_RESPONSE_ACTIVE, headers)
|
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['x-auth-token'] = 'noauth'
|
||||||
image_meta_headers['Content-Type'] = 'application/octet-stream'
|
image_meta_headers['Content-Type'] = 'application/octet-stream'
|
||||||
c.conn.prime_request('PUT', 'v1/images/%s' % image_meta['id'],
|
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)
|
headers, body = c.add_image_meta(image_meta)
|
||||||
|
|
||||||
|
|
||||||
@ -292,10 +294,10 @@ class FakeImageService(object):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
def add_image_meta(self, meta):
|
def add_image_meta(self, meta):
|
||||||
return {'status': 200}, None
|
return {'status': http.OK}, None
|
||||||
|
|
||||||
def add_image(self, meta, data):
|
def add_image(self, meta, data):
|
||||||
return {'status': 200}, None
|
return {'status': http.OK}, None
|
||||||
|
|
||||||
|
|
||||||
def get_image_service():
|
def get_image_service():
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from glance.api.middleware import version_negotiation
|
from glance.api.middleware import version_negotiation
|
||||||
@ -31,7 +32,7 @@ class VersionsTest(base.IsolatedUnitTest):
|
|||||||
req.accept = 'application/json'
|
req.accept = 'application/json'
|
||||||
self.config(bind_host='127.0.0.1', bind_port=9292)
|
self.config(bind_host='127.0.0.1', bind_port=9292)
|
||||||
res = versions.Controller().index(req)
|
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)
|
self.assertEqual('application/json', res.content_type)
|
||||||
results = jsonutils.loads(res.body)['versions']
|
results = jsonutils.loads(res.body)['versions']
|
||||||
expected = [
|
expected = [
|
||||||
@ -86,7 +87,7 @@ class VersionsTest(base.IsolatedUnitTest):
|
|||||||
self.config(bind_host='127.0.0.1', bind_port=9292,
|
self.config(bind_host='127.0.0.1', bind_port=9292,
|
||||||
public_endpoint='https://example.com:9292')
|
public_endpoint='https://example.com:9292')
|
||||||
res = versions.Controller().index(req)
|
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)
|
self.assertEqual('application/json', res.content_type)
|
||||||
results = jsonutils.loads(res.body)['versions']
|
results = jsonutils.loads(res.body)['versions']
|
||||||
expected = [
|
expected = [
|
||||||
@ -140,7 +141,7 @@ class VersionsTest(base.IsolatedUnitTest):
|
|||||||
environ = webob.request.environ_from_url('http://localhost:9292')
|
environ = webob.request.environ_from_url('http://localhost:9292')
|
||||||
req = WsgiRequest(environ)
|
req = WsgiRequest(environ)
|
||||||
res = versions.Controller().index(req)
|
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)
|
self.assertEqual('application/json', res.content_type)
|
||||||
results = jsonutils.loads(res.body)['versions']
|
results = jsonutils.loads(res.body)['versions']
|
||||||
expected = [
|
expected = [
|
||||||
@ -195,7 +196,7 @@ class VersionsTest(base.IsolatedUnitTest):
|
|||||||
environ['HTTP_X_FORWARDED_PROTO'] = "https"
|
environ['HTTP_X_FORWARDED_PROTO'] = "https"
|
||||||
req = WsgiRequest(environ)
|
req = WsgiRequest(environ)
|
||||||
res = versions.Controller().index(req)
|
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)
|
self.assertEqual('application/json', res.content_type)
|
||||||
results = jsonutils.loads(res.body)['versions']
|
results = jsonutils.loads(res.body)['versions']
|
||||||
expected = [
|
expected = [
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,7 @@ import os
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
from six.moves import http_client as http
|
||||||
from six.moves import reload_module
|
from six.moves import reload_module
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
@ -913,7 +914,7 @@ class TestRegistryV1ClientApi(base.IsolatedUnitTest):
|
|||||||
|
|
||||||
|
|
||||||
class FakeResponse(object):
|
class FakeResponse(object):
|
||||||
status = 202
|
status = http.ACCEPTED
|
||||||
|
|
||||||
def getheader(*args, **kwargs):
|
def getheader(*args, **kwargs):
|
||||||
return None
|
return None
|
||||||
|
@ -18,6 +18,7 @@ from cursive import exception as cursive_exception
|
|||||||
import glance_store
|
import glance_store
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
import glance.api.policy
|
import glance.api.policy
|
||||||
@ -662,5 +663,5 @@ class TestImageDataSerializer(test_utils.BaseTestCase):
|
|||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
response.request = request
|
response.request = request
|
||||||
self.serializer.upload(response, {})
|
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'])
|
self.assertEqual('0', response.headers['Content-Length'])
|
||||||
|
@ -18,6 +18,7 @@ import datetime
|
|||||||
import glance_store
|
import glance_store
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
import glance.api.v2.image_members
|
import glance.api.v2.image_members
|
||||||
@ -346,7 +347,7 @@ class TestImageMembersController(test_utils.BaseTestCase):
|
|||||||
image_id = UUID2
|
image_id = UUID2
|
||||||
res = self.controller.delete(request, image_id, member_id)
|
res = self.controller.delete(request, image_id, member_id)
|
||||||
self.assertEqual(b'', res.body)
|
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(
|
found_member = self.db.image_member_find(
|
||||||
request.context, image_id=image_id, member=member_id)
|
request.context, image_id=image_id, member=member_id)
|
||||||
self.assertEqual([], found_member)
|
self.assertEqual([], found_member)
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
import glance.api.v2.image_tags
|
import glance.api.v2.image_tags
|
||||||
@ -96,9 +97,9 @@ class TestImagesSerializer(test_utils.BaseTestCase):
|
|||||||
def test_create_tag(self):
|
def test_create_tag(self):
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
self.serializer.update(response, None)
|
self.serializer.update(response, None)
|
||||||
self.assertEqual(204, response.status_int)
|
self.assertEqual(http.NO_CONTENT, response.status_int)
|
||||||
|
|
||||||
def test_delete_tag(self):
|
def test_delete_tag(self):
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
self.serializer.delete(response, None)
|
self.serializer.delete(response, None)
|
||||||
self.assertEqual(204, response.status_int)
|
self.assertEqual(http.NO_CONTENT, response.status_int)
|
||||||
|
@ -21,6 +21,7 @@ import mock
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
import six
|
||||||
|
from six.moves import http_client as http
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
import testtools
|
import testtools
|
||||||
@ -3260,12 +3261,12 @@ class TestImagesSerializer(test_utils.BaseTestCase):
|
|||||||
request = webob.Request.blank(url)
|
request = webob.Request.blank(url)
|
||||||
response = webob.Response(request=request)
|
response = webob.Response(request=request)
|
||||||
result = {'images': self.fixtures}
|
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
|
# The image index should work though the user is forbidden
|
||||||
result['images'][0].locations = ImageLocations()
|
result['images'][0].locations = ImageLocations()
|
||||||
self.serializer.index(response, result)
|
self.serializer.index(response, result)
|
||||||
self.assertEqual(200, response.status_int)
|
self.assertEqual(http.OK, response.status_int)
|
||||||
|
|
||||||
def test_show_full_fixture(self):
|
def test_show_full_fixture(self):
|
||||||
expected = {
|
expected = {
|
||||||
@ -3346,7 +3347,7 @@ class TestImagesSerializer(test_utils.BaseTestCase):
|
|||||||
}
|
}
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
self.serializer.create(response, self.fixtures[0])
|
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 = jsonutils.loads(response.body)
|
||||||
actual['tags'] = sorted(actual['tags'])
|
actual['tags'] = sorted(actual['tags'])
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
@ -3505,7 +3506,7 @@ class TestImagesSerializerWithUnicode(test_utils.BaseTestCase):
|
|||||||
}
|
}
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
self.serializer.create(response, self.fixtures[0])
|
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 = jsonutils.loads(response.body)
|
||||||
actual['tags'] = sorted(actual['tags'])
|
actual['tags'] = sorted(actual['tags'])
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
@ -22,6 +22,7 @@ from oslo_config import cfg
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import routes
|
import routes
|
||||||
import six
|
import six
|
||||||
|
from six.moves import http_client as http
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
import glance.api.common
|
import glance.api.common
|
||||||
@ -131,7 +132,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
image = res_dict
|
image = res_dict
|
||||||
for k, v in six.iteritems(fixture):
|
for k, v in six.iteritems(fixture):
|
||||||
@ -167,7 +168,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(1, len(images))
|
self.assertEqual(1, len(images))
|
||||||
@ -235,7 +236,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
# should be sorted by created_at desc, id desc
|
# should be sorted by created_at desc, id desc
|
||||||
@ -272,7 +273,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(2, len(images))
|
self.assertEqual(2, len(images))
|
||||||
|
|
||||||
@ -305,7 +306,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -338,7 +339,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(2, len(images))
|
self.assertEqual(2, len(images))
|
||||||
|
|
||||||
@ -371,7 +372,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -404,7 +405,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(2, len(images))
|
self.assertEqual(2, len(images))
|
||||||
|
|
||||||
@ -437,7 +438,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -501,7 +502,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
images = jsonutils.loads(res.body)[0]
|
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)
|
self._compare_images_and_uuids([UUID4], images)
|
||||||
|
|
||||||
@ -549,7 +550,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
res_dict = jsonutils.loads(res.body)[0]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(200, res.status_int)
|
self.assertEqual(http.OK, res.status_int)
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
self._compare_images_and_uuids([UUID2], images)
|
self._compare_images_and_uuids([UUID2], images)
|
||||||
@ -592,7 +593,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
res_dict = jsonutils.loads(res.body)[0]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(200, res.status_int)
|
self.assertEqual(http.OK, res.status_int)
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
self.assertEqual(2, len(images))
|
self.assertEqual(2, len(images))
|
||||||
@ -626,7 +627,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(2, len(images))
|
self.assertEqual(2, len(images))
|
||||||
self.assertEqual(extra_id, images[0]['id'])
|
self.assertEqual(extra_id, images[0]['id'])
|
||||||
@ -639,7 +640,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -650,7 +651,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -661,7 +662,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -672,7 +673,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(1, len(images))
|
self.assertEqual(1, len(images))
|
||||||
self.assertEqual(extra_id, images[0]['id'])
|
self.assertEqual(extra_id, images[0]['id'])
|
||||||
@ -684,7 +685,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -695,7 +696,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -706,7 +707,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
images = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(images))
|
self.assertEqual(0, len(images))
|
||||||
|
|
||||||
@ -769,7 +770,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
res_dict = jsonutils.loads(res.body)[0]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(200, res.status_int)
|
self.assertEqual(http.OK, res.status_int)
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
# (flaper87)registry's v1 forced is_public to True
|
# (flaper87)registry's v1 forced is_public to True
|
||||||
@ -826,7 +827,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -875,7 +876,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -923,7 +924,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -972,7 +973,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1017,7 +1018,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1069,7 +1070,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1121,7 +1122,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1188,7 +1189,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1202,7 +1203,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1269,7 +1270,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1283,7 +1284,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1297,7 +1298,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1311,7 +1312,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
}]
|
}]
|
||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
images = res_dict
|
images = res_dict
|
||||||
@ -1335,7 +1336,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
@ -1363,7 +1364,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
@ -1387,7 +1388,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
@ -1410,7 +1411,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
@ -1433,7 +1434,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
@ -1456,7 +1457,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
res_dict = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
@ -1483,7 +1484,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
self.assertEqual(error_cls, res_dict['_error']['cls'])
|
self.assertEqual(error_cls, res_dict['_error']['cls'])
|
||||||
return res_dict
|
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)
|
code, res_dict = self._send_request(command, kwargs)
|
||||||
self.assertEqual(expected_status, code)
|
self.assertEqual(expected_status, code)
|
||||||
return res_dict
|
return res_dict
|
||||||
@ -1558,7 +1559,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
res_dict = jsonutils.loads(res.body)[0]
|
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)
|
orig_num_images = len(res_dict)
|
||||||
|
|
||||||
@ -1570,7 +1571,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
self.assertEqual(200, res.status_int)
|
self.assertEqual(http.OK, res.status_int)
|
||||||
|
|
||||||
# Verify one less image
|
# Verify one less image
|
||||||
cmd = [{
|
cmd = [{
|
||||||
@ -1580,7 +1581,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
res_dict = jsonutils.loads(res.body)[0]
|
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)
|
new_num_images = len(res_dict)
|
||||||
self.assertEqual(new_num_images, orig_num_images - 1)
|
self.assertEqual(new_num_images, orig_num_images - 1)
|
||||||
@ -1598,7 +1599,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
res = req.get_response(self.api)
|
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]
|
deleted_image = jsonutils.loads(res.body)[0]
|
||||||
|
|
||||||
self.assertEqual(image['id'], deleted_image['id'])
|
self.assertEqual(image['id'], deleted_image['id'])
|
||||||
@ -1616,7 +1617,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
|||||||
req.body = jsonutils.dump_as_bytes(cmd)
|
req.body = jsonutils.dump_as_bytes(cmd)
|
||||||
|
|
||||||
res = req.get_response(self.api)
|
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]
|
memb_list = jsonutils.loads(res.body)[0]
|
||||||
self.assertEqual(0, len(memb_list))
|
self.assertEqual(0, len(memb_list))
|
||||||
|
@ -20,6 +20,7 @@ import uuid
|
|||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from six.moves import http_client as http
|
||||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
import webob
|
import webob
|
||||||
@ -811,7 +812,7 @@ class TestTasksSerializer(test_utils.BaseTestCase):
|
|||||||
self.serializer.create(response, self.fixtures[3])
|
self.serializer.create(response, self.fixtures[3])
|
||||||
|
|
||||||
serialized_task = jsonutils.loads(response.body)
|
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,
|
self.assertEqual(self.fixtures[3].task_id,
|
||||||
serialized_task['id'])
|
serialized_task['id'])
|
||||||
self.assertEqual(self.fixtures[3].task_input,
|
self.assertEqual(self.fixtures[3].task_input,
|
||||||
@ -825,7 +826,7 @@ class TestTasksSerializer(test_utils.BaseTestCase):
|
|||||||
self.serializer.create(response, self.fixtures[0])
|
self.serializer.create(response, self.fixtures[0])
|
||||||
|
|
||||||
serialized_task = jsonutils.loads(response.body)
|
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,
|
self.assertEqual(self.fixtures[0].task_id,
|
||||||
serialized_task['id'])
|
serialized_task['id'])
|
||||||
self.assertEqual(self.fixtures[0].task_input,
|
self.assertEqual(self.fixtures[0].task_input,
|
||||||
@ -838,7 +839,7 @@ class TestTasksSerializer(test_utils.BaseTestCase):
|
|||||||
self.serializer.create(response, self.fixtures[1])
|
self.serializer.create(response, self.fixtures[1])
|
||||||
|
|
||||||
serialized_task = jsonutils.loads(response.body)
|
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,
|
self.assertEqual(self.fixtures[1].task_id,
|
||||||
serialized_task['id'])
|
serialized_task['id'])
|
||||||
self.assertEqual(self.fixtures[1].task_input,
|
self.assertEqual(self.fixtures[1].task_input,
|
||||||
|
@ -31,6 +31,7 @@ from oslo_serialization import jsonutils
|
|||||||
from oslotest import moxstubout
|
from oslotest import moxstubout
|
||||||
import six
|
import six
|
||||||
from six.moves import BaseHTTPServer
|
from six.moves import BaseHTTPServer
|
||||||
|
from six.moves import http_client as http
|
||||||
import testtools
|
import testtools
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
@ -437,7 +438,7 @@ def start_http_server(image_id, image_data):
|
|||||||
def _get_http_handler_class(fixture):
|
def _get_http_handler_class(fixture):
|
||||||
class StaticHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
class StaticHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
self.send_response(200)
|
self.send_response(http.OK)
|
||||||
self.send_header('Content-Length', str(len(fixture)))
|
self.send_header('Content-Length', str(len(fixture)))
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(fixture)
|
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
|
# reserve non_existing_image_path for the cases where we expect
|
||||||
# 404 from the server
|
# 404 from the server
|
||||||
if 'non_existing_image_path' in self.path:
|
if 'non_existing_image_path' in self.path:
|
||||||
self.send_response(404)
|
self.send_response(http.NOT_FOUND)
|
||||||
else:
|
else:
|
||||||
self.send_response(200)
|
self.send_response(http.OK)
|
||||||
self.send_header('Content-Length', str(len(fixture)))
|
self.send_header('Content-Length', str(len(fixture)))
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
return
|
return
|
||||||
@ -574,7 +575,8 @@ class FakeAuthMiddleware(wsgi.Middleware):
|
|||||||
|
|
||||||
|
|
||||||
class FakeHTTPResponse(object):
|
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'
|
data = data or b'I am a teapot, short and stout\n'
|
||||||
self.data = six.BytesIO(data)
|
self.data = six.BytesIO(data)
|
||||||
self.read = self.data.read
|
self.read = self.data.read
|
||||||
|
Loading…
Reference in New Issue
Block a user