diff --git a/glance/tests/functional/db/test_rpc_endpoint.py b/glance/tests/functional/db/test_rpc_endpoint.py index c6c81df13c..13f1b23f5f 100644 --- a/glance/tests/functional/db/test_rpc_endpoint.py +++ b/glance/tests/functional/db/test_rpc_endpoint.py @@ -15,6 +15,7 @@ from oslo_serialization import jsonutils import requests +from six.moves import http_client as http from glance.tests import functional @@ -42,7 +43,7 @@ class TestRegistryURLVisibility(functional.FunctionalTest): path = self._url('/rpc') response = requests.post(path, headers=self._headers(), data=self.req_body) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) self.stop_servers() def test_v2_enabled(self): @@ -51,5 +52,5 @@ class TestRegistryURLVisibility(functional.FunctionalTest): path = self._url('/rpc') response = requests.post(path, headers=self._headers(), data=self.req_body) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.stop_servers() diff --git a/glance/tests/functional/glare/test_glare.py b/glance/tests/functional/glare/test_glare.py index 86eb524f57..7605d037b6 100644 --- a/glance/tests/functional/glare/test_glare.py +++ b/glance/tests/functional/glare/test_glare.py @@ -19,6 +19,7 @@ import mock from oslo_serialization import jsonutils import pkg_resources import requests +from six.moves import http_client as http from glance.api.glare.v0_1 import glare from glance.api.glare.v0_1 import router @@ -182,7 +183,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory super(TestArtifacts, self).start_servers(**kwargs) def _create_artifact(self, type_name, type_version='1.0', data=None, - status=201): + status=http.CREATED): # create an artifact first artifact_data = data or {'name': 'artifact-1', 'version': '12'} @@ -190,7 +191,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory type_version), artifact_data, status=status) - def _check_artifact_method(self, method, url, data=None, status=200, + def _check_artifact_method(self, method, url, data=None, status=http.OK, headers=None): if not headers: headers = self._headers() @@ -202,13 +203,13 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory response = getattr(requests, method)(self._url(url), headers=headers, data=data) self.assertEqual(status, response.status_code) - if status >= 400: + if status >= http.BAD_REQUEST: return response.text if "application/json" in response.headers["content-type"]: return jsonutils.loads(response.text) return response.text - def _check_artifact_post(self, url, data, status=201, + def _check_artifact_post(self, url, data, status=http.CREATED, headers=None): if headers is None: headers = {'Content-Type': 'application/json'} @@ -216,20 +217,20 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory return self._check_artifact_method("post", url, data, status=status, headers=headers) - def _check_artifact_get(self, url, status=200): + def _check_artifact_get(self, url, status=http.OK): return self._check_artifact_method("get", url, status=status) - def _check_artifact_delete(self, url, status=204): + def _check_artifact_delete(self, url, status=http.NO_CONTENT): response = requests.delete(self._url(url), headers=self._headers()) self.assertEqual(status, response.status_code) return response.text - def _check_artifact_patch(self, url, data, status=200, + def _check_artifact_patch(self, url, data, status=http.OK, headers={'Content-Type': 'application/json'}): return self._check_artifact_method("patch", url, data, status=status, headers=headers) - def _check_artifact_put(self, url, data, status=200, + def _check_artifact_put(self, url, data, status=http.OK, headers={'Content-Type': 'application/json'}): return self._check_artifact_method("put", url, data, status=status, headers=headers) @@ -268,7 +269,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory '/noprop/v1.0/drafts')["artifacts"] self.assertEqual(1, len(list_creating)) bad_version = self._check_artifact_get('/noprop/v1.0bad', - status=400) + status=http.BAD_REQUEST) self.assertIn("Invalid version string: u'1.0bad'", bad_version) def test_list_artifacts_with_pagination(self): @@ -313,7 +314,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory a wrong version should result in 400 BadRequest 'No such plugin has been loaded' """ - msg = self._check_artifact_get('/noprop/v0.0.9', 400) + msg = self._check_artifact_get('/noprop/v0.0.9', http.BAD_REQUEST) self.assertIn("No plugin for 'noprop v 0.0.9' has been loaded", msg) @@ -386,11 +387,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory artifact_id = art['id'] # 'hui' is invalid show level self._check_artifact_get( - '/noprop/%s?show_level=yoba' % artifact_id, status=400) + '/noprop/%s?show_level=yoba' % artifact_id, + status=http.BAD_REQUEST) def test_get_artifact_no_such_id(self): msg = self._check_artifact_get( - '/noprop/%s' % str(uuid.uuid4()), status=404) + '/noprop/%s' % str(uuid.uuid4()), status=http.NOT_FOUND) self.assertIn('No artifact found with ID', msg) def test_get_artifact_present_id_wrong_type(self): @@ -402,11 +404,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory art2 = self._create_artifact('noprop') # ok id and type_name but bad type_version should result in 404 self._check_artifact_get('/noprop/v0.5/%s' % str(art2['id']), - status=404) + status=http.NOT_FOUND) # try to access art2 by supplying art1.type and art2.id self._check_artifact_get('/withprops/%s' % str(art2['id']), - status=404) - self._check_artifact_get('/noprop/%s' % str(art1['id']), status=404) + status=http.NOT_FOUND) + self._check_artifact_get('/noprop/%s' % str(art1['id']), + status=http.NOT_FOUND) def test_delete_artifact(self): artifact_data = {'name': 'artifact-1', @@ -416,12 +419,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory art1 = self._create_artifact('withprops', data=artifact_data) self._check_artifact_delete('/withprops/v1.0/%s' % art1['id']) art1_deleted = self._check_artifact_get('/withprops/%s' % art1['id'], - status=404) + status=http.NOT_FOUND) self.assertIn('No artifact found with ID', art1_deleted) def test_delete_artifact_no_such_id(self): self._check_artifact_delete('/noprop/v1/%s' % str(uuid.uuid4()), - status=404) + status=http.NOT_FOUND) @unittest.skip("Test is unstable") def test_delete_artifact_with_dependency(self): @@ -441,7 +444,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory self.assertEqual(1, len(art_updated['depends_on_list'])) # try to delete an artifact prior to its dependency res = self._check_artifact_delete('/withprops/v1/%s' % art['id'], - status=400) + status=http.BAD_REQUEST) self.assertIn( "Dependency property 'depends_on' has to be deleted first", res) # delete a dependency @@ -450,7 +453,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory data=[{'op': 'remove', 'path': '/depends_on'}]) # try to delete prior to deleting artifact_list dependencies res = self._check_artifact_delete('/withprops/v1/%s' % art['id'], - status=400) + status=http.BAD_REQUEST) self.assertIn( "Dependency property 'depends_on_list' has to be deleted first", res) @@ -466,7 +469,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory headers = self._headers({'Content-Type': 'application/octet-stream'}) self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'], headers=headers, - data='ZZZZZ', status=200) + data='ZZZZZ', status=http.OK) self._check_artifact_delete('/withblob/v1/%s' % art['id']) def test_update_nonexistent_property_by_replace_op(self): @@ -477,7 +480,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory result = self._check_artifact_patch('/withprops/v1/%s' % art['id'], data=data, - status=400) + status=http.BAD_REQUEST) self.assertIn('400 Bad Request', result) self.assertIn('Artifact has no property nonexistent_property', result) @@ -489,7 +492,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory result = self._check_artifact_patch('/withprops/v1/%s' % art['id'], data=data, - status=400) + status=http.BAD_REQUEST) self.assertIn('400 Bad Request', result) self.assertIn('Artifact has no property nonexistent_property', result) @@ -554,7 +557,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory 'path': '/dict_prop/foo'}] art_updated = self._check_artifact_patch('/withprops/v1/%s' % art['id'], - data=data, status=400) + data=data, + status=http.BAD_REQUEST) self.assertIn("The provided path 'dict_prop/foo' is invalid", art_updated) @@ -564,7 +568,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory data = [{'op': 'remove', 'path': '/dict_prop/bar_list'}] art_updated = self._check_artifact_patch('/withprops/v1/%s' % art['id'], - data=data, status=400) + data=data, + status=http.BAD_REQUEST) self.assertIn("The provided path 'dict_prop/bar_list' is invalid", art_updated) @@ -654,7 +659,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory art_updated = self._check_artifact_patch('/withprops/v1/%s' % art['id'], data=bad_index_data, - status=400) + status=http.BAD_REQUEST) self.assertIn("The provided path 'prop_list/11' is invalid", art_updated) @@ -723,7 +728,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory data = [{'op': 'remove', 'value': 'some value', 'path': '/non-existent-path/and-another'}] art_updated = self._check_artifact_patch( - '/withprops/v1/%s' % art['id'], data=data, status=400) + '/withprops/v1/%s' % art['id'], data=data, + status=http.BAD_REQUEST) self.assertIn('Artifact has no property', art_updated) def test_update_replace_non_existent_artifact_properties(self): @@ -733,7 +739,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory data = [{'op': 'replace', 'value': 'some value', 'path': '/non-existent-path/and-another'}] art_updated = self._check_artifact_patch( - '/withprops/v1/%s' % art['id'], data=data, status=400) + '/withprops/v1/%s' % art['id'], data=data, + status=http.BAD_REQUEST) self.assertIn('Artifact has no property', art_updated) def test_update_artifact_remove_property(self): @@ -756,7 +763,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory self.assertIsNone(art[prop]) data = [{'op': 'replace', 'value': 123, 'path': '/prop1'}] art_updated = self._check_artifact_patch( - '/withprops/v1/%s' % art['id'], data=data, status=400) + '/withprops/v1/%s' % art['id'], data=data, status=http.BAD_REQUEST) self.assertIn("Property 'prop1' may not have value '123'", art_updated) def test_update_multiple_properties(self): @@ -798,7 +805,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory 'withprops', data={"name": "name", "version": "42", "depends_on_list": [no_prop_art['id'], - no_prop_art['id']]}, status=400) + no_prop_art['id']]}, + status=http.BAD_REQUEST) self.assertIn("Items have to be unique", res) def test_create_artifact_bad_dependency_format(self): @@ -812,12 +820,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory art = self._check_artifact_post( '/withprops/v1/drafts', {"name": "name", "version": "42", - "depends_on": [no_prop_art['id']]}, status=400) + "depends_on": [no_prop_art['id']]}, status=http.BAD_REQUEST) self.assertIn('Not a valid value type', art) art = self._check_artifact_post( '/withprops/v1.0/drafts', {"name": "name", "version": "42", - "depends_on_list": no_prop_art['id']}, status=400) + "depends_on_list": no_prop_art['id']}, status=http.BAD_REQUEST) self.assertIn('object is not iterable', art) def test_update_dependency(self): @@ -846,7 +854,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory 'path': '/depends_on', 'value': [with_prop_art['id']]}] not_updated = self._check_artifact_patch( - '/withprops/v1/%s' % with_prop_art['id'], data=data, status=400) + '/withprops/v1/%s' % with_prop_art['id'], data=data, + status=http.BAD_REQUEST) self.assertIn('Artifact with a circular dependency can not be created', not_updated) @@ -862,14 +871,15 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory self.assertNotEqual(0, len(art_updated['depends_on'])) # artifact can't be published if any dependency is in non-active state res = self._check_artifact_post( - '/withprops/v1/%s/publish' % art['id'], {}, status=400) + '/withprops/v1/%s/publish' % art['id'], {}, + status=http.BAD_REQUEST) self.assertIn("Not all dependencies are in 'active' state", res) # after you publish the dependency -> artifact can be published dep_published = self._check_artifact_post( - '/noprop/v1/%s/publish' % no_prop_art['id'], {}, status=200) + '/noprop/v1/%s/publish' % no_prop_art['id'], {}, status=http.OK) self.assertEqual('active', dep_published['state']) art_published = self._check_artifact_post( - '/withprops/v1.0/%s/publish' % art['id'], {}, status=200) + '/withprops/v1.0/%s/publish' % art['id'], {}, status=http.OK) self.assertEqual('active', art_published['state']) def test_no_mutable_change_in_published_state(self): @@ -891,25 +901,26 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory self.assertEqual(no_prop_other['id'], art_updated['depends_on']['id']) # publish dependency dep_published = self._check_artifact_post( - '/noprop/v1/%s/publish' % no_prop_other['id'], {}, status=200) + '/noprop/v1/%s/publish' % no_prop_other['id'], {}, status=http.OK) self.assertEqual('active', dep_published['state']) # publish artifact art_published = self._check_artifact_post( - '/withprops/v1.0/%s/publish' % art['id'], {}, status=200) + '/withprops/v1.0/%s/publish' % art['id'], {}, status=http.OK) self.assertEqual('active', art_published['state']) # try to change dependency, should fail as already published res = self._check_artifact_patch( '/withprops/v1/%s' % art_published['id'], - data=[{'op': 'remove', 'path': '/depends_on'}], status=400) + data=[{'op': 'remove', 'path': '/depends_on'}], + status=http.BAD_REQUEST) self.assertIn('Attempt to set value of immutable property', res) def test_create_artifact_empty_body(self): - self._check_artifact_post('/noprop/v1.0/drafts', {}, 400) + self._check_artifact_post('/noprop/v1.0/drafts', {}, http.BAD_REQUEST) def test_create_artifact_insufficient_arguments(self): self._check_artifact_post('/noprop/v1.0/drafts', {'name': 'some name, no version'}, - status=400) + status=http.BAD_REQUEST) def test_create_artifact_no_such_version(self): """Creation impossible without specifying a correct version. @@ -919,12 +930,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory 400 BadRequest 'No such plugin has been loaded' """ # make sure there is no such artifact noprop - self._check_artifact_get('/noprop/v0.0.9', 400) + self._check_artifact_get('/noprop/v0.0.9', http.BAD_REQUEST) artifact_data = {'name': 'artifact-1', 'version': '12'} msg = self._check_artifact_post('/noprop/v0.0.9/drafts', artifact_data, - status=400) + status=http.BAD_REQUEST) self.assertIn("No plugin for 'noprop v 0.0.9' has been loaded", msg) @@ -936,7 +947,8 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory """ artifact_data = {'name': 'artifact-1', 'version': '12'} - self._check_artifact_post('/noprop/drafts', artifact_data, 404) + self._check_artifact_post('/noprop/drafts', artifact_data, + http.NOT_FOUND) def test_create_artifact_no_properties(self): """Create an artifact with minimum parameters""" @@ -1022,13 +1034,13 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory 'prop1': 1} res = self._check_artifact_post('/withprops/v1.0/drafts', artifact_data, - status=400) + status=http.BAD_REQUEST) self.assertIn("Property 'prop1' may not have value '1'", res) artifact_data.pop('prop1') artifact_data['nosuchprop'] = "Random" res = self._check_artifact_post('/withprops/v1.0/drafts', artifact_data, - status=400) + status=http.BAD_REQUEST) self.assertIn("Artifact has no property nosuchprop", res) def test_create_public_artifact(self): @@ -1059,18 +1071,18 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory headers = self._headers({'Content-Type': 'application/octet-stream'}) self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'], headers=headers, - data='ZZZZZ', status=200) + data='ZZZZZ', status=http.OK) def test_upload_file_with_invalid_content_type(self): art = self._create_artifact('withblob') data = {'data': 'jjjjjj'} res = self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'], - data=data, status=400) + data=data, status=http.BAD_REQUEST) self.assertIn('Invalid Content-Type for work with blob1', res) res = self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'], - data=data, status=400) + data=data, status=http.BAD_REQUEST) self.assertIn('Invalid Content-Type for work with blob_list', res) def test_upload_list_files(self): @@ -1078,10 +1090,10 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory headers = self._headers({'Content-Type': 'application/octet-stream'}) self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'], headers=headers, - data='ZZZZZ', status=200) + data='ZZZZZ', status=http.OK) self._check_artifact_post('/withblob/v1/%s/blob_list' % art['id'], headers=headers, - data='YYYYY', status=200) + data='YYYYY', status=http.OK) def test_download_file(self): # Download some data from an artifact @@ -1090,7 +1102,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory headers = self._headers({'Content-Type': 'application/octet-stream'}) self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'], headers=headers, - data='ZZZZZ', status=200) + data='ZZZZZ', status=http.OK) art = self._check_artifact_get('/withblob/%s' % artifact_id) self.assertEqual(artifact_id, art['id']) @@ -1113,7 +1125,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory headers = self._headers({'Content-Type': 'application/octet-stream'}) self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'], headers=headers, - data=iterate_string('ZZZZZ'), status=200) + data=iterate_string('ZZZZZ'), status=http.OK) art = self._check_artifact_get('/withblob/%s' % artifact_id) self.assertEqual(artifact_id, art['id']) @@ -1212,12 +1224,12 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory # append to list property via POST upd = self._check_artifact_post( '/withprops/v1.0/%s/prop_list' % art['id'], data={'data': [11]}, - status=200) + status=http.OK) self.assertEqual([11], upd['prop_list']) # append to list property via POST upd = self._check_artifact_post( '/withprops/v1.0/%s/prop_list/-' % art['id'], - status=200, data={'data': 10}) + status=http.OK, data={'data': 10}) self.assertEqual([11, 10], upd['prop_list']) def test_bad_update_property(self): @@ -1227,22 +1239,23 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory # try to update nonexistent property upd = self._check_artifact_put( '/withprops/v1.0/%s/nosuchprop' % art['id'], - data={'data': 'wont be set'}, status=400) + data={'data': 'wont be set'}, status=http.BAD_REQUEST) self.assertIn('Artifact has no property nosuchprop', upd) # try to pass wrong property value upd = self._check_artifact_put( '/withprops/v1.0/%s/tuple_prop' % art['id'], - data={'data': ['should be an int', False]}, status=400) + data={'data': ['should be an int', False]}, + status=http.BAD_REQUEST) self.assertIn("Property 'tuple_prop[0]' may not have value", upd) # try to pass bad body (not a valid json) upd = self._check_artifact_put( '/withprops/v1.0/%s/tuple_prop' % art['id'], data="not a json", - status=400) + status=http.BAD_REQUEST) self.assertIn("Invalid json body", upd) # try to pass json body invalid under schema upd = self._check_artifact_put( '/withprops/v1.0/%s/tuple_prop' % art['id'], - data={"bad": "schema"}, status=400) + data={"bad": "schema"}, status=http.BAD_REQUEST) self.assertIn("Invalid json body", upd) def test_update_different_depths_levels(self): @@ -1251,36 +1264,36 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory art = self._create_artifact('withprops', data=data) upd = self._check_artifact_post( '/withprops/v1.0/%s/dict_prop' % art['id'], - data={'data': {'foo': 'some value'}}, status=200) + data={'data': {'foo': 'some value'}}, status=http.OK) self.assertEqual({'foo': 'some value'}, upd['dict_prop']) upd = self._check_artifact_post( '/withprops/v1.0/%s/dict_prop/bar_list' % art['id'], - data={'data': [5]}, status=200) + data={'data': [5]}, status=http.OK) self.assertEqual({'foo': 'some value', 'bar_list': [5]}, upd['dict_prop']) upd = self._check_artifact_post( '/withprops/v1.0/%s/dict_prop/bar_list/0' % art['id'], - data={'data': 15}, status=200) + data={'data': 15}, status=http.OK) self.assertEqual({'foo': 'some value', 'bar_list': [5, 15]}, upd['dict_prop']) # try to attempt dict_property by nonexistent path upd = self._check_artifact_post( '/withprops/v1.0/%s/dict_prop/bar_list/nosuchkey' % art['id'], - data={'data': 15}, status=400) + data={'data': 15}, status=http.BAD_REQUEST) def test_artifact_inaccessible_by_different_user(self): data = {'name': 'an artifact', 'version': '42'} art = self._create_artifact('withprops', data=data) self._set_user('user2') - self._check_artifact_get('/withprops/%s' % art['id'], 404) + self._check_artifact_get('/withprops/%s' % art['id'], http.NOT_FOUND) def test_artifact_accessible_by_admin(self): data = {'name': 'an artifact', 'version': '42'} art = self._create_artifact('withprops', data=data) self._set_user('admin') - self._check_artifact_get('/withprops/%s' % art['id'], 200) + self._check_artifact_get('/withprops/%s' % art['id'], http.OK) def test_public_artifact_accessible_by_different_user(self): data = {'name': 'an artifact', @@ -1290,7 +1303,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory '/withprops/v1.0/%s' % art['id'], data=[{'op': 'replace', 'value': 'public', 'path': '/visibility'}]) self._set_user('user2') - self._check_artifact_get('/withprops/%s' % art['id'], 200) + self._check_artifact_get('/withprops/%s' % art['id'], http.OK) def test_public_artifact_not_editable_by_different_user(self): data = {'name': 'an artifact', @@ -1303,7 +1316,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory self._check_artifact_patch( '/withprops/v1.0/%s' % art['id'], data=[{'op': 'replace', 'value': 'private', - 'path': '/visibility'}], status=403) + 'path': '/visibility'}], status=http.FORBIDDEN) def test_public_artifact_editable_by_admin(self): data = {'name': 'an artifact', @@ -1316,7 +1329,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory self._check_artifact_patch( '/withprops/v1.0/%s' % art['id'], data=[{'op': 'replace', 'value': 'private', - 'path': '/visibility'}], status=200) + 'path': '/visibility'}], status=http.OK) def test_list_artifact_types(self): actual = { @@ -1347,7 +1360,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory u'http://127.0.0.1:%d/v0.1/artifacts/withprops/v1.0' % self.api_port}]}]} - response = self._check_artifact_get("", status=200) + response = self._check_artifact_get("", status=http.OK) response[u'artifact_types'].sort(key=lambda x: x[u'type_name']) for artifact_type in response[u'artifact_types']: artifact_type[u'versions'].sort(key=lambda x: x[u'id']) @@ -1358,7 +1371,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory data = {'name': 'name1', 'version': '2.2'} self._check_artifact_post('/withprops/v1.0/drafts', data=data, - status=400, + status=http.BAD_REQUEST, headers={'Content-Type': 'lalala'}) def test_filter_by_non_dict_props(self): @@ -1905,7 +1918,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory self.assertEqual(2, len(result)) url = '/withprops/v1.0/drafts?version=latest' - self._check_artifact_get(url=url, status=400) + self._check_artifact_get(url=url, status=http.BAD_REQUEST) def test_filter_by_version_only(self): data = {'name': 'art1', @@ -1942,7 +1955,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory result = self._check_artifact_patch( '/withblob/v1.0/%s' % art['id'], - status=400, + status=http.BAD_REQUEST, data=[{'op': 'replace', 'value': 'public', 'path': '/blob1'}]) @@ -1950,7 +1963,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory result = self._check_artifact_patch( '/withblob/v1.0/%s' % art['id'], - status=400, + status=http.BAD_REQUEST, data=[{'op': 'remove', 'value': 'public', 'path': '/blob1'}]) @@ -1958,7 +1971,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory result = self._check_artifact_patch( '/withblob/v1.0/%s' % art['id'], - status=400, + status=http.BAD_REQUEST, data=[{'op': 'add', 'value': 'public', 'path': '/blob1'}]) @@ -1970,7 +1983,7 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory 'Use semver notation') for bad_version in bad_versions: url = '/withprops/v1.0/drafts?version=gt:%s' % bad_version - result = self._check_artifact_get(url=url, status=400) + result = self._check_artifact_get(url=url, status=http.BAD_REQUEST) self.assertIn(response_string % bad_version, result) def test_circular_dependency(self): @@ -1980,6 +1993,6 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory upd = self._check_artifact_post( '/withprops/v1.0/%s/depends_on' % art['id'], - data={'data': art['id']}, status=400) + data={'data': art['id']}, status=http.BAD_REQUEST) self.assertIn( 'Artifact with a circular dependency can not be created', upd) diff --git a/glance/tests/functional/store_utils.py b/glance/tests/functional/store_utils.py index 49efd70dcf..e383d834c2 100644 --- a/glance/tests/functional/store_utils.py +++ b/glance/tests/functional/store_utils.py @@ -24,6 +24,7 @@ import threading from oslo_utils import units from six.moves import BaseHTTPServer +from six.moves import http_client as http FIVE_KB = 5 * units.Ki @@ -35,13 +36,13 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler): Respond to an image HEAD request fake metadata """ if 'images' in self.path: - self.send_response(200) + self.send_response(http.OK) self.send_header('Content-Type', 'application/octet-stream') self.send_header('Content-Length', FIVE_KB) self.end_headers() return else: - self.send_error(404, 'File Not Found: %s' % self.path) + self.send_error(http.NOT_FOUND, 'File Not Found: %s' % self.path) return def do_GET(self): @@ -49,7 +50,7 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler): Respond to an image GET request with fake image content. """ if 'images' in self.path: - self.send_response(200) + self.send_response(http.OK) self.send_header('Content-Type', 'application/octet-stream') self.send_header('Content-Length', FIVE_KB) self.end_headers() @@ -58,7 +59,7 @@ class RemoteImageHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.wfile.close() return else: - self.send_error(404, 'File Not Found: %s' % self.path) + self.send_error(http.NOT_FOUND, 'File Not Found: %s' % self.path) return def log_message(self, format, *args): diff --git a/glance/tests/functional/test_api.py b/glance/tests/functional/test_api.py index d72d599382..de0d1f0454 100644 --- a/glance/tests/functional/test_api.py +++ b/glance/tests/functional/test_api.py @@ -18,6 +18,7 @@ import httplib2 from oslo_serialization import jsonutils +from six.moves import http_client from glance.tests import functional @@ -73,7 +74,7 @@ class TestApiVersions(functional.FunctionalTest): path = 'http://%s:%d' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(versions_json, content) def test_v2_api_configuration(self): @@ -115,7 +116,7 @@ class TestApiVersions(functional.FunctionalTest): path = 'http://%s:%d' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(versions_json, content) def test_v1_api_configuration(self): @@ -142,7 +143,7 @@ class TestApiVersions(functional.FunctionalTest): path = 'http://%s:%d' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(versions_json, content) @@ -201,7 +202,7 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(self.versions_json, content) def test_get_images_path(self): @@ -211,7 +212,7 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(self.versions_json, content) def test_get_v1_images_path(self): @@ -221,7 +222,7 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d/v1/images' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) def test_get_root_path_with_unknown_header(self): """Assert GET / with Accept: unknown header @@ -232,7 +233,7 @@ class TestApiPaths(functional.FunctionalTest): http = httplib2.Http() headers = {'Accept': 'unknown'} response, content = http.request(path, 'GET', headers=headers) - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(self.versions_json, content) def test_get_root_path_with_openstack_header(self): @@ -243,7 +244,7 @@ class TestApiPaths(functional.FunctionalTest): http = httplib2.Http() headers = {'Accept': 'application/vnd.openstack.images-v1'} response, content = http.request(path, 'GET', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(self.images_json, content) def test_get_images_path_with_openstack_header(self): @@ -256,7 +257,7 @@ class TestApiPaths(functional.FunctionalTest): http = httplib2.Http() headers = {'Accept': 'application/vnd.openstack.compute-v1'} response, content = http.request(path, 'GET', headers=headers) - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(self.versions_json, content) def test_get_v10_images_path(self): @@ -266,7 +267,7 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) def test_get_v1a_images_path(self): """Assert GET /v1.a/images with no Accept: header @@ -275,7 +276,7 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) def test_get_va1_images_path(self): """Assert GET /va.1/images with no Accept: header @@ -284,7 +285,7 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d/va.1/images' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(self.versions_json, content) def test_get_versions_path(self): @@ -294,7 +295,7 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(self.versions_json, content) def test_get_versions_path_with_openstack_header(self): @@ -306,7 +307,7 @@ class TestApiPaths(functional.FunctionalTest): http = httplib2.Http() headers = {'Accept': 'application/vnd.openstack.images-v1'} response, content = http.request(path, 'GET', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(self.versions_json, content) def test_get_v1_versions_path(self): @@ -316,14 +317,14 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d/v1/versions' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) def test_get_versions_choices(self): """Verify version choices returned""" path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(self.versions_json, content) def test_get_images_path_with_openstack_v2_header(self): @@ -336,7 +337,7 @@ class TestApiPaths(functional.FunctionalTest): http = httplib2.Http() headers = {'Accept': 'application/vnd.openstack.images-v10'} response, content = http.request(path, 'GET', headers=headers) - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(self.versions_json, content) def test_get_v12_images_path(self): @@ -346,5 +347,5 @@ class TestApiPaths(functional.FunctionalTest): path = 'http://%s:%d/v1.2/images' % ('127.0.0.1', self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) self.assertEqual(self.versions_json, content) diff --git a/glance/tests/functional/test_bin_glance_cache_manage.py b/glance/tests/functional/test_bin_glance_cache_manage.py index f120f7b3df..1057b87f3e 100644 --- a/glance/tests/functional/test_bin_glance_cache_manage.py +++ b/glance/tests/functional/test_bin_glance_cache_manage.py @@ -23,6 +23,7 @@ import sys import httplib2 from oslo_serialization import jsonutils from oslo_utils import units +from six.moves import http_client # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range @@ -61,7 +62,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum']) @@ -144,7 +145,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest): ids[1]) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertTrue(self.is_image_cached(ids[1]), "%s is not cached." % ids[1]) diff --git a/glance/tests/functional/test_cache_middleware.py b/glance/tests/functional/test_cache_middleware.py index fafeca0fb3..847538ec2c 100644 --- a/glance/tests/functional/test_cache_middleware.py +++ b/glance/tests/functional/test_cache_middleware.py @@ -29,6 +29,7 @@ import time import httplib2 from oslo_serialization import jsonutils from oslo_utils import units +from six.moves import http_client # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range @@ -61,7 +62,7 @@ class BaseCacheMiddlewareTest(object): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum']) @@ -81,7 +82,7 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Verify image now in cache image_cached_path = os.path.join(self.api_server.image_cache_dir, @@ -111,7 +112,7 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertFalse(os.path.exists(image_cached_path)) @@ -136,7 +137,7 @@ class BaseCacheMiddlewareTest(object): response, content = http.request(path, 'POST', headers=headers, body=jsonutils.dumps(image_entity)) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['id'] @@ -147,7 +148,7 @@ class BaseCacheMiddlewareTest(object): response, content = http.request(path, 'PUT', headers=headers, body=image_data) - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) # Verify image not in cache image_cached_path = os.path.join(self.api_server.image_cache_dir, @@ -157,7 +158,7 @@ class BaseCacheMiddlewareTest(object): # Grab the image http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Verify image now in cache image_cached_path = os.path.join(self.api_server.image_cache_dir, @@ -169,7 +170,7 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) self.assertFalse(os.path.exists(image_cached_path)) @@ -195,7 +196,7 @@ class BaseCacheMiddlewareTest(object): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual(FIVE_KB, data['image']['size']) @@ -206,13 +207,13 @@ class BaseCacheMiddlewareTest(object): # Grab the image http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Grab the image again to ensure it can be served out from # cache with the correct size http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(FIVE_KB, int(response['content-length'])) self.stop_servers() @@ -233,7 +234,7 @@ class BaseCacheMiddlewareTest(object): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum']) @@ -257,7 +258,7 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Now, we delete the image from the server and verify that # the image cache no longer contains the deleted image @@ -265,7 +266,7 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertFalse(os.path.exists(image_cached_path)) @@ -293,7 +294,7 @@ class BaseCacheMiddlewareTest(object): response, content = http.request(path, 'POST', headers=headers, body=jsonutils.dumps(image_entity)) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['id'] @@ -304,7 +305,7 @@ class BaseCacheMiddlewareTest(object): response, content = http.request(path, 'PUT', headers=headers, body=image_data) - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) # Verify image not in cache image_cached_path = os.path.join(self.api_server.image_cache_dir, @@ -318,7 +319,7 @@ class BaseCacheMiddlewareTest(object): # Grab the image http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Now, we delete the image from the server and verify that # the image cache no longer contains the deleted image @@ -326,7 +327,7 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) self.assertFalse(os.path.exists(image_cached_path)) @@ -350,7 +351,7 @@ class BaseCacheMiddlewareTest(object): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum']) @@ -365,7 +366,7 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Verify image in cache image_cached_path = os.path.join(self.api_server.image_cache_dir, @@ -377,14 +378,14 @@ class BaseCacheMiddlewareTest(object): path = path % ("127.0.0.1", self.api_port, image_id) http = httplib2.Http() response, content = http.request(path, 'POST') - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) # Download the image with v1. Ensure it is forbidden path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Download the image with v2. This succeeds because # we are in admin context. @@ -392,28 +393,28 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Reactivate the image using v2 path = "http://%s:%d/v2/images/%s/actions/reactivate" path = path % ("127.0.0.1", self.api_port, image_id) http = httplib2.Http() response, content = http.request(path, 'POST') - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) # Download the image with v1. Ensure it is allowed path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Download the image with v2. Ensure it is allowed path = "http://%s:%d/v2/images/%s/file" % ("127.0.0.1", self.api_port, image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Now, we delete the image from the server and verify that # the image cache no longer contains the deleted image @@ -421,7 +422,7 @@ class BaseCacheMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertFalse(os.path.exists(image_cached_path)) @@ -436,7 +437,7 @@ class BaseCacheManageMiddlewareTest(object): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('images', data) self.assertEqual(0, len(data['images'])) @@ -453,7 +454,7 @@ class BaseCacheManageMiddlewareTest(object): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum']) @@ -469,7 +470,7 @@ class BaseCacheManageMiddlewareTest(object): path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('cached_images', data) @@ -493,13 +494,13 @@ class BaseCacheManageMiddlewareTest(object): image_id1) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Verify image now in cache path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('cached_images', data) @@ -516,27 +517,27 @@ class BaseCacheManageMiddlewareTest(object): path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Verify an unprivileged user cannot delete images from the cache path = "http://%s:%d/v1/cached_images/%s" % ("127.0.0.1", self.api_port, image_id1) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Verify an unprivileged user cannot delete all cached images path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Verify an unprivileged user cannot queue an image path = "http://%s:%d/v1/queued_images/%s" % ("127.0.0.1", self.api_port, image_id2) http = httplib2.Http() response, content = http.request(path, 'PUT') - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) self.stop_servers() @@ -561,13 +562,13 @@ class BaseCacheManageMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Verify image now in cache path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('cached_images', data) @@ -593,13 +594,13 @@ class BaseCacheManageMiddlewareTest(object): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Verify image hits increased in output of manage GET path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('cached_images', data) @@ -637,14 +638,14 @@ class BaseCacheManageMiddlewareTest(object): ids[x]) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status, + self.assertEqual(http_client.OK, response.status, "Failed to find image %s" % ids[x]) # Verify images now in cache path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('cached_images', data) @@ -661,12 +662,12 @@ class BaseCacheManageMiddlewareTest(object): self.api_port, ids[2]) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('cached_images', data) @@ -679,12 +680,12 @@ class BaseCacheManageMiddlewareTest(object): path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('cached_images', data) @@ -714,13 +715,13 @@ class BaseCacheManageMiddlewareTest(object): self.api_port, ids[x]) http = httplib2.Http() response, content = http.request(path, 'PUT') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Delete all queued images path = "http://%s:%d/v1/queued_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) num_deleted = data['num_deleted'] @@ -730,7 +731,7 @@ class BaseCacheManageMiddlewareTest(object): path = "http://%s:%d/v1/queued_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) num_deleted = data['num_deleted'] @@ -785,7 +786,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s self.api_port, ids[0]) http = httplib2.Http() response, content = http.request(path, 'PUT') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.verify_no_cached_images() @@ -801,7 +802,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertIn('cached_images', data) diff --git a/glance/tests/functional/test_client_exceptions.py b/glance/tests/functional/test_client_exceptions.py index 9576504c01..72489b9fc8 100644 --- a/glance/tests/functional/test_client_exceptions.py +++ b/glance/tests/functional/test_client_exceptions.py @@ -18,6 +18,7 @@ import eventlet.patcher import httplib2 +from six.moves import http_client import webob.dec import webob.exc @@ -46,14 +47,14 @@ class ExceptionTestApp(object): elif path == "/rate-limit-retry": request.response.retry_after = 10 - request.response.status = 413 + request.response.status = http_client.REQUEST_ENTITY_TOO_LARGE elif path == "/service-unavailable": request.response = webob.exc.HTTPServiceUnavailable() elif path == "/service-unavailable-retry": request.response.retry_after = 10 - request.response.status = 503 + request.response.status = http_client.SERVICE_UNAVAILABLE elif path == "/expectation-failed": request.response = webob.exc.HTTPExpectationFailed() @@ -134,4 +135,4 @@ class TestClientExceptions(functional.FunctionalTest): ('127.0.0.1', self.port)) response, content = http.request(path, 'GET') self.assertNotIn(b'ServerError', content) - self.assertEqual(500, response.status) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, response.status) diff --git a/glance/tests/functional/test_client_redirects.py b/glance/tests/functional/test_client_redirects.py index 9a34637ca9..1c2312623f 100644 --- a/glance/tests/functional/test_client_redirects.py +++ b/glance/tests/functional/test_client_redirects.py @@ -16,6 +16,7 @@ """Functional test cases testing glance client redirect-following.""" import eventlet.patcher +from six.moves import http_client as http import webob.dec import webob.exc @@ -97,7 +98,7 @@ class TestClientRedirects(functional.FunctionalTest): Test GET with no redirect """ response = self.client.do_request("GET", "/") - self.assertEqual(200, response.status) + self.assertEqual(http.OK, response.status) self.assertEqual("root", response.read()) def test_get_with_one_redirect(self): @@ -105,7 +106,7 @@ class TestClientRedirects(functional.FunctionalTest): Test GET with one 302 FOUND redirect """ response = self.client.do_request("GET", "/302") - self.assertEqual(200, response.status) + self.assertEqual(http.OK, response.status) self.assertEqual("success_from_host_one", response.read()) def test_get_with_one_redirect_query_string(self): @@ -114,7 +115,7 @@ class TestClientRedirects(functional.FunctionalTest): """ response = self.client.do_request("GET", "/302", params={'with_qs': 'yes'}) - self.assertEqual(200, response.status) + self.assertEqual(http.OK, response.status) self.assertEqual("success_with_qs", response.read()) def test_get_with_max_redirects(self): @@ -131,7 +132,7 @@ class TestClientRedirects(functional.FunctionalTest): Test POST with 302 redirect """ response = self.client.do_request("POST", "/302") - self.assertEqual(200, response.status) + self.assertEqual(http.OK, response.status) self.assertEqual("success_from_host_one", response.read()) def test_redirect_to_new_host(self): @@ -141,9 +142,9 @@ class TestClientRedirects(functional.FunctionalTest): url = "/redirect-to-%d" % self.port_two response = self.client.do_request("POST", url) - self.assertEqual(200, response.status) + self.assertEqual(http.OK, response.status) self.assertEqual("success_from_host_two", response.read()) response = self.client.do_request("POST", "/success") - self.assertEqual(200, response.status) + self.assertEqual(http.OK, response.status) self.assertEqual("success_from_host_one", response.read()) diff --git a/glance/tests/functional/test_cors_middleware.py b/glance/tests/functional/test_cors_middleware.py index 5484e2b786..5e65ffe8e4 100644 --- a/glance/tests/functional/test_cors_middleware.py +++ b/glance/tests/functional/test_cors_middleware.py @@ -15,6 +15,7 @@ """Tests cors middleware.""" import httplib2 +from six.moves import http_client from glance.tests import functional @@ -43,7 +44,7 @@ class TestCORSMiddleware(functional.FunctionalTest): 'Access-Control-Request-Method': 'GET' }) - self.assertEqual(200, r_headers.status) + self.assertEqual(http_client.OK, r_headers.status) self.assertIn('access-control-allow-origin', r_headers) self.assertEqual('http://valid.example.com', r_headers['access-control-allow-origin']) @@ -57,7 +58,7 @@ class TestCORSMiddleware(functional.FunctionalTest): 'Access-Control-Request-Method': 'GET' }) - self.assertEqual(200, r_headers.status) + self.assertEqual(http_client.OK, r_headers.status) self.assertNotIn('access-control-allow-origin', r_headers) def test_valid_cors_get_request(self): @@ -68,7 +69,7 @@ class TestCORSMiddleware(functional.FunctionalTest): 'Origin': 'http://valid.example.com' }) - self.assertEqual(200, r_headers.status) + self.assertEqual(http_client.OK, r_headers.status) self.assertIn('access-control-allow-origin', r_headers) self.assertEqual('http://valid.example.com', r_headers['access-control-allow-origin']) @@ -81,5 +82,5 @@ class TestCORSMiddleware(functional.FunctionalTest): 'Origin': 'http://invalid.example.com' }) - self.assertEqual(200, r_headers.status) + self.assertEqual(http_client.OK, r_headers.status) self.assertNotIn('access-control-allow-origin', r_headers) diff --git a/glance/tests/functional/test_healthcheck_middleware.py b/glance/tests/functional/test_healthcheck_middleware.py index ded5f2647d..9d2f496c8f 100644 --- a/glance/tests/functional/test_healthcheck_middleware.py +++ b/glance/tests/functional/test_healthcheck_middleware.py @@ -18,6 +18,7 @@ import tempfile import httplib2 +from six.moves import http_client from glance.tests import functional from glance.tests import utils @@ -37,7 +38,7 @@ class HealthcheckMiddlewareTest(functional.FunctionalTest): response, content = self.request() self.assertEqual('OK', content) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.stop_servers() @@ -49,6 +50,6 @@ class HealthcheckMiddlewareTest(functional.FunctionalTest): response, content = self.request() self.assertEqual('DISABLED BY FILE', content) - self.assertEqual(503, response.status) + self.assertEqual(http_client.SERVICE_UNAVAILABLE, response.status) self.stop_servers() diff --git a/glance/tests/functional/test_logging.py b/glance/tests/functional/test_logging.py index cb3008b460..ecb1010bf6 100644 --- a/glance/tests/functional/test_logging.py +++ b/glance/tests/functional/test_logging.py @@ -19,6 +19,7 @@ import os import stat import httplib2 +from six.moves import http_client as http from glance.tests import functional @@ -89,7 +90,7 @@ class TestLogging(functional.FunctionalTest): path = "http://%s:%d/" % ("127.0.0.1", self.api_port) response, content = httplib2.Http().request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http.MULTIPLE_CHOICES, response.status) self.assertNotEmptyFile(self.api_server.log_file) diff --git a/glance/tests/functional/test_reload.py b/glance/tests/functional/test_reload.py index 6be842eeab..4c7acfb1a0 100644 --- a/glance/tests/functional/test_reload.py +++ b/glance/tests/functional/test_reload.py @@ -19,6 +19,7 @@ import time import psutil import requests +from six.moves import http_client as http from glance.tests import functional from glance.tests.utils import execute @@ -143,7 +144,7 @@ class TestReload(functional.FunctionalTest): # This recycles the existing socket path = self._url('http', '/') response = requests.get(path) - self.assertEqual(300, response.status_code) + self.assertEqual(http.MULTIPLE_CHOICES, response.status_code) del response # close socket so that process audit is reliable pre_pids['api'] = self._get_children('api') @@ -163,7 +164,7 @@ class TestReload(functional.FunctionalTest): ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt') path = self._url('https', '/') response = requests.get(path, verify=ca_file) - self.assertEqual(300, response.status_code) + self.assertEqual(http.MULTIPLE_CHOICES, response.status_code) del response # Test https restart @@ -181,7 +182,7 @@ class TestReload(functional.FunctionalTest): ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt') path = self._url('https', '/') response = requests.get(path, verify=ca_file) - self.assertEqual(300, response.status_code) + self.assertEqual(http.MULTIPLE_CHOICES, response.status_code) del response # Test changing the https bind_host @@ -199,7 +200,7 @@ class TestReload(functional.FunctionalTest): path = self._url('https', '/') response = requests.get(path, verify=ca_file) - self.assertEqual(300, response.status_code) + self.assertEqual(http.MULTIPLE_CHOICES, response.status_code) del response # Test https -> http @@ -218,7 +219,7 @@ class TestReload(functional.FunctionalTest): path = self._url('http', '/') response = requests.get(path) - self.assertEqual(300, response.status_code) + self.assertEqual(http.MULTIPLE_CHOICES, response.status_code) del response # Test changing the http bind_host @@ -236,7 +237,7 @@ class TestReload(functional.FunctionalTest): path = self._url('http', '/') response = requests.get(path) - self.assertEqual(300, response.status_code) + self.assertEqual(http.MULTIPLE_CHOICES, response.status_code) del response # Test logging configuration change diff --git a/glance/tests/functional/test_scrubber.py b/glance/tests/functional/test_scrubber.py index 5bcfe1f6f2..8ddae8b70e 100644 --- a/glance/tests/functional/test_scrubber.py +++ b/glance/tests/functional/test_scrubber.py @@ -20,6 +20,7 @@ import time import httplib2 from oslo_serialization import jsonutils from oslo_utils import units +from six.moves import http_client # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range @@ -60,16 +61,16 @@ class TestScrubber(functional.FunctionalTest): metadata_encryption_key='') path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) response, content = self._send_http_request(path, 'POST', body='XXX') - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('active', image['status']) path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, image['id']) response, content = self._send_http_request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) response, content = self._send_http_request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('pending_delete', response['x-image-meta-status']) self.wait_for_scrub(path) @@ -106,7 +107,7 @@ class TestScrubber(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', body='XXX', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('active', image['status']) image_id = image['id'] @@ -115,10 +116,10 @@ class TestScrubber(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE', headers=base_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) response, content = http.request(path, 'HEAD', headers=base_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('pending_delete', response['x-image-meta-status']) self.wait_for_scrub(path, headers=base_headers) @@ -136,17 +137,17 @@ class TestScrubber(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) response, content = self._send_http_request(path, 'POST', body='XXX') - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('active', image['status']) path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, image['id']) response, content = self._send_http_request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) response, content = self._send_http_request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('pending_delete', response['x-image-meta-status']) # wait for the scrub time on the image to pass @@ -193,7 +194,7 @@ class TestScrubber(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', body='XXX', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('active', image['status']) image_id = image['id'] @@ -202,10 +203,10 @@ class TestScrubber(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE', headers=base_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) response, content = http.request(path, 'HEAD', headers=base_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('pending_delete', response['x-image-meta-status']) # wait for the scrub time on the image to pass @@ -240,7 +241,7 @@ class TestScrubber(functional.FunctionalTest): # add an image path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) response, content = self._send_http_request(path, 'POST', body='XXX') - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('active', image['status']) @@ -248,11 +249,11 @@ class TestScrubber(functional.FunctionalTest): path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, image['id']) response, content = self._send_http_request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # ensure the image is marked pending delete response, content = self._send_http_request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('pending_delete', response['x-image-meta-status']) # Remove the file from the backend. diff --git a/glance/tests/functional/test_ssl.py b/glance/tests/functional/test_ssl.py index d91e176bbf..7b584c2def 100644 --- a/glance/tests/functional/test_ssl.py +++ b/glance/tests/functional/test_ssl.py @@ -16,6 +16,7 @@ import os import httplib2 +from six.moves import http_client as http from glance.tests import functional @@ -79,4 +80,4 @@ class TestSSL(functional.FunctionalTest): path = "https://%s:%d/versions" % ("127.0.0.1", self.api_port) https = httplib2.Http(ca_certs=self.ca_file) response, content = https.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http.OK, response.status) diff --git a/glance/tests/functional/v1/test_api.py b/glance/tests/functional/v1/test_api.py index ff13c3fd48..daec963600 100644 --- a/glance/tests/functional/v1/test_api.py +++ b/glance/tests/functional/v1/test_api.py @@ -22,6 +22,7 @@ import sys from oslo_serialization import jsonutils from oslo_utils import units +from six.moves import http_client # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range @@ -37,7 +38,7 @@ class TestApi(functional.FunctionalTest): """Functional tests using httplib2 against the API server""" - def _check_image_create(self, headers, status=201, + def _check_image_create(self, headers, status=http_client.CREATED, image_data="*" * FIVE_KB): # performs image_create request, checks the response and returns # content @@ -56,7 +57,7 @@ class TestApi(functional.FunctionalTest): # checksum can be no longer that 32 characters (String(32)) headers['X-Image-Meta-Checksum'] = 'x' * 42 - content = self._check_image_create(headers, 400) + content = self._check_image_create(headers, http_client.BAD_REQUEST) self.assertIn("Invalid checksum", content) # test positive case as well headers['X-Image-Meta-Checksum'] = hashlib.md5(image_data).hexdigest() @@ -71,11 +72,13 @@ class TestApi(functional.FunctionalTest): headers = minimal_headers('Image1') # check that long numbers result in 400 headers['X-Image-Meta-%s' % param] = str(sys.maxint + 1) - content = self._check_image_create(headers, 400) + content = self._check_image_create(headers, + http_client.BAD_REQUEST) self.assertIn("'%s' value out of range" % param, content) # check that integers over 4 byte result in 400 headers['X-Image-Meta-%s' % param] = str(2 ** 31) - content = self._check_image_create(headers, 400) + content = self._check_image_create(headers, + http_client.BAD_REQUEST) self.assertIn("'%s' value out of range" % param, content) # verify positive case as well headers['X-Image-Meta-%s' % param] = str((2 ** 31) - 1) @@ -165,7 +168,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) # 1. GET /images/detail @@ -173,7 +176,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) # 2. POST /images with public image named Image1 @@ -184,7 +187,7 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] self.assertEqual(hashlib.md5(image_data).hexdigest(), @@ -199,7 +202,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual("Image1", response['x-image-meta-name']) # 4. GET image @@ -208,7 +211,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_image_headers = { 'x-image-meta-id': image_id, @@ -246,7 +249,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_result = {"images": [ {"container_format": "ovf", @@ -262,7 +265,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_image = { "status": "active", @@ -293,7 +296,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'PUT', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual("x86_64", data['image']['properties']['arch']) self.assertEqual("Ubuntu", data['image']['properties']['distro']) @@ -307,14 +310,15 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'PUT', headers=headers) - self.assertEqual(413, response.status) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + response.status) # 9. GET /images/detail # Verify image and all its metadata path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_image = { "status": "active", @@ -343,11 +347,11 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'PUT', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port) response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content)['images'][0] self.assertEqual(1, len(data['properties'])) self.assertEqual("x86_64", data['properties']['arch']) @@ -359,12 +363,12 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'PUT', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port) response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content)['images'][0] self.assertEqual(2, len(data['properties'])) self.assertEqual("x86_64", data['properties']['arch']) @@ -376,21 +380,21 @@ class TestApi(functional.FunctionalTest): ("127.0.0.1", self.api_port, image_id)) http = httplib2.Http() response, content = http.request(path, 'PUT') - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) # 13. Add member to image path = ("http://%s:%d/v1/images/%s/members/pattiewhite" % ("127.0.0.1", self.api_port, image_id)) http = httplib2.Http() response, content = http.request(path, 'PUT') - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) # 14. List image members path = ("http://%s:%d/v1/images/%s/members" % ("127.0.0.1", self.api_port, image_id)) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(2, len(data['members'])) self.assertEqual('pattieblack', data['members'][0]['member_id']) @@ -401,7 +405,7 @@ class TestApi(functional.FunctionalTest): ("127.0.0.1", self.api_port, image_id)) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) # 16. Attempt to replace members with an overlimit amount # Adding 11 image members should fail since configured limit is 10 @@ -414,7 +418,8 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() body = jsonutils.dumps(dict(memberships=memberships)) response, content = http.request(path, 'PUT', body=body) - self.assertEqual(413, response.status) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + response.status) # 17. Attempt to add a member while at limit # Adding an 11th member should fail since configured limit is 10 @@ -427,13 +432,14 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() body = jsonutils.dumps(dict(memberships=memberships)) response, content = http.request(path, 'PUT', body=body) - self.assertEqual(204, response.status) + self.assertEqual(http_client.NO_CONTENT, response.status) path = ("http://%s:%d/v1/images/%s/members/fail_me" % ("127.0.0.1", self.api_port, image_id)) http = httplib2.Http() response, content = http.request(path, 'PUT') - self.assertEqual(413, response.status) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + response.status) # 18. POST /images with another public image named Image2 # attribute and three custom properties, "distro", "arch" & "foo". @@ -447,7 +453,7 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image2_id = data['image']['id'] self.assertEqual(hashlib.md5(image_data).hexdigest(), @@ -465,7 +471,7 @@ class TestApi(functional.FunctionalTest): image2_id) http = httplib2.Http() response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual("Image2", response['x-image-meta-name']) # 20. GET /images @@ -473,7 +479,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(2, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -485,7 +491,7 @@ class TestApi(functional.FunctionalTest): "127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(2, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -497,7 +503,7 @@ class TestApi(functional.FunctionalTest): "127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(0, len(images)) @@ -507,7 +513,7 @@ class TestApi(functional.FunctionalTest): self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(0, len(images)) @@ -517,7 +523,7 @@ class TestApi(functional.FunctionalTest): self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -528,7 +534,7 @@ class TestApi(functional.FunctionalTest): self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(1, len(images)) self.assertEqual(image_id, images[0]['id']) @@ -539,7 +545,7 @@ class TestApi(functional.FunctionalTest): self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -549,14 +555,14 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # 28. Try to list members of deleted image path = ("http://%s:%d/v1/images/%s/members" % ("127.0.0.1", self.api_port, image_id)) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) # 29. Try to update member of deleted image path = ("http://%s:%d/v1/images/%s/members" % @@ -565,35 +571,35 @@ class TestApi(functional.FunctionalTest): fixture = [{'member_id': 'pattieblack', 'can_share': 'false'}] body = jsonutils.dumps(dict(memberships=fixture)) response, content = http.request(path, 'PUT', body=body) - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) # 30. Try to add member to deleted image path = ("http://%s:%d/v1/images/%s/members/chickenpattie" % ("127.0.0.1", self.api_port, image_id)) http = httplib2.Http() response, content = http.request(path, 'PUT') - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) # 31. Try to delete member of deleted image path = ("http://%s:%d/v1/images/%s/members/pattieblack" % ("127.0.0.1", self.api_port, image_id)) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) # 32. DELETE image2 path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port, image2_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # 33. GET /images # Verify no images are listed path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(0, len(images)) @@ -601,7 +607,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images/detail" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'HEAD') - self.assertEqual(405, response.status) + self.assertEqual(http_client.METHOD_NOT_ALLOWED, response.status) self.assertEqual('GET', response.get('allow')) self.stop_servers() @@ -633,7 +639,7 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] self.assertEqual(hashlib.md5(image_data).hexdigest(), @@ -648,7 +654,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual("Image1", response['x-image-meta-name']) # 2. GET /images @@ -656,7 +662,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_result = {"images": [ {"container_format": "ovf", @@ -672,7 +678,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # 4. GET image # Verify that 403 HTTPForbidden exception is raised prior to @@ -683,7 +689,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) self.stop_servers() @@ -712,7 +718,7 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] self.assertEqual(hashlib.md5(image_data).hexdigest(), @@ -727,7 +733,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual("Image1", response['x-image-meta-name']) # 2. GET /images @@ -735,7 +741,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_result = {"images": [ {"container_format": "ovf", @@ -751,7 +757,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # 4. GET image # Verify that 404 HTTPNotFound exception is raised @@ -759,7 +765,7 @@ class TestApi(functional.FunctionalTest): image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) self.stop_servers() @@ -776,7 +782,7 @@ class TestApi(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) response, content = http.request(path, 'POST', headers=headers, body=None) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('queued', image['status']) @@ -786,18 +792,18 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() headers = {'X-Image-Meta-Status': 'active'} response, content = http.request(path, 'PUT', headers=headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('queued', response['x-image-meta-status']) # We allow 'setting' to the same status http = httplib2.Http() headers = {'X-Image-Meta-Status': 'queued'} response, content = http.request(path, 'PUT', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('queued', response['x-image-meta-status']) # Make image active @@ -805,7 +811,7 @@ class TestApi(functional.FunctionalTest): headers = {'Content-Type': 'application/octet-stream'} response, content = http.request(path, 'PUT', headers=headers, body='data') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('active', image['status']) @@ -813,18 +819,18 @@ class TestApi(functional.FunctionalTest): http = httplib2.Http() headers = {'X-Image-Meta-Status': 'queued'} response, content = http.request(path, 'PUT', headers=headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('active', response['x-image-meta-status']) # We allow 'setting' to the same status http = httplib2.Http() headers = {'X-Image-Meta-Status': 'active'} response, content = http.request(path, 'PUT', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('active', response['x-image-meta-status']) # Create a 'queued' image, ensure 'status' header is ignored @@ -834,7 +840,7 @@ class TestApi(functional.FunctionalTest): 'X-Image-Meta-Status': 'active'} response, content = http.request(path, 'POST', headers=headers, body=None) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('queued', image['status']) @@ -847,7 +853,7 @@ class TestApi(functional.FunctionalTest): 'X-Image-Meta-Container-Format': 'bare'} response, content = http.request(path, 'POST', headers=headers, body='data') - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('active', image['status']) self.stop_servers() diff --git a/glance/tests/functional/v1/test_copy_to_file.py b/glance/tests/functional/v1/test_copy_to_file.py index b50a66be74..7c829cd5ca 100644 --- a/glance/tests/functional/v1/test_copy_to_file.py +++ b/glance/tests/functional/v1/test_copy_to_file.py @@ -26,6 +26,7 @@ import time import httplib2 from oslo_serialization import jsonutils from oslo_utils import units +from six.moves import http_client # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range @@ -66,7 +67,7 @@ class TestCopyToFile(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status, content) + self.assertEqual(http_client.CREATED, response.status, content) data = jsonutils.loads(content) original_image_id = data['image']['id'] @@ -82,7 +83,7 @@ class TestCopyToFile(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status, content) + self.assertEqual(http_client.CREATED, response.status, content) data = jsonutils.loads(content) copy_image_id = data['image']['id'] @@ -97,7 +98,7 @@ class TestCopyToFile(functional.FunctionalTest): time.sleep(0.01) http = httplib2.Http() response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) if response['x-image-meta-status'] == expected_status: return self.fail('unexpected image status %s' % @@ -106,7 +107,7 @@ class TestCopyToFile(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(str(FIVE_KB), response['content-length']) self.assertEqual("*" * FIVE_KB, content) @@ -120,7 +121,7 @@ class TestCopyToFile(functional.FunctionalTest): original_image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # GET image again to make sure the existence of the original # image in from_store is not depended on @@ -128,7 +129,7 @@ class TestCopyToFile(functional.FunctionalTest): copy_image_id) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(str(FIVE_KB), response['content-length']) self.assertEqual("*" * FIVE_KB, content) @@ -142,7 +143,7 @@ class TestCopyToFile(functional.FunctionalTest): copy_image_id) http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.stop_servers() @@ -173,7 +174,7 @@ class TestCopyToFile(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status, content) + self.assertEqual(http_client.CREATED, response.status, content) data = jsonutils.loads(content) copy_image_id = data['image']['id'] @@ -187,7 +188,7 @@ class TestCopyToFile(functional.FunctionalTest): time.sleep(0.01) http = httplib2.Http() response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) if response['x-image-meta-status'] == expected_status: return self.fail('unexpected image status %s' % @@ -198,7 +199,7 @@ class TestCopyToFile(functional.FunctionalTest): # GET image and make sure image content is as expected http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(str(FIVE_KB), response['content-length']) self.assertEqual("*" * FIVE_KB, content) @@ -208,7 +209,7 @@ class TestCopyToFile(functional.FunctionalTest): # DELETE copied image http = httplib2.Http() response, content = http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.stop_servers() @@ -234,7 +235,7 @@ class TestCopyToFile(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers) - self.assertEqual(404, response.status, content) + self.assertEqual(http_client.NOT_FOUND, response.status, content) expected = 'HTTP datastore could not find image at URI.' self.assertIn(expected, content) @@ -264,7 +265,7 @@ class TestCopyToFile(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers) - self.assertEqual(400, response.status, content) + self.assertEqual(http_client.BAD_REQUEST, response.status, content) expected = 'External sources are not supported: \'%s\'' % copy_from msg = 'expected "%s" in "%s"' % (expected, content) @@ -290,7 +291,7 @@ class TestCopyToFile(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers) - self.assertEqual(400, response.status, content) + self.assertEqual(http_client.BAD_REQUEST, response.status, content) expected = 'External sources are not supported: \'swift+config://xxx\'' msg = 'expected "%s" in "%s"' % (expected, content) diff --git a/glance/tests/functional/v1/test_misc.py b/glance/tests/functional/v1/test_misc.py index 5fa00b7e77..9769c98f8c 100644 --- a/glance/tests/functional/v1/test_misc.py +++ b/glance/tests/functional/v1/test_misc.py @@ -18,6 +18,7 @@ import os import httplib2 from oslo_serialization import jsonutils from oslo_utils import units +from six.moves import http_client from glance.tests import functional from glance.tests.utils import minimal_headers @@ -57,7 +58,7 @@ class TestMiscellaneous(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum']) @@ -75,7 +76,7 @@ class TestMiscellaneous(functional.FunctionalTest): data['image']['id']) http = httplib2.Http() response, content = http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual("Image1", response['x-image-meta-name']) # 4. GET /images/1 @@ -83,7 +84,7 @@ class TestMiscellaneous(functional.FunctionalTest): path = "http://%s:%d/v1/images/1" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) self.stop_servers() @@ -106,7 +107,7 @@ class TestMiscellaneous(functional.FunctionalTest): http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) headers = {'Content-Type': 'application/octet-stream', diff --git a/glance/tests/functional/v1/test_multiprocessing.py b/glance/tests/functional/v1/test_multiprocessing.py index 00bd9adc36..0a8034296a 100644 --- a/glance/tests/functional/v1/test_multiprocessing.py +++ b/glance/tests/functional/v1/test_multiprocessing.py @@ -17,6 +17,7 @@ import time import httplib2 import psutil +from six.moves import http_client # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range @@ -39,7 +40,7 @@ class TestMultiprocessing(functional.FunctionalTest): path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port) http = httplib2.Http() response, content = http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(b'{"images": []}', content) self.stop_servers() diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py index 721e090d88..cec1a7f0ef 100644 --- a/glance/tests/functional/v2/test_images.py +++ b/glance/tests/functional/v2/test_images.py @@ -20,6 +20,7 @@ import uuid from oslo_serialization import jsonutils import requests import six +from six.moves import http_client as http # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range from six.moves import urllib @@ -85,7 +86,7 @@ class TestImages(functional.FunctionalTest): headers['x-image-meta-property-my_empty_prop'] = '' response = requests.post(path, headers=headers) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) data = jsonutils.loads(response.text) image_id = data['image']['id'] @@ -94,7 +95,7 @@ class TestImages(functional.FunctionalTest): # string. path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual('', image['my_empty_prop']) self.stop_servers() @@ -114,23 +115,23 @@ class TestImages(functional.FunctionalTest): # image create should return 401 response = requests.post(self._url('/v2/images'), headers=headers, data=jsonutils.dumps(image)) - self.assertEqual(401, response.status_code) + self.assertEqual(http.UNAUTHORIZED, response.status_code) # image list should return 401 response = requests.get(self._url('/v2/images')) - self.assertEqual(401, response.status_code) + self.assertEqual(http.UNAUTHORIZED, response.status_code) # image show should return 401 response = requests.get(self._url('/v2/images/someimageid')) - self.assertEqual(401, response.status_code) + self.assertEqual(http.UNAUTHORIZED, response.status_code) # image update should return 401 ops = [{'op': 'replace', 'path': '/protected', 'value': False}] media_type = 'application/openstack-images-v2.1-json-patch' response = requests.patch(self._url('/v2/images/someimageid'), headers={'content-type': media_type}, data=jsonutils.dumps(ops)) - self.assertEqual(401, response.status_code) + self.assertEqual(http.UNAUTHORIZED, response.status_code) # image delete should return 401 response = requests.delete(self._url('/v2/images/someimageid')) - self.assertEqual(401, response.status_code) + self.assertEqual(http.UNAUTHORIZED, response.status_code) self.stop_servers() def test_image_lifecycle(self): @@ -139,7 +140,7 @@ class TestImages(functional.FunctionalTest): self.start_servers(**self.__dict__.copy()) path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -150,7 +151,7 @@ class TestImages(functional.FunctionalTest): 'foo': 'bar', 'disk_format': 'aki', 'container_format': 'aki', 'abc': 'xyz'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image_location_header = response.headers['Location'] # Returned image entity should have a generated id and status @@ -203,7 +204,7 @@ class TestImages(functional.FunctionalTest): # Image list should now have one entry path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual(image_id, images[0]['id']) @@ -215,7 +216,7 @@ class TestImages(functional.FunctionalTest): 'bar': 'foo', 'disk_format': 'aki', 'container_format': 'aki', 'xyz': 'abc'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned image entity should have a generated id and status image = jsonutils.loads(response.text) @@ -267,7 +268,7 @@ class TestImages(functional.FunctionalTest): # Image list should now have two entries path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(2, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -277,7 +278,7 @@ class TestImages(functional.FunctionalTest): # property 'bar' path = self._url('/v2/images?bar=foo') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -286,7 +287,7 @@ class TestImages(functional.FunctionalTest): # property 'foo' path = self._url('/v2/images?foo=bar') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual(image_id, images[0]['id']) @@ -294,17 +295,17 @@ class TestImages(functional.FunctionalTest): # The "changes-since" filter shouldn't work on glance v2 path = self._url('/v2/images?changes-since=20001007T10:10:10') response = requests.get(path, headers=self._headers()) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) path = self._url('/v2/images?changes-since=aaa') response = requests.get(path, headers=self._headers()) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Image list should list only image-1 based on the filter # 'foo=bar&abc=xyz' path = self._url('/v2/images?foo=bar&abc=xyz') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual(image_id, images[0]['id']) @@ -313,7 +314,7 @@ class TestImages(functional.FunctionalTest): # 'bar=foo&xyz=abc' path = self._url('/v2/images?bar=foo&xyz=abc') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -322,13 +323,13 @@ class TestImages(functional.FunctionalTest): # is not satisfied by either images path = self._url('/v2/images?foo=baz&abc=xyz') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) # Get the image using the returned Location header response = requests.get(image_location_header, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual(image_id, image['id']) self.assertIsNone(image['checksum']) @@ -357,7 +358,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps(changes) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(400, response.status_code, response.text) + self.assertEqual(http.BAD_REQUEST, response.status_code, response.text) # The image should be mutable, including adding and removing properties path = self._url('/v2/images/%s' % image_id) @@ -373,7 +374,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/type'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned image entity should reflect the changes image = jsonutils.loads(response.text) @@ -396,7 +397,8 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps(changes) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(413, response.status_code, response.text) + self.assertEqual(http.REQUEST_ENTITY_TOO_LARGE, response.status_code, + response.text) # Adding 3 image locations should fail since configured limit is 2 path = self._url('/v2/images/%s' % image_id) @@ -412,7 +414,8 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps(changes) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(413, response.status_code, response.text) + self.assertEqual(http.REQUEST_ENTITY_TOO_LARGE, response.status_code, + response.text) # Ensure the v2.0 json-patch content type is accepted path = self._url('/v2/images/%s' % image_id) @@ -420,7 +423,7 @@ class TestImages(functional.FunctionalTest): headers = self._headers({'content-type': media_type}) data = jsonutils.dumps([{'add': '/ding', 'value': 'dong'}]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned image entity should reflect the changes image = jsonutils.loads(response.text) @@ -429,7 +432,7 @@ class TestImages(functional.FunctionalTest): # Updates should persist across requests path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual(image_id, image['id']) self.assertEqual('image-2', image['name']) @@ -442,13 +445,13 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers() response = requests.get(path, headers=headers) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) def _verify_image_checksum_and_status(checksum, status): # Checksum should be populated and status should be active path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual(checksum, image['checksum']) self.assertEqual(status, image['status']) @@ -457,7 +460,7 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='ZZZZZ') - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) expected_checksum = '8f113e38d28a79a5a451b16048cc2b72' _verify_image_checksum_and_status(expected_checksum, 'active') @@ -473,12 +476,12 @@ class TestImages(functional.FunctionalTest): {'op': 'replace', 'path': immutable_path, 'value': 'ari'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Try to download the data that was just uploaded path = self._url('/v2/images/%s/file' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.assertEqual(expected_checksum, response.headers['Content-MD5']) self.assertEqual('ZZZZZ', response.text) @@ -487,19 +490,19 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='XXX') - self.assertEqual(409, response.status_code) + self.assertEqual(http.CONFLICT, response.status_code) _verify_image_checksum_and_status(expected_checksum, 'active') # Ensure the size is updated to reflect the data uploaded path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.assertEqual(5, jsonutils.loads(response.text)['size']) # Should be able to deactivate image path = self._url('/v2/images/%s/actions/deactivate' % image_id) response = requests.post(path, data={}, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Change the image to public so TENANT2 can see it path = self._url('/v2/images/%s' % image_id) @@ -507,34 +510,34 @@ class TestImages(functional.FunctionalTest): headers = self._headers({'content-type': media_type}) data = jsonutils.dumps([{"replace": "/visibility", "value": "public"}]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Tenant2 should get Forbidden when deactivating the public image path = self._url('/v2/images/%s/actions/deactivate' % image_id) response = requests.post(path, data={}, headers=self._headers( {'X-Tenant-Id': TENANT2})) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Tenant2 should get Forbidden when reactivating the public image path = self._url('/v2/images/%s/actions/reactivate' % image_id) response = requests.post(path, data={}, headers=self._headers( {'X-Tenant-Id': TENANT2})) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Deactivating a deactivated image succeeds (no-op) path = self._url('/v2/images/%s/actions/deactivate' % image_id) response = requests.post(path, data={}, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Can't download a deactivated image path = self._url('/v2/images/%s/file' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Deactivated image should still be in a listing path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(2, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -543,17 +546,17 @@ class TestImages(functional.FunctionalTest): # Should be able to reactivate a deactivated image path = self._url('/v2/images/%s/actions/reactivate' % image_id) response = requests.post(path, data={}, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Reactivating an active image succeeds (no-op) path = self._url('/v2/images/%s/actions/reactivate' % image_id) response = requests.post(path, data={}, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Deletion should not work on protected images path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Unprotect image for deletion path = self._url('/v2/images/%s' % image_id) @@ -562,28 +565,28 @@ class TestImages(functional.FunctionalTest): doc = [{'op': 'replace', 'path': '/protected', 'value': False}] data = jsonutils.dumps(doc) response = requests.patch(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 image-1 path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # This image should be no longer be directly accessible path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # And neither should its data path = self._url('/v2/images/%s/file' % image_id) headers = self._headers() response = requests.get(path, headers=headers) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Image list should now contain just image-2 path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -591,12 +594,12 @@ class TestImages(functional.FunctionalTest): # Deleting image-2 should work path = self._url('/v2/images/%s' % image2_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Image list should now be empty path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -605,21 +608,21 @@ class TestImages(functional.FunctionalTest): headers = self._headers({'content-type': 'application/json'}) data = 'true' response = requests.post(path, headers=headers, data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Create image that tries to send a string should return 400 path = self._url('/v2/images') headers = self._headers({'content-type': 'application/json'}) data = '"hello"' response = requests.post(path, headers=headers, data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Create image that tries to send 123 should return 400 path = self._url('/v2/images') headers = self._headers({'content-type': 'application/json'}) data = '123' response = requests.post(path, headers=headers, data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) self.stop_servers() @@ -646,7 +649,7 @@ class TestImages(functional.FunctionalTest): 'value': 'value1'}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) for prop in props: doc = [{'op': 'remove', @@ -654,7 +657,7 @@ class TestImages(functional.FunctionalTest): 'value': 'value1'}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) for prop in props: doc = [{'op': 'add', @@ -662,7 +665,7 @@ class TestImages(functional.FunctionalTest): 'value': 'value1'}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) self.stop_servers() @@ -671,7 +674,7 @@ class TestImages(functional.FunctionalTest): self.start_servers(**self.__dict__.copy()) path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Test all the schemas schema_urls = [ @@ -684,14 +687,14 @@ class TestImages(functional.FunctionalTest): path = self._url(value) data = jsonutils.dumps(["body"]) response = requests.get(path, headers=self._headers(), data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Create image for use with tests path = self._url('/v2/images') headers = self._headers({'content-type': 'application/json'}) data = jsonutils.dumps({'name': 'image'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] @@ -711,31 +714,31 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps(["body"]) response = getattr(requests, method)( path, headers=self._headers(), data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # DELETE /images/imgid without legal json path = self._url('/v2/images/%s' % image_id) data = '{"hello"]' response = requests.delete(path, headers=self._headers(), data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # POST /images/imgid/members path = self._url('/v2/images/%s/members' % image_id) data = jsonutils.dumps({'member': TENANT3}) response = requests.post(path, headers=self._headers(), data=data) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # GET /images/imgid/members/memid path = self._url('/v2/images/%s/members/%s' % (image_id, TENANT3)) data = jsonutils.dumps(["body"]) response = requests.get(path, headers=self._headers(), data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # DELETE /images/imgid/members/memid path = self._url('/v2/images/%s/members/%s' % (image_id, TENANT3)) data = jsonutils.dumps(["body"]) response = requests.delete(path, headers=self._headers(), data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) self.stop_servers() @@ -748,7 +751,7 @@ class TestImages(functional.FunctionalTest): 'bar': 'foo', 'disk_format': 'aki', 'container_format': 'aki', 'xyz': 'abc'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] @@ -757,7 +760,7 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data=image_data) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) result_body = '' for x in range(15): @@ -794,7 +797,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned image entity image = jsonutils.loads(response.text) @@ -818,23 +821,23 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='ZZZZZ') - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Get an image should fail path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.get(path, headers=headers) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Image Deletion should work path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # This image should be no longer be directly accessible path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) self.stop_servers() @@ -863,7 +866,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned image entity image = jsonutils.loads(response.text) @@ -888,24 +891,24 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='ZZZZZ') - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Get an image should fail path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream', 'X-Roles': '_member_'}) response = requests.get(path, headers=headers) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Image Deletion should work path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # This image should be no longer be directly accessible path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) self.stop_servers() @@ -935,7 +938,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned image entity image = jsonutils.loads(response.text) @@ -960,24 +963,24 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='ZZZZZ') - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Get an image should be allowed path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream', 'X-Roles': 'member'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Image Deletion should work path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # This image should be no longer be directly accessible path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) self.stop_servers() @@ -993,7 +996,7 @@ class TestImages(functional.FunctionalTest): 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get image id image = jsonutils.loads(response.text) @@ -1012,13 +1015,13 @@ class TestImages(functional.FunctionalTest): 'value': values}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Download an image should work path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Stop http server used to update image location os.kill(http_server_pid, signal.SIGKILL) @@ -1027,17 +1030,17 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(503, response.status_code) + self.assertEqual(http.SERVICE_UNAVAILABLE, response.status_code) # Image Deletion should work path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # This image should be no longer be directly accessible path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) self.stop_servers() @@ -1065,7 +1068,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image's ID image = jsonutils.loads(response.text) @@ -1079,7 +1082,7 @@ class TestImages(functional.FunctionalTest): {'op': 'replace', 'path': '/name', 'value': 'new-name'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.stop_servers() @@ -1107,7 +1110,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image's ID image = jsonutils.loads(response.text) @@ -1121,7 +1124,7 @@ class TestImages(functional.FunctionalTest): {'op': 'replace', 'path': '/name', 'value': 'new-name'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) self.stop_servers() @@ -1150,7 +1153,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image's ID image = jsonutils.loads(response.text) @@ -1161,7 +1164,7 @@ class TestImages(functional.FunctionalTest): body = jsonutils.dumps({'member': TENANT3}) del headers['X-Roles'] response = requests.post(path, headers=headers, data=body) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.stop_servers() @@ -1190,11 +1193,11 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) headers['X-Tenant-Id'] = TENANT2 response = requests.post(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) self.stop_servers() @@ -1223,7 +1226,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Remove the admin role del headers['X-Roles'] @@ -1234,16 +1237,16 @@ class TestImages(functional.FunctionalTest): # Can retrieve the image as TENANT1 path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Can retrieve the image's members as TENANT1 path = self._url('/v2/images/%s/members' % image_id) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) headers['X-Tenant-Id'] = TENANT2 response = requests.get(path, headers=headers) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) self.stop_servers() @@ -1273,7 +1276,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image's ID image = jsonutils.loads(response.text) @@ -1287,7 +1290,7 @@ class TestImages(functional.FunctionalTest): doc = [{'op': 'replace', 'path': '/visibility', 'value': 'public'}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) def test_owning_tenant_can_delete_image(self): rules = { @@ -1315,7 +1318,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image's ID image = jsonutils.loads(response.text) @@ -1323,7 +1326,7 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=headers) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) def test_list_show_ok_when_get_location_allowed_for_admins(self): self.api_server.show_image_direct_url = True @@ -1353,7 +1356,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image's ID image = jsonutils.loads(response.text) @@ -1362,12 +1365,12 @@ class TestImages(functional.FunctionalTest): # Can retrieve the image as TENANT1 path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Can list images as TENANT1 path = self._url('/v2/images') response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.stop_servers() @@ -1381,7 +1384,7 @@ class TestImages(functional.FunctionalTest): 'type': 'kernel', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] @@ -1401,7 +1404,7 @@ class TestImages(functional.FunctionalTest): response = requests.put(path, headers=headers, data=StreamSim( self.api_server.image_size_cap + 1)) - self.assertEqual(413, response.status_code) + self.assertEqual(http.REQUEST_ENTITY_TOO_LARGE, response.status_code) # hashlib.md5('Z'*129).hexdigest() # == '76522d28cb4418f12704dfa7acd6e7ee' @@ -1421,32 +1424,32 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'raw', 'container_format': 'bare'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image_id = jsonutils.loads(response.text)['id'] # Upload some image data path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='ZZZZZ') - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # TENANT1 should see the image in their list path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(image_id, images[0]['id']) # TENANT1 should be able to access the image directly path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # TENANT2 should not see the image in their list path = self._url('/v2/images') headers = self._headers({'X-Tenant-Id': TENANT2}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -1454,7 +1457,7 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s' % image_id) headers = self._headers({'X-Tenant-Id': TENANT2}) response = requests.get(path, headers=headers) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # TENANT2 should not be able to modify the image, either path = self._url('/v2/images/%s' % image_id) @@ -1465,13 +1468,13 @@ class TestImages(functional.FunctionalTest): doc = [{'op': 'replace', 'path': '/name', 'value': 'image-2'}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # TENANT2 should not be able to delete the image, either path = self._url('/v2/images/%s' % image_id) headers = self._headers({'X-Tenant-Id': TENANT2}) response = requests.delete(path, headers=headers) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Publicize the image as an admin of TENANT1 path = self._url('/v2/images/%s' % image_id) @@ -1482,13 +1485,13 @@ class TestImages(functional.FunctionalTest): doc = [{'op': 'replace', 'path': '/visibility', 'value': 'public'}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # TENANT3 should now see the image in their list path = self._url('/v2/images') headers = self._headers({'X-Tenant-Id': TENANT3}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(image_id, images[0]['id']) @@ -1496,7 +1499,7 @@ class TestImages(functional.FunctionalTest): path = self._url('/v2/images/%s' % image_id) headers = self._headers({'X-Tenant-Id': TENANT3}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # TENANT3 still should not be able to modify the image path = self._url('/v2/images/%s' % image_id) @@ -1507,18 +1510,18 @@ class TestImages(functional.FunctionalTest): doc = [{'op': 'replace', 'path': '/name', 'value': 'image-2'}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # TENANT3 should not be able to delete the image, either path = self._url('/v2/images/%s' % image_id) headers = self._headers({'X-Tenant-Id': TENANT3}) response = requests.delete(path, headers=headers) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Image data should still be present after the failed delete path = self._url('/v2/images/%s/file' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.assertEqual(response.text, 'ZZZZZ') self.stop_servers() @@ -1531,7 +1534,7 @@ class TestImages(functional.FunctionalTest): # Image list should be empty path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -1545,7 +1548,7 @@ class TestImages(functional.FunctionalTest): 'container_format': 'aki', 'x_owner_foo': 'o_s_bar'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Create an image for role member without 'foo' path = self._url('/v2/images') @@ -1555,7 +1558,7 @@ class TestImages(functional.FunctionalTest): 'container_format': 'aki', 'x_owner_foo': 'o_s_bar'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned image entity should have 'x_owner_foo' image = jsonutils.loads(response.text) @@ -1590,7 +1593,7 @@ class TestImages(functional.FunctionalTest): 'spl_delete_prop': 'delete_bar', 'spl_delete_empty_prop': ''}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] @@ -1604,7 +1607,7 @@ class TestImages(functional.FunctionalTest): {'op': 'replace', 'path': '/spl_update_prop', 'value': 'u'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code, response.text) + self.assertEqual(http.FORBIDDEN, response.status_code, response.text) # Attempt to replace, add and remove properties which are forbidden path = self._url('/v2/images/%s' % image_id) @@ -1617,7 +1620,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/spl_delete_prop'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code, response.text) + self.assertEqual(http.FORBIDDEN, response.status_code, response.text) # Attempt to replace properties path = self._url('/v2/images/%s' % image_id) @@ -1630,7 +1633,7 @@ class TestImages(functional.FunctionalTest): {'op': 'replace', 'path': '/spl_update_prop', 'value': 'u'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned image entity should reflect the changes image = jsonutils.loads(response.text) @@ -1650,7 +1653,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/spl_delete_empty_prop'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned image entity should reflect the changes image = jsonutils.loads(response.text) @@ -1663,12 +1666,12 @@ class TestImages(functional.FunctionalTest): # Image Deletion should work path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # This image should be no longer be directly accessible path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) self.stop_servers() @@ -1681,7 +1684,7 @@ class TestImages(functional.FunctionalTest): # Image list should be empty path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -1695,7 +1698,7 @@ class TestImages(functional.FunctionalTest): 'container_format': 'aki', 'x_owner_foo': 'o_s_bar'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Create an image for role member without 'foo' path = self._url('/v2/images') @@ -1704,7 +1707,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned image entity image = jsonutils.loads(response.text) @@ -1734,7 +1737,7 @@ class TestImages(functional.FunctionalTest): 'spl_creator_policy': 'creator_bar', 'spl_default_policy': 'default_bar'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] self.assertEqual('creator_bar', image['spl_creator_policy']) @@ -1751,7 +1754,7 @@ class TestImages(functional.FunctionalTest): {'op': 'replace', 'path': '/spl_creator_policy', 'value': 'r'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned image entity should reflect the changes image = jsonutils.loads(response.text) @@ -1769,14 +1772,14 @@ class TestImages(functional.FunctionalTest): {'op': 'replace', 'path': '/spl_creator_policy', 'value': 'z'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code, response.text) + self.assertEqual(http.FORBIDDEN, response.status_code, response.text) # Attempt to read properties path = self._url('/v2/images/%s' % image_id) headers = self._headers({'content-type': media_type, 'X-Roles': 'random_role'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) # 'random_role' is allowed read 'spl_default_policy'. @@ -1795,7 +1798,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/spl_creator_policy'}, ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned image entity should reflect the changes image = jsonutils.loads(response.text) @@ -1809,7 +1812,7 @@ class TestImages(functional.FunctionalTest): headers = self._headers({'content-type': media_type, 'X-Roles': 'random_role'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Returned image entity should reflect the changes image = jsonutils.loads(response.text) @@ -1818,12 +1821,12 @@ class TestImages(functional.FunctionalTest): # Image Deletion should work path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # This image should be no longer be directly accessible path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) self.stop_servers() @@ -1844,7 +1847,7 @@ class TestImages(functional.FunctionalTest): 'x_all_permitted_admin': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] expected_image = { @@ -1872,7 +1875,7 @@ class TestImages(functional.FunctionalTest): 'x_all_permitted_joe_soap': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] expected_image = { @@ -1897,14 +1900,14 @@ class TestImages(functional.FunctionalTest): 'X-Roles': 'admin'}) path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual('1', image['x_all_permitted_joe_soap']) headers = self._headers({'content-type': 'application/json', 'X-Roles': 'joe_soap'}) path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual('1', image['x_all_permitted_joe_soap']) @@ -1919,7 +1922,7 @@ class TestImages(functional.FunctionalTest): 'path': '/x_all_permitted_joe_soap', 'value': '2'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) image = jsonutils.loads(response.text) self.assertEqual('2', image['x_all_permitted_joe_soap']) path = self._url('/v2/images/%s' % image_id) @@ -1931,7 +1934,7 @@ class TestImages(functional.FunctionalTest): 'path': '/x_all_permitted_joe_soap', 'value': '3'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) image = jsonutils.loads(response.text) self.assertEqual('3', image['x_all_permitted_joe_soap']) @@ -1948,7 +1951,7 @@ class TestImages(functional.FunctionalTest): 'x_all_permitted_b': '2' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] path = self._url('/v2/images/%s' % image_id) @@ -1959,7 +1962,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/x_all_permitted_a'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) image = jsonutils.loads(response.text) self.assertNotIn('x_all_permitted_a', image.keys()) path = self._url('/v2/images/%s' % image_id) @@ -1970,7 +1973,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/x_all_permitted_b'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) image = jsonutils.loads(response.text) self.assertNotIn('x_all_permitted_b', image.keys()) @@ -1986,7 +1989,7 @@ class TestImages(functional.FunctionalTest): 'x_none_permitted_admin': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) path = self._url('/v2/images') headers = self._headers({'content-type': 'application/json', 'X-Roles': 'joe_soap'}) @@ -1997,7 +2000,7 @@ class TestImages(functional.FunctionalTest): 'x_none_permitted_joe_soap': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Verify neither admin nor unknown role can read properties marked with # '!' @@ -2011,7 +2014,7 @@ class TestImages(functional.FunctionalTest): 'x_none_read': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] self.assertNotIn('x_none_read', image.keys()) @@ -2019,14 +2022,14 @@ class TestImages(functional.FunctionalTest): 'X-Roles': 'admin'}) path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertNotIn('x_none_read', image.keys()) headers = self._headers({'content-type': 'application/json', 'X-Roles': 'joe_soap'}) path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertNotIn('x_none_read', image.keys()) @@ -2042,7 +2045,7 @@ class TestImages(functional.FunctionalTest): 'x_none_update': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] self.assertEqual('1', image['x_none_update']) @@ -2055,7 +2058,7 @@ class TestImages(functional.FunctionalTest): 'path': '/x_none_update', 'value': '2'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code, response.text) + self.assertEqual(http.FORBIDDEN, response.status_code, response.text) path = self._url('/v2/images/%s' % image_id) media_type = 'application/openstack-images-v2.1-json-patch' headers = self._headers({'content-type': media_type, @@ -2065,7 +2068,7 @@ class TestImages(functional.FunctionalTest): 'path': '/x_none_update', 'value': '3'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(409, response.status_code, response.text) + self.assertEqual(http.CONFLICT, response.status_code, response.text) # Verify neither admin nor unknown role can delete properties marked # with '!' @@ -2079,7 +2082,7 @@ class TestImages(functional.FunctionalTest): 'x_none_delete': '1', }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] path = self._url('/v2/images/%s' % image_id) @@ -2090,7 +2093,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/x_none_delete'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code, response.text) + self.assertEqual(http.FORBIDDEN, response.status_code, response.text) path = self._url('/v2/images/%s' % image_id) media_type = 'application/openstack-images-v2.1-json-patch' headers = self._headers({'content-type': media_type, @@ -2099,7 +2102,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/x_none_delete'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(409, response.status_code, response.text) + self.assertEqual(http.CONFLICT, response.status_code, response.text) self.stop_servers() @@ -2121,7 +2124,7 @@ class TestImages(functional.FunctionalTest): 'x_all_permitted_admin': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] expected_image = { @@ -2149,7 +2152,7 @@ class TestImages(functional.FunctionalTest): 'x_all_permitted_joe_soap': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] expected_image = { @@ -2174,14 +2177,14 @@ class TestImages(functional.FunctionalTest): 'X-Roles': 'admin'}) path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual('1', image['x_all_permitted_joe_soap']) headers = self._headers({'content-type': 'application/json', 'X-Roles': 'joe_soap'}) path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual('1', image['x_all_permitted_joe_soap']) @@ -2196,7 +2199,7 @@ class TestImages(functional.FunctionalTest): 'path': '/x_all_permitted_joe_soap', 'value': '2'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) image = jsonutils.loads(response.text) self.assertEqual('2', image['x_all_permitted_joe_soap']) path = self._url('/v2/images/%s' % image_id) @@ -2208,7 +2211,7 @@ class TestImages(functional.FunctionalTest): 'path': '/x_all_permitted_joe_soap', 'value': '3'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) image = jsonutils.loads(response.text) self.assertEqual('3', image['x_all_permitted_joe_soap']) @@ -2225,7 +2228,7 @@ class TestImages(functional.FunctionalTest): 'x_all_permitted_b': '2' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] path = self._url('/v2/images/%s' % image_id) @@ -2236,7 +2239,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/x_all_permitted_a'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) image = jsonutils.loads(response.text) self.assertNotIn('x_all_permitted_a', image.keys()) path = self._url('/v2/images/%s' % image_id) @@ -2247,7 +2250,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/x_all_permitted_b'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) image = jsonutils.loads(response.text) self.assertNotIn('x_all_permitted_b', image.keys()) @@ -2263,7 +2266,7 @@ class TestImages(functional.FunctionalTest): 'x_none_permitted_admin': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) path = self._url('/v2/images') headers = self._headers({'content-type': 'application/json', 'X-Roles': 'joe_soap'}) @@ -2274,7 +2277,7 @@ class TestImages(functional.FunctionalTest): 'x_none_permitted_joe_soap': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Verify neither admin nor unknown role can read properties marked with # '!' @@ -2288,7 +2291,7 @@ class TestImages(functional.FunctionalTest): 'x_none_read': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] self.assertNotIn('x_none_read', image.keys()) @@ -2296,14 +2299,14 @@ class TestImages(functional.FunctionalTest): 'X-Roles': 'admin'}) path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertNotIn('x_none_read', image.keys()) headers = self._headers({'content-type': 'application/json', 'X-Roles': 'joe_soap'}) path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertNotIn('x_none_read', image.keys()) @@ -2319,7 +2322,7 @@ class TestImages(functional.FunctionalTest): 'x_none_update': '1' }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] self.assertEqual('1', image['x_none_update']) @@ -2332,7 +2335,7 @@ class TestImages(functional.FunctionalTest): 'path': '/x_none_update', 'value': '2'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code, response.text) + self.assertEqual(http.FORBIDDEN, response.status_code, response.text) path = self._url('/v2/images/%s' % image_id) media_type = 'application/openstack-images-v2.1-json-patch' headers = self._headers({'content-type': media_type, @@ -2342,7 +2345,7 @@ class TestImages(functional.FunctionalTest): 'path': '/x_none_update', 'value': '3'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(409, response.status_code, response.text) + self.assertEqual(http.CONFLICT, response.status_code, response.text) # Verify neither admin nor unknown role can delete properties marked # with '!' @@ -2356,7 +2359,7 @@ class TestImages(functional.FunctionalTest): 'x_none_delete': '1', }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] path = self._url('/v2/images/%s' % image_id) @@ -2367,7 +2370,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/x_none_delete'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(403, response.status_code, response.text) + self.assertEqual(http.FORBIDDEN, response.status_code, response.text) path = self._url('/v2/images/%s' % image_id) media_type = 'application/openstack-images-v2.1-json-patch' headers = self._headers({'content-type': media_type, @@ -2376,7 +2379,7 @@ class TestImages(functional.FunctionalTest): {'op': 'remove', 'path': '/x_none_delete'} ]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(409, response.status_code, response.text) + self.assertEqual(http.CONFLICT, response.status_code, response.text) self.stop_servers() @@ -2387,13 +2390,13 @@ class TestImages(functional.FunctionalTest): headers = self._headers({'Content-Type': 'application/json'}) data = jsonutils.dumps({'name': 'image-1', 'tags': ['sniff', 'sniff']}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image_id = jsonutils.loads(response.text)['id'] # Image should show a list with a single tag path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(['sniff'], tags) @@ -2401,24 +2404,24 @@ class TestImages(functional.FunctionalTest): for tag in tags: path = self._url('/v2/images/%s/tags/%s' % (image_id, tag)) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Update image with too many tags via PUT # Configured limit is 10 tags for i in range(10): path = self._url('/v2/images/%s/tags/foo%i' % (image_id, i)) response = requests.put(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # 11th tag should fail path = self._url('/v2/images/%s/tags/fail_me' % image_id) response = requests.put(path, headers=self._headers()) - self.assertEqual(413, response.status_code) + self.assertEqual(http.REQUEST_ENTITY_TOO_LARGE, response.status_code) # Make sure the 11th tag was not added path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(10, len(tags)) @@ -2435,7 +2438,7 @@ class TestImages(functional.FunctionalTest): ] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Update image with too many tags via PATCH # Configured limit is 10 tags @@ -2452,12 +2455,12 @@ class TestImages(functional.FunctionalTest): ] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(413, response.status_code) + self.assertEqual(http.REQUEST_ENTITY_TOO_LARGE, response.status_code) # Tags should not have changed since request was over limit path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(['foo'], tags) @@ -2474,31 +2477,31 @@ class TestImages(functional.FunctionalTest): ] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(['sniff', 'snozz'], sorted(tags)) # Image should show the appropriate tags path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(['sniff', 'snozz'], sorted(tags)) # Attempt to tag the image with a duplicate should be ignored path = self._url('/v2/images/%s/tags/snozz' % image_id) response = requests.put(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Create another more complex tag path = self._url('/v2/images/%s/tags/gabe%%40example.com' % image_id) response = requests.put(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Double-check that the tags container on the image is populated path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(['gabe@example.com', 'sniff', 'snozz'], sorted(tags)) @@ -2506,7 +2509,7 @@ class TestImages(functional.FunctionalTest): # Query images by single tag path = self._url('/v2/images?tag=sniff') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual('image-1', images[0]['name']) @@ -2514,7 +2517,7 @@ class TestImages(functional.FunctionalTest): # Query images by multiple tags path = self._url('/v2/images?tag=sniff&tag=snozz') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual('image-1', images[0]['name']) @@ -2522,7 +2525,7 @@ class TestImages(functional.FunctionalTest): # Query images by tag and other attributes path = self._url('/v2/images?tag=sniff&status=queued') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual('image-1', images[0]['name']) @@ -2530,31 +2533,31 @@ class TestImages(functional.FunctionalTest): # Query images by tag and a nonexistent tag path = self._url('/v2/images?tag=sniff&tag=fake') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) # The tag should be deletable path = self._url('/v2/images/%s/tags/gabe%%40example.com' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # List of tags should reflect the deletion path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(['sniff', 'snozz'], sorted(tags)) # Deleting the same tag should return a 404 path = self._url('/v2/images/%s/tags/gabe%%40example.com' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # The tags won't be able to query the images after deleting path = self._url('/v2/images?tag=gabe%%40example.com') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -2562,12 +2565,12 @@ class TestImages(functional.FunctionalTest): big_tag = 'a' * 300 path = self._url('/v2/images/%s/tags/%s' % (image_id, big_tag)) response = requests.put(path, headers=self._headers()) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Tags should not have changed since request was over limit path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(['sniff', 'snozz'], sorted(tags)) @@ -2578,7 +2581,7 @@ class TestImages(functional.FunctionalTest): self.start_servers(**self.__dict__.copy()) path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] first = jsonutils.loads(response.text)['first'] self.assertEqual(0, len(images)) @@ -2603,13 +2606,13 @@ class TestImages(functional.FunctionalTest): for fixture in fixtures: data = jsonutils.dumps(fixture) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) images.append(jsonutils.loads(response.text)) # Image list should contain 7 images path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(7, len(body['images'])) self.assertEqual('/v2/images', body['first']) @@ -2619,7 +2622,7 @@ class TestImages(functional.FunctionalTest): url_template = '/v2/images?created_at=lt:%s' path = self._url(url_template % images[0]['created_at']) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(0, len(body['images'])) self.assertEqual(url_template % images[0]['created_at'], @@ -2629,7 +2632,7 @@ class TestImages(functional.FunctionalTest): url_template = '/v2/images?updated_at=lt:%s' path = self._url(url_template % images[2]['updated_at']) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertGreaterEqual(3, len(body['images'])) self.assertEqual(url_template % images[2]['updated_at'], @@ -2640,26 +2643,26 @@ class TestImages(functional.FunctionalTest): for filter in ['updated_at', 'created_at']: path = self._url(url_template % filter) response = requests.get(path, headers=self._headers()) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Image list filters by updated_at and created_at with invalid operator url_template = '/v2/images?%s=invalid_operator:2015-11-19T12:24:02Z' for filter in ['updated_at', 'created_at']: path = self._url(url_template % filter) response = requests.get(path, headers=self._headers()) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Image list filters by non-'URL encoding' value path = self._url('/v2/images?name=%FF') response = requests.get(path, headers=self._headers()) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Image list filters by name with in operator url_template = '/v2/images?name=in:%s' filter_value = 'image-1,image-2' path = self._url(url_template % filter_value) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertGreaterEqual(3, len(body['images'])) @@ -2668,7 +2671,7 @@ class TestImages(functional.FunctionalTest): filter_value = 'bare,ami' path = self._url(url_template % filter_value) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertGreaterEqual(2, len(body['images'])) @@ -2677,7 +2680,7 @@ class TestImages(functional.FunctionalTest): filter_value = 'bare,ami,iso' path = self._url(url_template % filter_value) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertGreaterEqual(2, len(body['images'])) @@ -2686,7 +2689,7 @@ class TestImages(functional.FunctionalTest): '&marker=%s&type=kernel&ping=pong') path = self._url(template_url % images[2]['id']) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(2, len(body['images'])) response_ids = [image['id'] for image in body['images']] @@ -2695,7 +2698,7 @@ class TestImages(functional.FunctionalTest): # Continue pagination using next link from previous request path = self._url(body['next']) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(2, len(body['images'])) response_ids = [image['id'] for image in body['images']] @@ -2704,19 +2707,19 @@ class TestImages(functional.FunctionalTest): # Continue pagination - expect no results path = self._url(body['next']) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(0, len(body['images'])) # Delete first image path = self._url('/v2/images/%s' % images[0]['id']) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Ensure bad request for using a deleted image as marker path = self._url('/v2/images?marker=%s' % images[0]['id']) response = requests.get(path, headers=self._headers()) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) self.stop_servers() @@ -2744,7 +2747,7 @@ class TestImages(functional.FunctionalTest): 'visibility': visibility, }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) def list_images(tenant, role='', visibility=None): auth_token = 'user:%s:%s' % (tenant, role) @@ -2753,7 +2756,7 @@ class TestImages(functional.FunctionalTest): if visibility is not None: path += '?visibility=%s' % visibility response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) return jsonutils.loads(response.text)['images'] # 1. Known user sees public and their own images @@ -2835,7 +2838,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned image entity should have a generated id and status image = jsonutils.loads(response.text) @@ -2853,12 +2856,12 @@ class TestImages(functional.FunctionalTest): 'value': [{'url': url, 'metadata': {}}] }]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # The image size should be updated path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertEqual(10, image['size']) @@ -2871,7 +2874,7 @@ class TestImages(functional.FunctionalTest): data = jsonutils.dumps({'name': 'image-1', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned image entity should have a generated id and status image = jsonutils.loads(response.text) @@ -2889,14 +2892,14 @@ class TestImages(functional.FunctionalTest): 'metadata': {}}] }]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(400, response.status_code, response.text) + self.assertEqual(http.BAD_REQUEST, response.status_code, response.text) data = jsonutils.dumps([{'op': 'replace', 'path': '/locations', 'value': [{'url': 'swift+config:///foo_image', 'metadata': {}}] }]) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(400, response.status_code, response.text) + self.assertEqual(http.BAD_REQUEST, response.status_code, response.text) class TestImagesWithRegistry(TestImages): @@ -2933,7 +2936,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): self.start_servers(**self.__dict__.copy()) path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(300, response.status_code) + self.assertEqual(http.MULTIPLE_CHOICES, response.status_code) self.stop_servers() def test_v2_enabled(self): @@ -2941,7 +2944,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): self.start_servers(**self.__dict__.copy()) path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.stop_servers() def test_image_direct_url_visible(self): @@ -2952,7 +2955,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): # Image list should be empty path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -2964,7 +2967,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): 'container_format': 'aki', 'visibility': 'public'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image id image = jsonutils.loads(response.text) @@ -2974,7 +2977,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): path = self._url('/v2/images/%s' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertNotIn('direct_url', image) @@ -2982,13 +2985,13 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='ZZZZZ') - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Image direct_url should be visible path = self._url('/v2/images/%s' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertIn('direct_url', image) @@ -2997,7 +3000,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): headers = self._headers({'Content-Type': 'application/json', 'X-Tenant-Id': TENANT2}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertIn('direct_url', image) @@ -3005,7 +3008,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): path = self._url('/v2/images') headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text)['images'][0] self.assertIn('direct_url', image) @@ -3022,7 +3025,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): 'foo': 'bar', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image id image = jsonutils.loads(response.text) @@ -3032,7 +3035,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): path = self._url('/v2/images/%s' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertIn('locations', image) self.assertEqual([], image["locations"]) @@ -3041,13 +3044,13 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='ZZZZZ') - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Image locations should be visible path = self._url('/v2/images/%s' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertIn('locations', image) loc = image['locations'] @@ -3066,7 +3069,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): # Image list should be empty path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -3077,7 +3080,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): 'foo': 'bar', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image id image = jsonutils.loads(response.text) @@ -3087,13 +3090,13 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): path = self._url('/v2/images/%s/file' % image_id) headers = self._headers({'Content-Type': 'application/octet-stream'}) response = requests.put(path, headers=headers, data='ZZZZZ') - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Image direct_url should not be visible path = self._url('/v2/images/%s' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertNotIn('direct_url', image) @@ -3101,7 +3104,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest): path = self._url('/v2/images') headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text)['images'][0] self.assertNotIn('direct_url', image) @@ -3166,7 +3169,7 @@ class TestImageLocationSelectionStrategy(functional.FunctionalTest): 'foo': 'bar', 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the image id image = jsonutils.loads(response.text) @@ -3176,7 +3179,7 @@ class TestImageLocationSelectionStrategy(functional.FunctionalTest): path = self._url('/v2/images/%s' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertIn('locations', image) self.assertEqual([], image["locations"]) @@ -3194,13 +3197,13 @@ class TestImageLocationSelectionStrategy(functional.FunctionalTest): 'value': values}] data = jsonutils.dumps(doc) response = requests.patch(path, headers=headers, data=data) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) # Image locations should be visible path = self._url('/v2/images/%s' % image_id) headers = self._headers({'Content-Type': 'application/json'}) response = requests.get(path, headers=headers) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image = jsonutils.loads(response.text) self.assertIn('locations', image) self.assertEqual(values, image['locations']) @@ -3252,7 +3255,7 @@ class TestImageMembers(functional.FunctionalTest): # Image list should be empty path = self._url('/v2/images') response = requests.get(path, headers=get_header('tenant1')) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -3271,20 +3274,20 @@ class TestImageMembers(functional.FunctionalTest): 'visibility': visibility, }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image_fixture.append(jsonutils.loads(response.text)) # Image list should contain 4 images for tenant1 path = self._url('/v2/images') response = requests.get(path, headers=get_header('tenant1')) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(4, len(images)) # Image list should contain 3 images for TENANT3 path = self._url('/v2/images') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(3, len(images)) @@ -3293,7 +3296,7 @@ class TestImageMembers(functional.FunctionalTest): body = jsonutils.dumps({'member': TENANT3}) response = requests.post(path, headers=get_header('tenant1'), data=body) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image_member = jsonutils.loads(response.text) self.assertEqual(image_fixture[1]['id'], image_member['image_id']) self.assertEqual(TENANT3, image_member['member_id']) @@ -3304,7 +3307,7 @@ class TestImageMembers(functional.FunctionalTest): # Image list should contain 3 images for TENANT3 path = self._url('/v2/images') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(3, len(images)) @@ -3312,21 +3315,21 @@ class TestImageMembers(functional.FunctionalTest): # because default is accepted path = self._url('/v2/images?visibility=shared') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) # Image list should contain 4 images for TENANT3 with status pending path = self._url('/v2/images?member_status=pending') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(4, len(images)) # Image list should contain 4 images for TENANT3 with status all path = self._url('/v2/images?member_status=all') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(4, len(images)) @@ -3334,7 +3337,7 @@ class TestImageMembers(functional.FunctionalTest): # and visibility shared path = self._url('/v2/images?member_status=pending&visibility=shared') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(1, len(images)) self.assertEqual(images[0]['name'], 'tenant1-private') @@ -3343,7 +3346,7 @@ class TestImageMembers(functional.FunctionalTest): # and visibility shared path = self._url('/v2/images?member_status=rejected&visibility=shared') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -3351,7 +3354,7 @@ class TestImageMembers(functional.FunctionalTest): # and visibility shared path = self._url('/v2/images?member_status=accepted&visibility=shared') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -3359,14 +3362,14 @@ class TestImageMembers(functional.FunctionalTest): # and visibility private path = self._url('/v2/images?visibility=private') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) # Image tenant2-private's image members list should contain no members path = self._url('/v2/images/%s/members' % image_fixture[3]['id']) response = requests.get(path, headers=get_header('tenant2')) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(0, len(body['members'])) @@ -3375,13 +3378,13 @@ class TestImageMembers(functional.FunctionalTest): TENANT3)) body = jsonutils.dumps({'status': 'accepted'}) response = requests.put(path, headers=get_header('tenant1'), data=body) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Tenant 1, who is the owner can get status of its own image member path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'], TENANT3)) response = requests.get(path, headers=get_header('tenant1')) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual('pending', body['status']) self.assertEqual(image_fixture[1]['id'], body['image_id']) @@ -3391,7 +3394,7 @@ class TestImageMembers(functional.FunctionalTest): path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'], TENANT3)) response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual('pending', body['status']) self.assertEqual(image_fixture[1]['id'], body['image_id']) @@ -3401,14 +3404,14 @@ class TestImageMembers(functional.FunctionalTest): path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'], TENANT3)) response = requests.get(path, headers=get_header('tenant2')) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Tenant 3 can change status of image member path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'], TENANT3)) body = jsonutils.dumps({'status': 'accepted'}) response = requests.put(path, headers=get_header(TENANT3), data=body) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image_member = jsonutils.loads(response.text) self.assertEqual(image_fixture[1]['id'], image_member['image_id']) self.assertEqual(TENANT3, image_member['member_id']) @@ -3418,7 +3421,7 @@ class TestImageMembers(functional.FunctionalTest): # accepted path = self._url('/v2/images') response = requests.get(path, headers=get_header(TENANT3)) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(4, len(images)) @@ -3427,21 +3430,21 @@ class TestImageMembers(functional.FunctionalTest): TENANT3)) body = jsonutils.dumps({'status': 'invalid-status'}) response = requests.put(path, headers=get_header(TENANT3), data=body) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Owner cannot change status of image path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'], TENANT3)) body = jsonutils.dumps({'status': 'accepted'}) response = requests.put(path, headers=get_header('tenant1'), data=body) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Add Image member for tenant2-private image path = self._url('/v2/images/%s/members' % image_fixture[3]['id']) body = jsonutils.dumps({'member': TENANT4}) response = requests.post(path, headers=get_header('tenant2'), data=body) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image_member = jsonutils.loads(response.text) self.assertEqual(image_fixture[3]['id'], image_member['image_id']) self.assertEqual(TENANT4, image_member['member_id']) @@ -3453,49 +3456,49 @@ class TestImageMembers(functional.FunctionalTest): body = jsonutils.dumps({'member': TENANT2}) response = requests.post(path, headers=get_header('tenant1'), data=body) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Image tenant1-private's members list should contain 1 member path = self._url('/v2/images/%s/members' % image_fixture[1]['id']) response = requests.get(path, headers=get_header('tenant1')) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(1, len(body['members'])) # Admin can see any members path = self._url('/v2/images/%s/members' % image_fixture[1]['id']) response = requests.get(path, headers=get_header('tenant1', 'admin')) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(1, len(body['members'])) # Image members not found for private image not owned by TENANT 1 path = self._url('/v2/images/%s/members' % image_fixture[3]['id']) response = requests.get(path, headers=get_header('tenant1')) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Image members forbidden for public image path = self._url('/v2/images/%s/members' % image_fixture[0]['id']) response = requests.get(path, headers=get_header('tenant1')) self.assertIn("Public images do not have members", response.text) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Image Member Cannot delete Image membership path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'], TENANT3)) response = requests.delete(path, headers=get_header(TENANT3)) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Delete Image member path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'], TENANT3)) response = requests.delete(path, headers=get_header('tenant1')) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Now the image has no members path = self._url('/v2/images/%s/members' % image_fixture[1]['id']) response = requests.get(path, headers=get_header('tenant1')) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.loads(response.text) self.assertEqual(0, len(body['members'])) @@ -3505,24 +3508,24 @@ class TestImageMembers(functional.FunctionalTest): body = jsonutils.dumps({'member': str(uuid.uuid4())}) response = requests.post(path, headers=get_header('tenant1'), data=body) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) body = jsonutils.dumps({'member': str(uuid.uuid4())}) response = requests.post(path, headers=get_header('tenant1'), data=body) - self.assertEqual(413, response.status_code) + self.assertEqual(http.REQUEST_ENTITY_TOO_LARGE, response.status_code) # Get Image member should return not found for public image path = self._url('/v2/images/%s/members/%s' % (image_fixture[0]['id'], TENANT3)) response = requests.get(path, headers=get_header('tenant1')) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Delete Image member should return forbidden for public image path = self._url('/v2/images/%s/members/%s' % (image_fixture[0]['id'], TENANT3)) response = requests.delete(path, headers=get_header('tenant1')) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) self.stop_servers() @@ -3563,7 +3566,7 @@ class TestQuotas(functional.FunctionalTest): # Image list should be empty path = self._url('/v2/images') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images = jsonutils.loads(response.text)['images'] self.assertEqual(0, len(images)) @@ -3576,7 +3579,7 @@ class TestQuotas(functional.FunctionalTest): 'disk_format': 'aki', 'container_format': 'aki'}) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) image = jsonutils.loads(response.text) image_id = image['id'] @@ -3589,27 +3592,27 @@ class TestQuotas(functional.FunctionalTest): # Deletion should work path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) def test_image_upload_under_quota(self): data = 'x' * (self.user_storage_quota - 1) - self._upload_image_test(data, 204) + self._upload_image_test(data, http.NO_CONTENT) def test_image_upload_exceed_quota(self): data = 'x' * (self.user_storage_quota + 1) - self._upload_image_test(data, 413) + self._upload_image_test(data, http.REQUEST_ENTITY_TOO_LARGE) def test_chunked_image_upload_under_quota(self): def data_gen(): yield 'x' * (self.user_storage_quota - 1) - self._upload_image_test(data_gen(), 204) + self._upload_image_test(data_gen(), http.NO_CONTENT) def test_chunked_image_upload_exceed_quota(self): def data_gen(): yield 'x' * (self.user_storage_quota + 1) - self._upload_image_test(data_gen(), 413) + self._upload_image_test(data_gen(), http.REQUEST_ENTITY_TOO_LARGE) class TestQuotasWithRegistry(TestQuotas): diff --git a/glance/tests/functional/v2/test_metadef_namespaces.py b/glance/tests/functional/v2/test_metadef_namespaces.py index 0e90ed4279..99c3e9c4aa 100644 --- a/glance/tests/functional/v2/test_metadef_namespaces.py +++ b/glance/tests/functional/v2/test_metadef_namespaces.py @@ -17,6 +17,7 @@ import uuid from oslo_serialization import jsonutils import requests +from six.moves import http_client as http from glance.tests import functional @@ -50,7 +51,7 @@ class TestNamespaces(functional.FunctionalTest): # Namespace should not exist path = self._url('/v2/metadefs/namespaces/MyNamespace') response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create a namespace path = self._url('/v2/metadefs/namespaces') @@ -63,7 +64,7 @@ class TestNamespaces(functional.FunctionalTest): } ) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) namespace_loc_header = response.headers['Location'] # Returned namespace should match the created namespace with default @@ -98,11 +99,11 @@ class TestNamespaces(functional.FunctionalTest): # Attempt to insert a duplicate response = requests.post(path, headers=headers, data=data) - self.assertEqual(409, response.status_code) + self.assertEqual(http.CONFLICT, response.status_code) # Get the namespace using the returned Location header response = requests.get(namespace_loc_header, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) namespace = jsonutils.loads(response.text) self.assertEqual(namespace_name, namespace['namespace']) self.assertNotIn('object', namespace) @@ -126,7 +127,7 @@ class TestNamespaces(functional.FunctionalTest): } ) response = requests.put(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned namespace should reflect the changes namespace = jsonutils.loads(response.text) @@ -140,7 +141,7 @@ class TestNamespaces(functional.FunctionalTest): # Updates should persist across requests path = self._url('/v2/metadefs/namespaces/%s' % namespace_name) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) namespace = jsonutils.loads(response.text) self.assertEqual('MyNamespace-UPDATED', namespace['namespace']) self.assertEqual('display_name-UPDATED', namespace['display_name']) @@ -152,7 +153,7 @@ class TestNamespaces(functional.FunctionalTest): # Deletion should not work on protected namespaces path = self._url('/v2/metadefs/namespaces/%s' % namespace_name) response = requests.delete(path, headers=self._headers()) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) # Unprotect namespace for deletion path = self._url('/v2/metadefs/namespaces/%s' % namespace_name) @@ -168,23 +169,23 @@ class TestNamespaces(functional.FunctionalTest): } data = jsonutils.dumps(doc) response = requests.put(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Deletion should work. Deleting namespace MyNamespace path = self._url('/v2/metadefs/namespaces/%s' % namespace_name) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # Namespace should not exist path = self._url('/v2/metadefs/namespaces/MyNamespace') response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) def test_metadef_dont_accept_illegal_bodies(self): # Namespace should not exist path = self._url('/v2/metadefs/namespaces/bodytest') response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create a namespace path = self._url('/v2/metadefs/namespaces') @@ -197,7 +198,7 @@ class TestNamespaces(functional.FunctionalTest): } ) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Test all the urls that supply data data_urls = [ @@ -217,7 +218,7 @@ class TestNamespaces(functional.FunctionalTest): path = self._url(value) data = jsonutils.dumps(["body"]) response = requests.get(path, headers=self._headers(), data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) # Put the namespace into the url test_urls = [ @@ -238,4 +239,4 @@ class TestNamespaces(functional.FunctionalTest): data = jsonutils.dumps(["body"]) response = getattr(requests, method)( path, headers=self._headers(), data=data) - self.assertEqual(400, response.status_code) + self.assertEqual(http.BAD_REQUEST, response.status_code) diff --git a/glance/tests/functional/v2/test_metadef_objects.py b/glance/tests/functional/v2/test_metadef_objects.py index 8a14d0ce62..98a94cb6a9 100644 --- a/glance/tests/functional/v2/test_metadef_objects.py +++ b/glance/tests/functional/v2/test_metadef_objects.py @@ -17,6 +17,7 @@ import uuid from oslo_serialization import jsonutils import requests +from six.moves import http_client as http from glance.tests import functional @@ -49,7 +50,7 @@ class TestMetadefObjects(functional.FunctionalTest): # Namespace should not exist path = self._url('/v2/metadefs/namespaces/MyNamespace') response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create a namespace path = self._url('/v2/metadefs/namespaces') @@ -65,12 +66,12 @@ class TestMetadefObjects(functional.FunctionalTest): } ) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Metadata objects should not exist path = self._url('/v2/metadefs/namespaces/MyNamespace/objects/object1') response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create a object path = self._url('/v2/metadefs/namespaces/MyNamespace/objects') @@ -105,18 +106,18 @@ class TestMetadefObjects(functional.FunctionalTest): } ) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Attempt to insert a duplicate response = requests.post(path, headers=headers, data=data) - self.assertEqual(409, response.status_code) + self.assertEqual(http.CONFLICT, response.status_code) # Get the metadata object created above path = self._url('/v2/metadefs/namespaces/%s/objects/%s' % (namespace_name, metadata_object_name)) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) metadata_object = jsonutils.loads(response.text) self.assertEqual("object1", metadata_object['name']) @@ -216,7 +217,7 @@ class TestMetadefObjects(functional.FunctionalTest): } ) response = requests.put(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned metadata_object should reflect the changes metadata_object = jsonutils.loads(response.text) @@ -263,10 +264,10 @@ class TestMetadefObjects(functional.FunctionalTest): path = self._url('/v2/metadefs/namespaces/%s/objects/%s' % (namespace_name, metadata_object_name)) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # metadata_object object1 should not exist path = self._url('/v2/metadefs/namespaces/%s/objects/%s' % (namespace_name, metadata_object_name)) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) diff --git a/glance/tests/functional/v2/test_metadef_properties.py b/glance/tests/functional/v2/test_metadef_properties.py index 9909bd0d3f..3d55eaebdb 100644 --- a/glance/tests/functional/v2/test_metadef_properties.py +++ b/glance/tests/functional/v2/test_metadef_properties.py @@ -17,6 +17,7 @@ import uuid from oslo_serialization import jsonutils import requests +from six.moves import http_client as http from glance.tests import functional @@ -49,7 +50,7 @@ class TestNamespaceProperties(functional.FunctionalTest): # Namespace should not exist path = self._url('/v2/metadefs/namespaces/MyNamespace') response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create a namespace path = self._url('/v2/metadefs/namespaces') @@ -72,13 +73,13 @@ class TestNamespaceProperties(functional.FunctionalTest): ] }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Property1 should not exist path = self._url('/v2/metadefs/namespaces/MyNamespace/properties' '/property1') response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create a property path = self._url('/v2/metadefs/namespaces/MyNamespace/properties') @@ -97,17 +98,17 @@ class TestNamespaceProperties(functional.FunctionalTest): } ) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Attempt to insert a duplicate response = requests.post(path, headers=headers, data=data) - self.assertEqual(409, response.status_code) + self.assertEqual(http.CONFLICT, response.status_code) # Get the property created above path = self._url('/v2/metadefs/namespaces/%s/properties/%s' % (namespace_name, property_name)) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) property_object = jsonutils.loads(response.text) self.assertEqual("integer", property_object['type']) self.assertEqual("property1", property_object['title']) @@ -122,7 +123,7 @@ class TestNamespaceProperties(functional.FunctionalTest): namespace_name, property_name, '='.join(['?resource_type', resource_type_name]))) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Get the property with prefix and specific resource type association property_name_with_prefix = ''.join([resource_type_prefix, @@ -131,7 +132,7 @@ class TestNamespaceProperties(functional.FunctionalTest): namespace_name, property_name_with_prefix, '='.join([ '?resource_type', resource_type_name]))) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) property_object = jsonutils.loads(response.text) self.assertEqual("integer", property_object['type']) self.assertEqual("property1", property_object['title']) @@ -188,7 +189,7 @@ class TestNamespaceProperties(functional.FunctionalTest): } ) response = requests.put(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned property should reflect the changes property_object = jsonutils.loads(response.text) @@ -215,10 +216,10 @@ class TestNamespaceProperties(functional.FunctionalTest): path = self._url('/v2/metadefs/namespaces/%s/properties/%s' % (namespace_name, property_name)) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # property1 should not exist path = self._url('/v2/metadefs/namespaces/%s/properties/%s' % (namespace_name, property_name)) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) diff --git a/glance/tests/functional/v2/test_metadef_resourcetypes.py b/glance/tests/functional/v2/test_metadef_resourcetypes.py index f06baf8a92..cc047d6111 100644 --- a/glance/tests/functional/v2/test_metadef_resourcetypes.py +++ b/glance/tests/functional/v2/test_metadef_resourcetypes.py @@ -17,6 +17,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import encodeutils import six +from six.moves import http_client as http import webob.exc from wsme.rest import json @@ -183,13 +184,13 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def create(self, response, result): resource_type_json = json.tojson(ResourceTypeAssociation, result) - response.status_int = 201 + response.status_int = http.CREATED body = jsonutils.dumps(resource_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' def delete(self, response, result): - response.status_int = 204 + response.status_int = http.NO_CONTENT def _get_base_properties(): diff --git a/glance/tests/functional/v2/test_metadef_tags.py b/glance/tests/functional/v2/test_metadef_tags.py index d6a75a04c8..520a1ce135 100644 --- a/glance/tests/functional/v2/test_metadef_tags.py +++ b/glance/tests/functional/v2/test_metadef_tags.py @@ -17,6 +17,7 @@ import uuid from oslo_serialization import jsonutils import requests +from six.moves import http_client as http from glance.tests import functional @@ -49,7 +50,7 @@ class TestMetadefTags(functional.FunctionalTest): # Namespace should not exist path = self._url('/v2/metadefs/namespaces/MyNamespace') response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create a namespace path = self._url('/v2/metadefs/namespaces') @@ -64,24 +65,24 @@ class TestMetadefTags(functional.FunctionalTest): "owner": "The Test Owner"} ) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Metadata tag should not exist metadata_tag_name = "tag1" path = self._url('/v2/metadefs/namespaces/%s/tags/%s' % (namespace_name, metadata_tag_name)) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create the metadata tag headers = self._headers({'content-type': 'application/json'}) response = requests.post(path, headers=headers) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Get the metadata tag created above response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) metadata_tag = jsonutils.loads(response.text) self.assertEqual(metadata_tag_name, metadata_tag['name']) @@ -108,7 +109,7 @@ class TestMetadefTags(functional.FunctionalTest): # Try to create a duplicate metadata tag headers = self._headers({'content-type': 'application/json'}) response = requests.post(path, headers=headers) - self.assertEqual(409, response.status_code) + self.assertEqual(http.CONFLICT, response.status_code) # The metadata_tag should be mutable path = self._url('/v2/metadefs/namespaces/%s/tags/%s' % @@ -122,7 +123,7 @@ class TestMetadefTags(functional.FunctionalTest): } ) response = requests.put(path, headers=headers, data=data) - self.assertEqual(200, response.status_code, response.text) + self.assertEqual(http.OK, response.status_code, response.text) # Returned metadata_tag should reflect the changes metadata_tag = jsonutils.loads(response.text) @@ -132,20 +133,20 @@ class TestMetadefTags(functional.FunctionalTest): path = self._url('/v2/metadefs/namespaces/%s/tags/%s' % (namespace_name, metadata_tag_name)) response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) self.assertEqual('tag1-UPDATED', metadata_tag['name']) # Deletion of metadata_tag_name path = self._url('/v2/metadefs/namespaces/%s/tags/%s' % (namespace_name, metadata_tag_name)) response = requests.delete(path, headers=self._headers()) - self.assertEqual(204, response.status_code) + self.assertEqual(http.NO_CONTENT, response.status_code) # metadata_tag_name should not exist path = self._url('/v2/metadefs/namespaces/%s/tags/%s' % (namespace_name, metadata_tag_name)) response = requests.get(path, headers=self._headers()) - self.assertEqual(404, response.status_code) + self.assertEqual(http.NOT_FOUND, response.status_code) # Create multiple tags. path = self._url('/v2/metadefs/namespaces/%s/tags' % @@ -155,11 +156,11 @@ class TestMetadefTags(functional.FunctionalTest): {"tags": [{"name": "tag1"}, {"name": "tag2"}, {"name": "tag3"}]} ) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # List out the three new tags. response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(3, len(tags)) @@ -168,10 +169,10 @@ class TestMetadefTags(functional.FunctionalTest): {"tags": [{"name": "tag4"}, {"name": "tag5"}, {"name": "tag4"}]} ) response = requests.post(path, headers=headers, data=data) - self.assertEqual(409, response.status_code) + self.assertEqual(http.CONFLICT, response.status_code) # Verify the previous 3 still exist response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tags = jsonutils.loads(response.text)['tags'] self.assertEqual(3, len(tags)) diff --git a/glance/tests/functional/v2/test_schemas.py b/glance/tests/functional/v2/test_schemas.py index 63eb8d5047..2257e95de4 100644 --- a/glance/tests/functional/v2/test_schemas.py +++ b/glance/tests/functional/v2/test_schemas.py @@ -15,6 +15,7 @@ from oslo_serialization import jsonutils import requests +from six.moves import http_client as http from glance.tests import functional @@ -30,7 +31,7 @@ class TestSchemas(functional.FunctionalTest): # Ensure the image link works and custom properties are loaded path = 'http://%s:%d/v2/schemas/image' % ('127.0.0.1', self.api_port) response = requests.get(path) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) image_schema = jsonutils.loads(response.text) expected = set([ 'id', @@ -60,7 +61,7 @@ class TestSchemas(functional.FunctionalTest): # Ensure the images link works and agrees with the image schema path = 'http://%s:%d/v2/schemas/images' % ('127.0.0.1', self.api_port) response = requests.get(path) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) images_schema = jsonutils.loads(response.text) item_schema = images_schema['properties']['images']['items'] self.assertEqual(item_schema, image_schema) diff --git a/glance/tests/functional/v2/test_tasks.py b/glance/tests/functional/v2/test_tasks.py index 5522ba27d5..674dd53e58 100644 --- a/glance/tests/functional/v2/test_tasks.py +++ b/glance/tests/functional/v2/test_tasks.py @@ -18,6 +18,7 @@ import uuid from oslo_serialization import jsonutils import requests +from six.moves import http_client as http from glance.tests import functional @@ -55,14 +56,14 @@ class TestTasks(functional.FunctionalTest): # Task list should be empty path = self._url('/v2/tasks') response = requests.get(path, headers=self._headers(roles)) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) def test_task_lifecycle(self): self.start_servers(**self.__dict__.copy()) # Task list should be empty path = self._url('/v2/tasks') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tasks = jsonutils.loads(response.text)['tasks'] self.assertEqual(0, len(tasks)) @@ -82,7 +83,7 @@ class TestTasks(functional.FunctionalTest): } }) response = requests.post(path, headers=headers, data=data) - self.assertEqual(201, response.status_code) + self.assertEqual(http.CREATED, response.status_code) # Returned task entity should have a generated id and status task = jsonutils.loads(response.text) @@ -121,7 +122,7 @@ class TestTasks(functional.FunctionalTest): # Tasks list should now have one entry path = self._url('/v2/tasks') response = requests.get(path, headers=self._headers()) - self.assertEqual(200, response.status_code) + self.assertEqual(http.OK, response.status_code) tasks = jsonutils.loads(response.text)['tasks'] self.assertEqual(1, len(tasks)) self.assertEqual(task_id, tasks[0]['id']) @@ -129,7 +130,7 @@ class TestTasks(functional.FunctionalTest): # Attempt to delete a task path = self._url('/v2/tasks/%s' % tasks[0]['id']) response = requests.delete(path, headers=self._headers()) - self.assertEqual(405, response.status_code) + self.assertEqual(http.METHOD_NOT_ALLOWED, response.status_code) self.assertIsNotNone(response.headers.get('Allow')) self.assertEqual('GET', response.headers.get('Allow')) diff --git a/glance/tests/integration/legacy_functional/test_v1_api.py b/glance/tests/integration/legacy_functional/test_v1_api.py index 696d4dd21a..87f1136f81 100644 --- a/glance/tests/integration/legacy_functional/test_v1_api.py +++ b/glance/tests/integration/legacy_functional/test_v1_api.py @@ -17,6 +17,7 @@ import tempfile from oslo_serialization import jsonutils from oslo_utils import units +from six.moves import http_client import testtools from glance.common import timeutils @@ -33,14 +34,14 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) # 1. GET /images/detail # Verify no public images path = "/v1/images/detail" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) # 2. POST /images with public image named Image1 @@ -50,7 +51,7 @@ class TestApi(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] self.assertEqual(hashlib.md5(image_data).hexdigest(), @@ -63,14 +64,14 @@ class TestApi(base.ApiTest): # Verify image found now path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual("Image1", response['x-image-meta-name']) # 4. GET image # Verify all information on image we just added is correct path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_image_headers = { 'x-image-meta-id': image_id, @@ -107,7 +108,7 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_result = {"images": [ {"container_format": "ovf", @@ -122,7 +123,7 @@ class TestApi(base.ApiTest): # Verify image and all its metadata path = "/v1/images/detail" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_image = { "status": "active", @@ -151,7 +152,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Property-Arch': 'x86_64'} path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual("x86_64", data['image']['properties']['arch']) self.assertEqual("Ubuntu", data['image']['properties']['distro']) @@ -160,7 +161,7 @@ class TestApi(base.ApiTest): # Verify image and all its metadata path = "/v1/images/detail" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_image = { "status": "active", @@ -187,11 +188,11 @@ class TestApi(base.ApiTest): headers = {'X-Image-Meta-Property-Arch': 'x86_64'} path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) path = "/v1/images/detail" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content)['images'][0] self.assertEqual(1, len(data['properties'])) self.assertEqual("x86_64", data['properties']['arch']) @@ -201,12 +202,12 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Property-Arch': 'x86_64'} path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) path = "/v1/images/detail" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content)['images'][0] self.assertEqual(2, len(data['properties'])) self.assertEqual("x86_64", data['properties']['arch']) @@ -216,7 +217,7 @@ class TestApi(base.ApiTest): # DELETE image path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) def test_queued_process_flow(self): """ @@ -246,7 +247,7 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) # 1. POST /images with public image named Image1 @@ -254,7 +255,7 @@ class TestApi(base.ApiTest): headers = minimal_headers('Image1') path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertIsNone(data['image']['checksum']) self.assertEqual(0, data['image']['size']) @@ -269,7 +270,7 @@ class TestApi(base.ApiTest): # Verify 1 public image path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(image_id, data['images'][0]['id']) self.assertIsNone(data['images'][0]['checksum']) @@ -282,7 +283,7 @@ class TestApi(base.ApiTest): # Verify status is in queued path = "/v1/images/%s" % (image_id) response, content = self.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("queued", response['x-image-meta-status']) self.assertEqual('0', response['x-image-meta-size']) @@ -294,7 +295,7 @@ class TestApi(base.ApiTest): path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'PUT', headers=headers, body=image_data) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(hashlib.md5(image_data).hexdigest(), data['image']['checksum']) @@ -306,7 +307,7 @@ class TestApi(base.ApiTest): # Verify status is in active path = "/v1/images/%s" % (image_id) response, content = self.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("active", response['x-image-meta-status']) @@ -314,7 +315,7 @@ class TestApi(base.ApiTest): # Verify 1 public image still... path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(hashlib.md5(image_data).hexdigest(), data['images'][0]['checksum']) @@ -327,19 +328,19 @@ class TestApi(base.ApiTest): # DELETE image path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) def test_v1_not_enabled(self): self.config(enable_v1_api=False) path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(300, response.status) + self.assertEqual(http_client.MULTIPLE_CHOICES, response.status) def test_v1_enabled(self): self.config(enable_v1_api=True) path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) def test_zero_initial_size(self): """ @@ -357,7 +358,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Is-Public': 'True'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] self.assertEqual('active', image['status']) @@ -365,14 +366,14 @@ class TestApi(base.ApiTest): # Verify image size is zero and the status is active path = response.get('location') response, content = self.http.request(path, 'HEAD') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('0', response['x-image-meta-size']) self.assertEqual('active', response['x-image-meta-status']) # 3. GET image-location # Verify image content is empty response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual(0, len(content)) def test_traceback_not_consumed(self): @@ -395,7 +396,7 @@ class TestApi(base.ApiTest): response, content = self.http.request(path, 'POST', body=test_data_file.name, headers=headers) - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) expected = "Content-Type must be application/octet-stream" self.assertIn(expected, content, "Could not find '%s' in '%s'" % (expected, content)) @@ -409,7 +410,7 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) image_ids = [] @@ -427,7 +428,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Property-pants': 'are on'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual("are on", data['image']['properties']['pants']) self.assertTrue(data['image']['is_public']) @@ -444,7 +445,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Property-pants': 'are on'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual("are on", data['image']['properties']['pants']) self.assertTrue(data['image']['is_public']) @@ -461,7 +462,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Property-pants': 'are off'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertEqual("are off", data['image']['properties']['pants']) self.assertTrue(data['image']['is_public']) @@ -477,7 +478,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Protected': 'False'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) self.assertFalse(data['image']['is_public']) image_ids.append(data['image']['id']) @@ -486,7 +487,7 @@ class TestApi(base.ApiTest): # Verify three public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(3, len(data['images'])) @@ -495,7 +496,7 @@ class TestApi(base.ApiTest): params = "name=My%20Image!" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(2, len(data['images'])) for image in data['images']: @@ -506,7 +507,7 @@ class TestApi(base.ApiTest): params = "status=queued" path = "/v1/images/detail?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(3, len(data['images'])) for image in data['images']: @@ -515,7 +516,7 @@ class TestApi(base.ApiTest): params = "status=active" path = "/v1/images/detail?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(0, len(data['images'])) @@ -524,7 +525,7 @@ class TestApi(base.ApiTest): params = "container_format=ovf" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(2, len(data['images'])) for image in data['images']: @@ -535,7 +536,7 @@ class TestApi(base.ApiTest): params = "disk_format=vdi" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(1, len(data['images'])) for image in data['images']: @@ -546,7 +547,7 @@ class TestApi(base.ApiTest): params = "size_max=20" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(2, len(data['images'])) for image in data['images']: @@ -557,7 +558,7 @@ class TestApi(base.ApiTest): params = "size_min=20" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(2, len(data['images'])) for image in data['images']: @@ -569,7 +570,7 @@ class TestApi(base.ApiTest): params = "is_public=None" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(4, len(data['images'])) @@ -579,7 +580,7 @@ class TestApi(base.ApiTest): params = "is_public=False" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(1, len(data['images'])) for image in data['images']: @@ -591,7 +592,7 @@ class TestApi(base.ApiTest): params = "is_public=True" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(3, len(data['images'])) for image in data['images']: @@ -602,7 +603,7 @@ class TestApi(base.ApiTest): params = "protected=False" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(2, len(data['images'])) for image in data['images']: @@ -613,7 +614,7 @@ class TestApi(base.ApiTest): params = "protected=True" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(1, len(data['images'])) for image in data['images']: @@ -624,7 +625,7 @@ class TestApi(base.ApiTest): params = "property-pants=are%20on" path = "/v1/images/detail?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(2, len(data['images'])) for image in data['images']: @@ -636,7 +637,7 @@ class TestApi(base.ApiTest): params = "name=My%20Image!&property-pants=are%20on" path = "/v1/images/detail?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(1, len(data['images'])) for image in data['images']: @@ -649,7 +650,7 @@ class TestApi(base.ApiTest): params = "changes-since=%s" % yesterday path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(3, len(data['images'])) @@ -663,7 +664,7 @@ class TestApi(base.ApiTest): params = "changes-since=%s" % hour_ago path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(3, len(data['images'])) @@ -673,7 +674,7 @@ class TestApi(base.ApiTest): params = "changes-since=%s" % tomorrow path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(0, len(data['images'])) @@ -683,7 +684,7 @@ class TestApi(base.ApiTest): params = "changes-since=%s" % hour_hence path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(0, len(data['images'])) @@ -692,7 +693,7 @@ class TestApi(base.ApiTest): params = "size_min=-1" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) self.assertIn("filter size_min got -1", content) # 19. GET /images with size_min filter @@ -700,7 +701,7 @@ class TestApi(base.ApiTest): params = "size_max=-1" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) self.assertIn("filter size_max got -1", content) # 20. GET /images with size_min filter @@ -708,7 +709,7 @@ class TestApi(base.ApiTest): params = "min_ram=-1" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) self.assertIn("Bad value passed to filter min_ram got -1", content) # 21. GET /images with size_min filter @@ -716,7 +717,7 @@ class TestApi(base.ApiTest): params = "protected=imalittleteapot" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) self.assertIn("protected got imalittleteapot", content) # 22. GET /images with size_min filter @@ -724,7 +725,7 @@ class TestApi(base.ApiTest): params = "is_public=imalittleteapot" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) self.assertIn("is_public got imalittleteapot", content) def test_limited_images(self): @@ -736,7 +737,7 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) image_ids = [] @@ -745,25 +746,25 @@ class TestApi(base.ApiTest): headers = minimal_headers('Image1') path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image_ids.append(jsonutils.loads(content)['image']['id']) headers = minimal_headers('Image2') path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image_ids.append(jsonutils.loads(content)['image']['id']) headers = minimal_headers('Image3') path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image_ids.append(jsonutils.loads(content)['image']['id']) # 2. GET /images with all images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(3, len(images)) @@ -772,7 +773,7 @@ class TestApi(base.ApiTest): params = "limit=2" path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content)['images'] self.assertEqual(2, len(data)) self.assertEqual(images[0]['id'], data[0]['id']) @@ -783,7 +784,7 @@ class TestApi(base.ApiTest): params = "marker=%s" % images[0]['id'] path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content)['images'] self.assertEqual(2, len(data)) self.assertEqual(images[1]['id'], data[0]['id']) @@ -794,7 +795,7 @@ class TestApi(base.ApiTest): params = "limit=1&marker=%s" % images[1]['id'] path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content)['images'] self.assertEqual(1, len(data)) self.assertEqual(images[2]['id'], data[0]['id']) @@ -804,7 +805,7 @@ class TestApi(base.ApiTest): params = "limit=1&marker=%s" % images[1]['id'] path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content)['images'] self.assertEqual(1, len(data)) self.assertEqual(images[2]['id'], data[0]['id']) @@ -813,7 +814,7 @@ class TestApi(base.ApiTest): for image_id in image_ids: path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) def test_ordered_images(self): """ @@ -823,7 +824,7 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) # 1. POST /images with three public images with various attributes @@ -837,7 +838,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Is-Public': 'True'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image_ids.append(jsonutils.loads(content)['image']['id']) headers = {'Content-Type': 'application/octet-stream', @@ -849,7 +850,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Is-Public': 'True'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image_ids.append(jsonutils.loads(content)['image']['id']) headers = {'Content-Type': 'application/octet-stream', @@ -861,14 +862,14 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Is-Public': 'True'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image_ids.append(jsonutils.loads(content)['image']['id']) # 2. GET /images with no query params # Verify three public images sorted by created_at desc path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(3, len(data['images'])) self.assertEqual(image_ids[2], data['images'][0]['id']) @@ -879,7 +880,7 @@ class TestApi(base.ApiTest): params = 'sort_key=name&sort_dir=asc' path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(3, len(data['images'])) self.assertEqual(image_ids[1], data['images'][0]['id']) @@ -890,7 +891,7 @@ class TestApi(base.ApiTest): params = 'sort_key=size&sort_dir=desc' path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(3, len(data['images'])) self.assertEqual(image_ids[0], data['images'][0]['id']) @@ -901,7 +902,7 @@ class TestApi(base.ApiTest): params = 'sort_key=size&sort_dir=desc&marker=%s' % image_ids[0] path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(2, len(data['images'])) self.assertEqual(image_ids[2], data['images'][0]['id']) @@ -911,7 +912,7 @@ class TestApi(base.ApiTest): params = 'sort_key=name&sort_dir=asc&marker=%s' % image_ids[2] path = "/v1/images?%s" % (params) response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) data = jsonutils.loads(content) self.assertEqual(0, len(data['images'])) @@ -919,7 +920,7 @@ class TestApi(base.ApiTest): for image_id in image_ids: path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'DELETE') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) def test_duplicate_image_upload(self): """ @@ -929,7 +930,7 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) # 1. POST /images with public image named Image1 @@ -942,7 +943,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Is-Public': 'True'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) image = jsonutils.loads(content)['image'] @@ -957,7 +958,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Is-Public': 'True'} path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(409, response.status) + self.assertEqual(http_client.CONFLICT, response.status) def test_delete_not_existing(self): """ @@ -973,14 +974,14 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('{"images": []}', content) # 1. DELETE /images/1 # Verify 404 returned path = "/v1/images/1" response, content = self.http.request(path, 'DELETE') - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) def _do_test_post_image_content_bad_format(self, format): """ @@ -992,7 +993,7 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(0, len(images)) @@ -1007,7 +1008,7 @@ class TestApi(base.ApiTest): response, content = self.http.request(path, 'POST', headers=headers, body=test_data_file.name) - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) type = format.replace('_format', '') expected = "Invalid %s format 'bad_value' for image" % type self.assertIn(expected, content, @@ -1017,7 +1018,7 @@ class TestApi(base.ApiTest): # Verify no public images path = "/v1/images" response, content = self.http.request(path, 'GET') - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) images = jsonutils.loads(content)['images'] self.assertEqual(0, len(images)) @@ -1043,7 +1044,7 @@ class TestApi(base.ApiTest): 'X-Image-Meta-Is-Public': 'True', } response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] self.addDetail('image_data', testtools.content.json_content(data)) @@ -1058,7 +1059,7 @@ class TestApi(base.ApiTest): response, content = self.http.request(path, 'PUT', headers=headers, body=test_data_file.name) - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) type = format.replace('_format', '').capitalize() expected = "%s format is not specified" % type self.assertIn(expected, content, @@ -1081,7 +1082,7 @@ class TestApi(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers, body=image_data) - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) images_dir = os.path.join(self.test_dir, 'images') image_count = len([name for name in os.listdir(images_dir) @@ -1128,14 +1129,14 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=create_headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('tenant2', response['x-image-meta-owner']) # Now add an image without admin privileges and ensure the owner @@ -1148,7 +1149,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=create_headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] @@ -1161,7 +1162,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('tenant1', response['x-image-meta-owner']) # Make sure the non-privileged user can't update their owner either @@ -1174,7 +1175,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'PUT', headers=update_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # We have to be admin to see the owner auth_headers = { @@ -1184,7 +1185,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('tenant1', response['x-image-meta-owner']) # An admin user should be able to update the owner @@ -1201,12 +1202,12 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'PUT', headers=update_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) path = "/v1/images/%s" % (image_id) response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('tenant2', response['x-image-meta-owner']) def test_image_visibility_to_different_users(self): @@ -1228,7 +1229,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_ids[name] = data['image']['id'] @@ -1239,7 +1240,7 @@ class TestApiWithFakeAuth(base.ApiTest): if is_public is not None: path += '?is_public=%s' % is_public response, content = self.http.request(path, 'GET', headers=headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) return jsonutils.loads(content)['images'] # 1. Known user sees public and their own images @@ -1324,7 +1325,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Create an image for role member without 'foo' auth_headers = { @@ -1338,7 +1339,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=auth_headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) # Returned image entity should have 'x_owner_foo' data = jsonutils.loads(content) @@ -1360,7 +1361,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=auth_headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] @@ -1379,7 +1380,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Attempt to create properties which are forbidden auth_headers = { @@ -1394,7 +1395,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Attempt to update, create and delete properties auth_headers = { @@ -1411,7 +1412,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # Returned image entity should reflect the changes image = jsonutils.loads(content) @@ -1436,7 +1437,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'DELETE', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # This image should be no longer be directly accessible auth_headers = { @@ -1445,7 +1446,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) def test_property_protections_special_chars(self): # Enable property protection @@ -1469,7 +1470,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=auth_headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] @@ -1485,7 +1486,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) image = jsonutils.loads(content) self.assertEqual('1', image['image']['properties']['x_all_permitted_admin']) @@ -1500,7 +1501,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) image = jsonutils.loads(content) self.assertEqual( '1', image['image']['properties']['x_all_permitted_joe_soap']) @@ -1513,7 +1514,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('1', response.get( 'x-image-meta-property-x_all_permitted_admin')) self.assertEqual('1', response.get( @@ -1524,7 +1525,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertEqual('1', response.get( 'x-image-meta-property-x_all_permitted_admin')) self.assertEqual('1', response.get( @@ -1543,7 +1544,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) image = jsonutils.loads(content) self.assertEqual('2', image['image']['properties']['x_all_permitted_admin']) @@ -1558,7 +1559,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) image = jsonutils.loads(content) self.assertEqual( '2', image['image']['properties']['x_all_permitted_joe_soap']) @@ -1576,7 +1577,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) image = jsonutils.loads(content) self.assertNotIn('x_all_permitted_admin', image['image']['properties']) auth_headers = { @@ -1589,7 +1590,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) image = jsonutils.loads(content) self.assertNotIn('x_all_permitted_joe_soap', image['image']['properties']) @@ -1606,7 +1607,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) auth_headers = { 'X-Auth-Token': 'user1:tenant1:joe_soap', } @@ -1617,7 +1618,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Verify neither admin nor unknown role can read properties marked with # '!' @@ -1632,7 +1633,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=auth_headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] auth_headers = { @@ -1641,7 +1642,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertRaises(KeyError, response.get, 'X-Image-Meta-Property-x_none_read') auth_headers = { @@ -1650,7 +1651,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'HEAD', headers=auth_headers) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertRaises(KeyError, response.get, 'X-Image-Meta-Property-x_none_read') @@ -1667,7 +1668,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=auth_headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] auth_headers = { @@ -1680,7 +1681,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) auth_headers = { 'X-Auth-Token': 'user1:tenant1:joe_soap', } @@ -1691,7 +1692,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) # Verify neither admin nor unknown role can delete properties marked # with '!' @@ -1706,7 +1707,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images" response, content = self.http.request(path, 'POST', headers=auth_headers) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = jsonutils.loads(content) image_id = data['image']['id'] auth_headers = { @@ -1719,7 +1720,7 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) auth_headers = { 'X-Auth-Token': 'user1:tenant1:joe_soap', } @@ -1730,4 +1731,4 @@ class TestApiWithFakeAuth(base.ApiTest): path = "/v1/images/%s" % image_id response, content = self.http.request(path, 'PUT', headers=auth_headers) - self.assertEqual(403, response.status) + self.assertEqual(http_client.FORBIDDEN, response.status) diff --git a/glance/tests/integration/v2/test_property_quota_violations.py b/glance/tests/integration/v2/test_property_quota_violations.py index 25b65b1f45..3c9a7a80ac 100644 --- a/glance/tests/integration/v2/test_property_quota_violations.py +++ b/glance/tests/integration/v2/test_property_quota_violations.py @@ -15,6 +15,7 @@ from oslo_config import cfg from oslo_serialization import jsonutils +from six.moves import http_client # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range @@ -43,7 +44,7 @@ class TestPropertyQuotaViolations(base.ApiTest): def _get(self, image_id=""): path = ('/v2/images/%s' % image_id).rstrip('/') rsp, content = self.http.request(path, 'GET', headers=self._headers()) - self.assertEqual(200, rsp.status) + self.assertEqual(http_client.OK, rsp.status) content = jsonutils.loads(content) return content @@ -52,7 +53,7 @@ class TestPropertyQuotaViolations(base.ApiTest): headers = self._headers({'content-type': 'application/json'}) rsp, content = self.http.request(path, 'POST', headers=headers, body=jsonutils.dumps(body)) - self.assertEqual(201, rsp.status) + self.assertEqual(http_client.CREATED, rsp.status) return jsonutils.loads(content) def _patch(self, image_id, body, expected_status): @@ -91,15 +92,17 @@ class TestPropertyQuotaViolations(base.ApiTest): self.config(image_property_quota=2) patch_body = [{'op': 'replace', 'path': '/k_4', 'value': 'v_4.new'}] - image = jsonutils.loads(self._patch(image_id, patch_body, 200)) + image = jsonutils.loads(self._patch(image_id, patch_body, + http_client.OK)) self.assertEqual('v_4.new', image['k_4']) patch_body = [{'op': 'remove', 'path': '/k_7'}] - image = jsonutils.loads(self._patch(image_id, patch_body, 200)) + image = jsonutils.loads(self._patch(image_id, patch_body, + http_client.OK)) self.assertNotIn('k_7', image) patch_body = [{'op': 'add', 'path': '/k_100', 'value': 'v_100'}] - self._patch(image_id, patch_body, 413) + self._patch(image_id, patch_body, http_client.REQUEST_ENTITY_TOO_LARGE) image = self._get(image_id) self.assertNotIn('k_100', image) @@ -107,7 +110,7 @@ class TestPropertyQuotaViolations(base.ApiTest): {'op': 'remove', 'path': '/k_5'}, {'op': 'add', 'path': '/k_100', 'value': 'v_100'}, ] - self._patch(image_id, patch_body, 413) + self._patch(image_id, patch_body, http_client.REQUEST_ENTITY_TOO_LARGE) image = self._get(image_id) self.assertNotIn('k_100', image) self.assertIn('k_5', image) @@ -119,7 +122,8 @@ class TestPropertyQuotaViolations(base.ApiTest): {'op': 'add', 'path': '/k_99', 'value': 'v_99'}] to_rm = ['k_%d' % i for i in range(orig_property_quota) if i != 7] patch_body.extend([{'op': 'remove', 'path': '/%s' % k} for k in to_rm]) - image = jsonutils.loads(self._patch(image_id, patch_body, 200)) + image = jsonutils.loads(self._patch(image_id, patch_body, + http_client.OK)) self.assertEqual('v_99', image['k_99']) self.assertEqual('v_100', image['k_100']) for k in to_rm: diff --git a/glance/tests/integration/v2/test_tasks_api.py b/glance/tests/integration/v2/test_tasks_api.py index 338610b401..6df8019805 100644 --- a/glance/tests/integration/v2/test_tasks_api.py +++ b/glance/tests/integration/v2/test_tasks_api.py @@ -15,6 +15,7 @@ import eventlet from oslo_serialization import jsonutils as json +from six.moves import http_client from glance.api.v2 import tasks from glance.common import timeutils @@ -73,7 +74,7 @@ class TestTasksApi(base.ApiTest): headers=minimal_task_headers()) content_dict = json.loads(content) - self.assertEqual(200, res.status) + self.assertEqual(http_client.OK, res.status) res_tasks = content_dict['tasks'] if len(res_tasks) != 0: for task in res_tasks: @@ -104,7 +105,7 @@ class TestTasksApi(base.ApiTest): headers=headers, body=body_content) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) task = json.loads(content) task_id = task['id'] @@ -124,7 +125,7 @@ class TestTasksApi(base.ApiTest): headers=minimal_task_headers()) content_dict = json.loads(content) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertFalse(content_dict['tasks']) # 1. GET /tasks/{task_id} @@ -134,7 +135,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(404, response.status) + self.assertEqual(http_client.NOT_FOUND, response.status) # 2. POST /tasks # Create a new task @@ -147,7 +148,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/tasks/%s" % task_id response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) # NOTE(sabari): wait for all task executions to finish before checking # task status. @@ -159,7 +160,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertIsNotNone(content) data = json.loads(content) @@ -182,7 +183,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/schemas/task" response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) schema = tasks.get_task_schema() expected_schema = schema.minimal() @@ -195,7 +196,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/schemas/tasks" response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) schema = tasks.get_collection_schema() expected_schema = schema.minimal() @@ -218,7 +219,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request( path, 'POST', headers=minimal_task_headers(task_owner), body=body_content) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = json.loads(content) task_id = data['id'] @@ -239,7 +240,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request( path, 'POST', headers=minimal_task_headers(task_owner), body=body_content) - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) # 1. POST /tasks # Create a new task with invalid input for type 'import' @@ -252,7 +253,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request( path, 'POST', headers=minimal_task_headers(task_owner), body=body_content) - self.assertEqual(400, response.status) + self.assertEqual(http_client.BAD_REQUEST, response.status) # NOTE(nikhil): wait for all task executions to finish before exiting # else there is a risk of running into deadlock @@ -266,7 +267,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) content_dict = json.loads(content) self.assertFalse(content_dict['tasks']) @@ -288,7 +289,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) content_dict = json.loads(content) self.assertEqual(2, len(content_dict['tasks'])) @@ -301,7 +302,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) content_dict = json.loads(content) self.assertEqual(1, len(content_dict['tasks'])) @@ -314,7 +315,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) content_dict = json.loads(content) self.assertEqual(1, len(content_dict['tasks'])) @@ -327,7 +328,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) content_dict = json.loads(content) self.assertEqual(2, len(content_dict['tasks'])) @@ -349,7 +350,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/tasks" response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) tasks = json.loads(content) self.assertFalse(tasks['tasks']) @@ -372,7 +373,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) tasks = json.loads(content)['tasks'] @@ -385,7 +386,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -400,7 +401,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -415,7 +416,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -432,7 +433,7 @@ class TestTasksApi(base.ApiTest): path = "/v2/tasks" response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) tasks = json.loads(content) self.assertFalse(tasks['tasks']) @@ -456,7 +457,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -471,7 +472,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) expected_task_owners = [TENANT1, TENANT2, TENANT3] expected_task_owners.sort() @@ -487,7 +488,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) actual_tasks = json.loads(content)['tasks'] self.assertEqual(2, len(actual_tasks)) @@ -503,7 +504,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) actual_tasks = json.loads(content)['tasks'] @@ -524,7 +525,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request( path, 'POST', headers=minimal_task_headers(task_owner), body=body_content) - self.assertEqual(201, response.status) + self.assertEqual(http_client.CREATED, response.status) data = json.loads(content) task_id = data['id'] @@ -535,7 +536,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'DELETE', headers=minimal_task_headers()) - self.assertEqual(405, response.status) + self.assertEqual(http_client.METHOD_NOT_ALLOWED, response.status) self.assertEqual('GET', response.webob_resp.headers.get('Allow')) self.assertEqual(('GET',), response.webob_resp.allow) self.assertEqual(('GET',), response.allow) @@ -546,7 +547,7 @@ class TestTasksApi(base.ApiTest): response, content = self.http.request(path, 'GET', headers=minimal_task_headers()) - self.assertEqual(200, response.status) + self.assertEqual(http_client.OK, response.status) self.assertIsNotNone(content) # NOTE(nikhil): wait for all task executions to finish before exiting diff --git a/glance/tests/unit/common/test_exception.py b/glance/tests/unit/common/test_exception.py index 4c38b9375b..33e7df9d9a 100644 --- a/glance/tests/unit/common/test_exception.py +++ b/glance/tests/unit/common/test_exception.py @@ -15,6 +15,7 @@ from oslo_utils import encodeutils import six +from six.moves import http_client as http from glance.common import exception from glance.tests import utils as test_utils @@ -38,12 +39,13 @@ class GlanceExceptionTestCase(test_utils.BaseTestCase): class FakeGlanceException(exception.GlanceException): message = "default message: %(code)s" - exc = FakeGlanceException(code=500) + exc = FakeGlanceException(code=http.INTERNAL_SERVER_ERROR) self.assertEqual("default message: 500", encodeutils.exception_to_unicode(exc)) def test_specified_error_msg_with_kwargs(self): - msg = exception.GlanceException('test: %(code)s', code=500) + msg = exception.GlanceException('test: %(code)s', + code=http.INTERNAL_SERVER_ERROR) self.assertIn('test: 500', encodeutils.exception_to_unicode(msg)) def test_non_unicode_error_msg(self): diff --git a/glance/tests/unit/common/test_rpc.py b/glance/tests/unit/common/test_rpc.py index 6d5fc6c368..c599b9c46a 100644 --- a/glance/tests/unit/common/test_rpc.py +++ b/glance/tests/unit/common/test_rpc.py @@ -21,6 +21,7 @@ from oslo_serialization import jsonutils from oslo_utils import encodeutils import routes import six +from six.moves import http_client as http import webob from glance.common import exception @@ -157,27 +158,27 @@ class TestRPCController(base.IsolatedUnitTest): # Body is not a list, it should fail req.body = jsonutils.dump_as_bytes({}) res = req.get_response(api) - self.assertEqual(400, res.status_int) + self.assertEqual(http.BAD_REQUEST, res.status_int) # cmd is not dict, it should fail. req.body = jsonutils.dump_as_bytes([None]) res = req.get_response(api) - self.assertEqual(400, res.status_int) + self.assertEqual(http.BAD_REQUEST, res.status_int) # No command key, it should fail. req.body = jsonutils.dump_as_bytes([{}]) res = req.get_response(api) - self.assertEqual(400, res.status_int) + self.assertEqual(http.BAD_REQUEST, res.status_int) # kwargs not dict, it should fail. req.body = jsonutils.dump_as_bytes([{"command": "test", "kwargs": 2}]) res = req.get_response(api) - self.assertEqual(400, res.status_int) + self.assertEqual(http.BAD_REQUEST, res.status_int) # Command does not exist, it should fail. req.body = jsonutils.dump_as_bytes([{"command": "test"}]) res = req.get_response(api) - self.assertEqual(404, res.status_int) + self.assertEqual(http.NOT_FOUND, res.status_int) def test_rpc_exception_propagation(self): api = create_api() @@ -187,7 +188,7 @@ class TestRPCController(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes([{"command": "raise_value_error"}]) res = req.get_response(api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) returned = jsonutils.loads(res.body)[0] err_cls = 'builtins.ValueError' if six.PY3 else 'exceptions.ValueError' @@ -195,7 +196,7 @@ class TestRPCController(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes([{"command": "raise_weird_error"}]) res = req.get_response(api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) returned = jsonutils.loads(res.body)[0] self.assertEqual('glance.common.exception.RPCError', @@ -284,7 +285,7 @@ class TestRPCJSONSerializer(test_utils.BaseTestCase): fixture = {"key": "value"} response = webob.Response() rpc.RPCJSONSerializer().default(response, fixture) - self.assertEqual(200, response.status_int) + self.assertEqual(http.OK, response.status_int) content_types = [h for h in response.headerlist if h[0] == 'Content-Type'] self.assertEqual(1, len(content_types)) diff --git a/glance/tests/unit/common/test_wsgi.py b/glance/tests/unit/common/test_wsgi.py index 5d7934d137..e152f2d99a 100644 --- a/glance/tests/unit/common/test_wsgi.py +++ b/glance/tests/unit/common/test_wsgi.py @@ -27,6 +27,7 @@ from oslo_concurrency import processutils from oslo_serialization import jsonutils import routes import six +from six.moves import http_client as http import webob from glance.api.v1 import router as router_v1 @@ -188,7 +189,7 @@ class RequestTest(test_utils.BaseTestCase): req = webob.Request.blank(uri) req.method = method res = req.get_response(api) - self.assertEqual(405, res.status_int) + self.assertEqual(http.METHOD_NOT_ALLOWED, res.status_int) """Makes sure v2 unallowed methods return 405""" unallowed_methods = [ @@ -217,13 +218,13 @@ class RequestTest(test_utils.BaseTestCase): req = webob.Request.blank(uri) req.method = method res = req.get_response(api) - self.assertEqual(405, res.status_int) + self.assertEqual(http.METHOD_NOT_ALLOWED, res.status_int) # Makes sure not implemented methods return 405 req = webob.Request.blank('/schemas/image') req.method = 'NonexistentMethod' res = req.get_response(api) - self.assertEqual(405, res.status_int) + self.assertEqual(http.METHOD_NOT_ALLOWED, res.status_int) class ResourceTest(test_utils.BaseTestCase): @@ -317,7 +318,7 @@ class ResourceTest(test_utils.BaseTestCase): response = resource.__call__(request) self.assertIsInstance(response, webob.exc.HTTPForbidden) - self.assertEqual(403, response.status_code) + self.assertEqual(http.FORBIDDEN, response.status_code) def test_call_raises_exception(self): class FakeController(object): @@ -336,7 +337,7 @@ class ResourceTest(test_utils.BaseTestCase): response = resource.__call__(request) self.assertIsInstance(response, webob.exc.HTTPInternalServerError) - self.assertEqual(500, response.status_code) + self.assertEqual(http.INTERNAL_SERVER_ERROR, response.status_code) @mock.patch.object(wsgi, 'translate_exception') def test_resource_call_error_handle_localized(self, @@ -433,7 +434,7 @@ class JSONResponseSerializerTest(test_utils.BaseTestCase): fixture = {"key": "value"} response = webob.Response() wsgi.JSONResponseSerializer().default(response, fixture) - self.assertEqual(200, response.status_int) + self.assertEqual(http.OK, response.status_int) content_types = [h for h in response.headerlist if h[0] == 'Content-Type'] self.assertEqual(1, len(content_types)) diff --git a/glance/tests/unit/test_auth.py b/glance/tests/unit/test_auth.py index f67fb88cc1..56a62d4717 100644 --- a/glance/tests/unit/test_auth.py +++ b/glance/tests/unit/test_auth.py @@ -16,6 +16,7 @@ from oslo_serialization import jsonutils from oslotest import moxstubout +from six.moves import http_client as http import webob from glance.api import authorization @@ -196,7 +197,7 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase): """ def fake_do_request(*args, **kwargs): resp = webob.Response() - resp.status = 400 + resp.status = http.BAD_REQUEST return FakeResponse(resp), "" self.stubs.Set(auth.KeystoneStrategy, '_do_request', fake_do_request) @@ -218,7 +219,7 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase): """ def fake_do_request(*args, **kwargs): resp = webob.Response() - resp.status = 400 + resp.status = http.BAD_REQUEST return FakeResponse(resp), "" self.stubs.Set(auth.KeystoneStrategy, '_do_request', fake_do_request) @@ -246,9 +247,9 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase): if (headers.get('X-Auth-User') != 'user1' or headers.get('X-Auth-Key') != 'pass'): - resp.status = 401 + resp.status = http.UNAUTHORIZED else: - resp.status = 200 + resp.status = http.OK resp.headers.update({"x-image-management-url": "example.com"}) return FakeResponse(resp), "" @@ -334,9 +335,9 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase): if (username != 'user1' or password != 'pass' or tenant != 'tenant-ok'): - resp.status = 401 + resp.status = http.UNAUTHORIZED else: - resp.status = 200 + resp.status = http.OK body = mock_token.token return FakeResponse(resp), jsonutils.dumps(body) diff --git a/glance/tests/unit/test_cache_middleware.py b/glance/tests/unit/test_cache_middleware.py index 1062d2d508..04b8ac7c58 100644 --- a/glance/tests/unit/test_cache_middleware.py +++ b/glance/tests/unit/test_cache_middleware.py @@ -15,6 +15,7 @@ from oslo_policy import policy # NOTE(jokke): simplified transition to py3, behaves like py2 xrange +from six.moves import http_client as http from six.moves import range import testtools import webob @@ -614,7 +615,7 @@ class TestCacheMiddlewareProcessResponse(base.IsolatedUnitTest): resp = webob.Response(headers=headers) cache_filter = ProcessRequestTestCacheFilter() actual = cache_filter.get_status_code(resp) - self.assertEqual(200, actual) + self.assertEqual(http.OK, actual) def test_process_response(self): def fake_fetch_request_info(*args, **kwargs): diff --git a/glance/tests/unit/test_glance_replicator.py b/glance/tests/unit/test_glance_replicator.py index b3a4ae25eb..8c10fdfd57 100644 --- a/glance/tests/unit/test_glance_replicator.py +++ b/glance/tests/unit/test_glance_replicator.py @@ -22,6 +22,7 @@ import mock from oslo_serialization import jsonutils import six from six import moves +from six.moves import http_client as http import webob from glance.cmd import replicator as glance_replicator @@ -126,11 +127,12 @@ class ImageServiceTestCase(test_utils.BaseTestCase): def test_rest_errors(self): c = glance_replicator.ImageService(FakeHTTPConnection(), 'noauth') - for code, exc in [(400, webob.exc.HTTPBadRequest), - (401, webob.exc.HTTPUnauthorized), - (403, webob.exc.HTTPForbidden), - (409, webob.exc.HTTPConflict), - (500, webob.exc.HTTPInternalServerError)]: + for code, exc in [(http.BAD_REQUEST, webob.exc.HTTPBadRequest), + (http.UNAUTHORIZED, webob.exc.HTTPUnauthorized), + (http.FORBIDDEN, webob.exc.HTTPForbidden), + (http.CONFLICT, webob.exc.HTTPConflict), + (http.INTERNAL_SERVER_ERROR, + webob.exc.HTTPInternalServerError)]: c.conn.prime_request('GET', ('v1/images/' '5dcddce0-cba5-4f18-9cf4-9853c7b207a6'), '', @@ -145,12 +147,12 @@ class ImageServiceTestCase(test_utils.BaseTestCase): resp = {'images': [IMG_RESPONSE_ACTIVE, IMG_RESPONSE_QUEUED]} c.conn.prime_request('GET', 'v1/images/detail?is_public=None', '', {'x-auth-token': 'noauth'}, - 200, jsonutils.dumps(resp), {}) + http.OK, jsonutils.dumps(resp), {}) c.conn.prime_request('GET', ('v1/images/detail?marker=%s&is_public=None' % IMG_RESPONSE_QUEUED['id']), '', {'x-auth-token': 'noauth'}, - 200, jsonutils.dumps({'images': []}), {}) + http.OK, jsonutils.dumps({'images': []}), {}) imgs = list(c.get_images()) self.assertEqual(2, len(imgs)) @@ -163,7 +165,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase): c.conn.prime_request('GET', 'v1/images/%s' % IMG_RESPONSE_ACTIVE['id'], '', {'x-auth-token': 'noauth'}, - 200, image_contents, IMG_RESPONSE_ACTIVE) + http.OK, image_contents, IMG_RESPONSE_ACTIVE) body = c.get_image(IMG_RESPONSE_ACTIVE['id']) self.assertEqual(image_contents, body.read()) @@ -187,7 +189,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase): c.conn.prime_request('HEAD', 'v1/images/%s' % IMG_RESPONSE_ACTIVE['id'], '', {'x-auth-token': 'noauth'}, - 200, '', IMG_RESPONSE_ACTIVE) + http.OK, '', IMG_RESPONSE_ACTIVE) header = c.get_image_meta(IMG_RESPONSE_ACTIVE['id']) self.assertIn('id', header) @@ -222,7 +224,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase): c.conn.prime_request('POST', 'v1/images', image_body, image_meta_with_proto, - 200, '', IMG_RESPONSE_ACTIVE) + http.OK, '', IMG_RESPONSE_ACTIVE) headers, body = c.add_image(IMG_RESPONSE_ACTIVE, image_body) self.assertEqual(IMG_RESPONSE_ACTIVE, headers) @@ -237,7 +239,7 @@ class ImageServiceTestCase(test_utils.BaseTestCase): image_meta_headers['x-auth-token'] = 'noauth' image_meta_headers['Content-Type'] = 'application/octet-stream' c.conn.prime_request('PUT', 'v1/images/%s' % image_meta['id'], - '', image_meta_headers, 200, '', '') + '', image_meta_headers, http.OK, '', '') headers, body = c.add_image_meta(image_meta) @@ -292,10 +294,10 @@ class FakeImageService(object): return {} def add_image_meta(self, meta): - return {'status': 200}, None + return {'status': http.OK}, None def add_image(self, meta, data): - return {'status': 200}, None + return {'status': http.OK}, None def get_image_service(): diff --git a/glance/tests/unit/test_versions.py b/glance/tests/unit/test_versions.py index e7e13a94ff..e7037d6f99 100644 --- a/glance/tests/unit/test_versions.py +++ b/glance/tests/unit/test_versions.py @@ -14,6 +14,7 @@ # under the License. from oslo_serialization import jsonutils +from six.moves import http_client as http import webob from glance.api.middleware import version_negotiation @@ -31,7 +32,7 @@ class VersionsTest(base.IsolatedUnitTest): req.accept = 'application/json' self.config(bind_host='127.0.0.1', bind_port=9292) res = versions.Controller().index(req) - self.assertEqual(300, res.status_int) + self.assertEqual(http.MULTIPLE_CHOICES, res.status_int) self.assertEqual('application/json', res.content_type) results = jsonutils.loads(res.body)['versions'] expected = [ @@ -86,7 +87,7 @@ class VersionsTest(base.IsolatedUnitTest): self.config(bind_host='127.0.0.1', bind_port=9292, public_endpoint='https://example.com:9292') res = versions.Controller().index(req) - self.assertEqual(300, res.status_int) + self.assertEqual(http.MULTIPLE_CHOICES, res.status_int) self.assertEqual('application/json', res.content_type) results = jsonutils.loads(res.body)['versions'] expected = [ @@ -140,7 +141,7 @@ class VersionsTest(base.IsolatedUnitTest): environ = webob.request.environ_from_url('http://localhost:9292') req = WsgiRequest(environ) res = versions.Controller().index(req) - self.assertEqual(300, res.status_int) + self.assertEqual(http.MULTIPLE_CHOICES, res.status_int) self.assertEqual('application/json', res.content_type) results = jsonutils.loads(res.body)['versions'] expected = [ @@ -195,7 +196,7 @@ class VersionsTest(base.IsolatedUnitTest): environ['HTTP_X_FORWARDED_PROTO'] = "https" req = WsgiRequest(environ) res = versions.Controller().index(req) - self.assertEqual(300, res.status_int) + self.assertEqual(http.MULTIPLE_CHOICES, res.status_int) self.assertEqual('application/json', res.content_type) results = jsonutils.loads(res.body)['versions'] expected = [ diff --git a/glance/tests/unit/v1/test_api.py b/glance/tests/unit/v1/test_api.py index 90aa8c36e8..a51ae8675a 100644 --- a/glance/tests/unit/v1/test_api.py +++ b/glance/tests/unit/v1/test_api.py @@ -28,6 +28,7 @@ from oslo_config import cfg from oslo_serialization import jsonutils import routes import six +from six.moves import http_client import webob import glance.api @@ -150,7 +151,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as mocked_size: mocked_size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual(format_value, res_body['disk_format']) self.assertEqual(format_value, res_body['container_format']) @@ -176,7 +177,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_bad_time_create_string(self): fixture_headers = {'x-image-meta-store': 'file', @@ -190,7 +191,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_bad_time_create_low_year(self): # 'strftime' only allows values after 1900 in glance v1 @@ -205,7 +206,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_bad_time_create_string_in_date(self): fixture_headers = {'x-image-meta-store': 'file', @@ -219,7 +220,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_bad_min_disk_size_create(self): fixture_headers = {'x-image-meta-store': 'file', @@ -233,7 +234,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid value', res.body) def test_updating_imageid_after_creation(self): @@ -242,14 +243,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.headers['x-image-meta-id'] = '000000-000-0000-0000-000' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) # Test using id of another image req = webob.Request.blank("/images/%s" % UUID1) req.method = 'PUT' req.headers['x-image-meta-id'] = UUID2 res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_bad_min_disk_size_update(self): fixture_headers = {'x-image-meta-disk-format': 'vhd', @@ -261,7 +262,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -270,7 +271,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.headers['x-image-meta-min-disk'] = '-42' res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid value', res.body) def test_invalid_min_disk_size_update(self): @@ -283,7 +284,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -292,7 +293,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.headers['x-image-meta-min-disk'] = str(2 ** 31 + 1) res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_bad_min_ram_size_create(self): fixture_headers = {'x-image-meta-store': 'file', @@ -306,7 +307,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid value', res.body) def test_bad_min_ram_size_update(self): @@ -319,7 +320,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -328,7 +329,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.headers['x-image-meta-min-ram'] = '-42' res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid value', res.body) def test_invalid_min_ram_size_update(self): @@ -341,7 +342,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -350,7 +351,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.headers['x-image-meta-min-ram'] = str(2 ** 31 + 1) res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_bad_disk_format(self): fixture_headers = { @@ -367,7 +368,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid disk format', res.body) def test_configured_disk_format_good(self): @@ -388,7 +389,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as mocked_size: mocked_size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) def test_configured_disk_format_bad(self): self.config(disk_formats=['foo'], group="image_format") @@ -406,7 +407,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid disk format', res.body) def test_configured_container_format_good(self): @@ -428,7 +429,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as mocked_size: mocked_size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) def test_configured_container_format_bad(self): self.config(container_formats=['foo'], group="image_format") @@ -446,7 +447,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid container format', res.body) def test_container_and_disk_amazon_format_differs(self): @@ -467,7 +468,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): b"When setting a disk or container format to one of " b"'aki', 'ari', or 'ami', " b"the container and disk formats must match.") - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(expected, res.body) def test_create_with_location_no_container_format(self): @@ -487,7 +488,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as mocked_size: mocked_size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Container format is not specified', res.body) def test_create_with_location_no_disk_format(self): @@ -507,7 +508,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as mocked_size: mocked_size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Disk format is not specified', res.body) def test_create_with_empty_location(self): @@ -521,7 +522,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_create_with_empty_copy_from(self): fixture_headers = { @@ -534,7 +535,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_create_delayed_image_with_no_disk_and_container_formats(self): fixture_headers = { @@ -551,7 +552,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as mocked_size: mocked_size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) def test_create_with_bad_store_name(self): fixture_headers = { @@ -567,7 +568,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Required store bad is invalid', res.body) @mock.patch.object(glance.api.v1.images.Controller, '_external_source') @@ -592,7 +593,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): mock_get_store_from_location.return_value = scheme res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertEqual(1, mock_external_source.call_count) self.assertEqual(1, mock_get_store_from_location.call_count) self.assertIn('Store for scheme %s not found' % scheme, @@ -613,7 +614,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'External sources are not supported', res.body) def test_create_with_location_bad_store_uri(self): @@ -631,7 +632,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid location', res.body) def test_create_image_with_too_many_properties(self): @@ -644,7 +645,8 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(413, output.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + output.status_int) def test_bad_container_format(self): fixture_headers = { @@ -661,7 +663,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid container format', res.body) def test_bad_image_size(self): @@ -679,7 +681,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): method='POST', headers=fixture_headers) res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(expected_substr, res.body) expected = b"Cannot convert image size 'invalid' to an integer." @@ -702,7 +704,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_image_no_location_no_image_as_body(self): """Tests creates a queued image for no body and no loc header""" @@ -719,7 +721,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -737,7 +739,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as mocked_size: mocked_size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_body = jsonutils.loads(res.body)['image'] # Once the location is set, the image should be activated @@ -758,7 +760,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_image_size_header_too_big(self): """Tests raises BadRequest for supplied image size that is too big""" @@ -771,7 +773,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_image_size_chunked_data_too_big(self): self.config(image_size_cap=512) @@ -791,7 +793,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(413, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) def test_add_image_size_data_too_big(self): self.config(image_size_cap=512) @@ -810,7 +812,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_image_size_header_exceed_quota(self): quota = 500 @@ -828,10 +830,10 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v req.body = b'X' * (quota + 1) res = req.get_response(self.api) - self.assertEqual(413, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) def test_add_image_size_data_exceed_quota(self): - quota = 500 + quota = http_client.INTERNAL_SERVER_ERROR self.config(user_storage_quota=str(quota)) fixture_headers = { 'x-image-meta-name': 'fake image #3', @@ -848,7 +850,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(413, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) def test_add_image_size_data_exceed_quota_readd(self): quota = 500 @@ -867,7 +869,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(413, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) used_size = sum([f['size'] for f in self.FIXTURES]) @@ -878,7 +880,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) def _add_check_no_url_info(self): @@ -901,7 +903,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % image_id) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertNotIn('x-image-meta-locations', res.headers) self.assertNotIn('x-image-meta-direct_url', res.headers) @@ -933,7 +935,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('active', res_body['status']) @@ -942,7 +944,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # GET empty image req = webob.Request.blank("/images/%s" % image_id) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(0, len(res.body)) def _do_test_add_image_attribute_mismatch(self, attributes): @@ -959,7 +961,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"XXXX" res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_image_checksum_mismatch(self): attributes = { @@ -993,7 +995,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_image_basic_file_store(self): """Tests to add a basic image in the file store""" @@ -1010,7 +1012,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) # Test that the Location: header is set to the URI to # edit the newly-created image, as required by APP. @@ -1031,7 +1033,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): url = self._http_loc_url('/images/123') req.headers['x-image-meta-location'] = url res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_image_unauthorized(self): rules = {"add_image": '!'} @@ -1049,7 +1051,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_add_publicize_image_unauthorized(self): rules = {"add_image": '@', "modify_image": '@', @@ -1069,7 +1071,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_add_publicize_image_authorized(self): rules = {"add_image": '@', "modify_image": '@', @@ -1089,7 +1091,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) def test_add_copy_from_image_unauthorized(self): rules = {"add_image": '@', "copy_from": '!'} @@ -1109,7 +1111,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_add_copy_from_upload_image_unauthorized(self): rules = {"add_image": '@', "copy_from": '@', "upload_image": '!'} @@ -1128,7 +1130,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_add_copy_from_image_authorized_upload_image_authorized(self): rules = {"add_image": '@', "copy_from": '@', "upload_image": '@'} @@ -1151,7 +1153,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as mock_size: mock_size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) def test_upload_image_http_nonexistent_location_url(self): # Ensure HTTP 404 response returned when try to upload @@ -1172,7 +1174,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_add_copy_from_with_nonempty_body(self): """Tests creates an image from copy-from and nonempty body""" @@ -1189,7 +1191,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_location_with_nonempty_body(self): """Tests creates an image from location and nonempty body""" @@ -1206,7 +1208,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_location_with_conflict_image_size(self): """Tests creates an image from location and conflict image size""" @@ -1231,7 +1233,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(409, res.status_int) + self.assertEqual(http_client.CONFLICT, res.status_int) def test_add_location_with_invalid_location_on_conflict_image_size(self): """Tests creates an image from location and conflict image size""" @@ -1248,7 +1250,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_location_with_invalid_location_on_restricted_sources(self): """Tests creates an image from location and restricted sources""" @@ -1264,7 +1266,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) fixture_headers = {'x-image-meta-store': 'file', 'x-image-meta-disk-format': 'vhd', @@ -1278,7 +1280,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_create_image_with_nonexistent_location_url(self): # Ensure HTTP 404 response returned when try to create @@ -1297,7 +1299,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_add_copy_from_with_location(self): """Tests creates an image from copy-from and location""" @@ -1313,7 +1315,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_copy_from_with_restricted_sources(self): """Tests creates an image from copy-from with restricted sources""" @@ -1333,7 +1335,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v req.headers['x-glance-api-copy-from'] = schema res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_add_copy_from_upload_image_unauthorized_with_body(self): rules = {"upload_image": '!', "modify_image": '@', @@ -1356,7 +1358,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_update_data_upload_bad_store_uri(self): fixture_headers = {'x-image-meta-name': 'fake image #3'} @@ -1366,7 +1368,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -1378,7 +1380,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['x-image-container-format'] = 'ovf' req.headers['x-image-meta-location'] = 'http://' res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn(b'Invalid location', res.body) def test_update_data_upload_image_unauthorized(self): @@ -1395,7 +1397,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -1408,7 +1410,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['x-image-container-format'] = 'ovf' req.body_file = six.StringIO('X' * (CONF.image_size_cap)) res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_update_copy_from_upload_image_unauthorized(self): rules = {"upload_image": '!', "modify_image": '@', @@ -1424,7 +1426,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -1434,7 +1436,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.headers['x-glance-api-copy-from'] = self._http_loc_url('/i.ovf') res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_update_copy_from_unauthorized(self): rules = {"upload_image": '@', "modify_image": '@', @@ -1450,7 +1452,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -1460,7 +1462,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.headers['x-glance-api-copy-from'] = self._http_loc_url('/i.ovf') res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def _do_test_post_image_content_missing_format(self, missing): """Tests creation of an image with missing format""" @@ -1481,7 +1483,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_post_image_content_missing_disk_format(self): """Tests creation of an image with missing disk format""" @@ -1507,7 +1509,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -1520,7 +1522,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_put_image_content_missing_disk_format(self): """Tests delayed activation of image with missing disk format""" @@ -1535,14 +1537,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID3) req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_update_deleted_image(self): """Tests that exception raised trying to update a deleted image""" req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) fixture = {'name': 'test_del_img'} req = webob.Request.blank('/images/%s' % UUID2) @@ -1551,7 +1553,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(dict(image=fixture)) res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) self.assertIn(b'Forbidden to update deleted image', res.body) def test_delete_deleted_image(self): @@ -1559,19 +1561,19 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) # Verify the status is 'deleted' req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual("deleted", res.headers['x-image-meta-status']) req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) msg = "Image %s not found." % UUID2 self.assertIn(msg, res.body.decode()) @@ -1579,7 +1581,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual("deleted", res.headers['x-image-meta-status']) def test_image_status_when_delete_fails(self): @@ -1596,14 +1598,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) self.assertIn(b'Forbidden to delete image', res.body) # check image metadata is still there with active state req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual("active", res.headers['x-image-meta-status']) def test_delete_pending_delete_image(self): @@ -1616,27 +1618,27 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) # Verify the status is 'pending_delete' req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual("pending_delete", res.headers['x-image-meta-status']) # Second deletion req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) self.assertIn(b'Forbidden to delete a pending_delete image', res.body) # Verify the status is still 'pending_delete' req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual("pending_delete", res.headers['x-image-meta-status']) def test_upload_to_image_status_saving(self): @@ -1658,7 +1660,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] image_id = res_body['id'] @@ -1756,7 +1758,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Expect a 409 Conflict. res = req.get_response(self.api) - self.assertEqual(409, res.status_int) + self.assertEqual(http_client.CONFLICT, res.status_int) # Check expected call sequence self.assertEqual(['get_image_meta', 'get_image_meta', @@ -1793,7 +1795,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertIn('id', res_body) @@ -1819,14 +1821,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['x-image-meta-property-key2'] = 'value2' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) # Verify the status is 'queued' req = webob.Request.blank("/images/%s" % image_id) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertIn('x-image-meta-property-key1', res.headers, "Did not find required property in headers. " "Got headers: %r" % res.headers) @@ -1848,7 +1850,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertIn('id', res_body) @@ -1868,7 +1870,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(410, res.status_int) + self.assertEqual(http_client.GONE, res.status_int) self._verify_image_status(image_id, 'killed') def _get_image_status(self, image_id): @@ -1883,7 +1885,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): else: res = self.image_status.pop(0) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(status, res.headers['x-image-meta-status']) self.assertEqual(str(check_deleted), res.headers['x-image-meta-deleted']) @@ -1901,7 +1903,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertIn('id', res_body) @@ -1925,7 +1927,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.body = b"chunk00000remainder" res = req.get_response(self.api) # We expect 500 since an exception occurred during upload. - self.assertEqual(500, res.status_int) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, res.status_int) @mock.patch('glance_store.store_add_to_backend') def test_upload_safe_kill(self, mock_store_add_to_backend): @@ -1965,7 +1967,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % self.image_id) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) # expect 'deleted' self.image_status.append(self._get_image_status(self.image_id)) @@ -2003,7 +2005,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertIn('id', res_body) @@ -2034,7 +2036,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): method='DELETE', is_admin=is_admin) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.stubs.Set(registry, 'update_image_metadata', orig_update_image_metadata) @@ -2049,7 +2051,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = data res = req.get_response(self.api) - self.assertEqual(412, res.status_int) + self.assertEqual(http_client.PRECONDITION_FAILED, res.status_int) self.assertFalse(res.location) self.assertTrue(called['initiate_deletion']) @@ -2058,7 +2060,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): method='HEAD', is_admin=True) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('True', res.headers['x-image-meta-deleted']) self.assertEqual('deleted', res.headers['x-image-meta-status']) @@ -2088,7 +2090,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = b"chunk00000remainder" res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertIn('id', res_body) @@ -2112,14 +2114,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.headers['x-image-meta-property-key2'] = 'value2' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) # Verify the original property no longer in headers req = webob.Request.blank("/images/%s" % image_id) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertIn('x-image-meta-property-key2', res.headers, "Did not find required property in headers. " "Got headers: %r" % res.headers) @@ -2136,14 +2138,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['x-image-meta-property-key3'] = 'value3' req.headers['x-glance-registry-purge-props'] = 'false' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) # Verify the second and third property in headers req = webob.Request.blank("/images/%s" % image_id) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertIn('x-image-meta-property-key2', res.headers, "Did not find required property in headers. " "Got headers: %r" % res.headers) @@ -2167,14 +2169,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] req = webob.Request.blank("/images/%s" % res_body['id']) req.method = 'PUT' req.headers['x-image-meta-is-public'] = 'true' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_update_image_size_header_too_big(self): """Tests raises BadRequest for supplied image size that is too big""" @@ -2186,7 +2188,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_update_image_size_data_too_big(self): self.config(image_size_cap=512) @@ -2200,7 +2202,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_update_image_size_chunked_data_too_big(self): self.config(image_size_cap=512) @@ -2226,7 +2228,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(413, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) def test_update_non_existing_image(self): self.config(image_size_cap=100) @@ -2239,7 +2241,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['x-image-meta-disk_format'] = 'ami' req.headers['x-image-meta-is_public'] = 'False' res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_update_public_image(self): fixture_headers = {'x-image-meta-store': 'file', @@ -2253,14 +2255,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] req = webob.Request.blank("/images/%s" % res_body['id']) req.method = 'PUT' req.headers['x-image-meta-name'] = 'updated public image' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) @mock.patch.object(registry, 'update_image_metadata') def test_update_without_public_attribute(self, mock_update_image_metadata): @@ -2293,7 +2295,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_get_index_sort_name_asc(self): """ @@ -2327,7 +2329,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images?sort_key=name&sort_dir=asc') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -2388,7 +2390,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Check a standard list, 4 images in db (2 deleted) req = webob.Request.blank('/images/detail') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] self.assertEqual(2, len(images)) @@ -2398,7 +2400,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Expect 3 images (1 deleted) req = webob.Request.blank('/images/detail?changes-since=%s' % iso1) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] self.assertEqual(3, len(images)) @@ -2409,7 +2411,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Expect 1 images (0 deleted) req = webob.Request.blank('/images/detail?changes-since=%s' % iso2) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] self.assertEqual(1, len(images)) @@ -2419,7 +2421,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/detail?changes-since=%s' % hour_before) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] self.assertEqual(1, len(images)) @@ -2429,7 +2431,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/detail?changes-since=%s' % hour_after) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] self.assertEqual(0, len(images)) @@ -2437,7 +2439,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Expect 0 images (0 deleted) req = webob.Request.blank('/images/detail?changes-since=%s' % iso4) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] self.assertEqual(0, len(images)) @@ -2447,7 +2449,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/detail?changes-since=%s' % param) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] self.assertEqual(3, len(images)) @@ -2458,29 +2460,29 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Bad request (empty changes-since param) req = webob.Request.blank('/images/detail?changes-since=') res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_get_images_bad_urls(self): """Check that routes collections are not on (LP bug 1185828)""" req = webob.Request.blank('/images/detail.xxx') res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) req = webob.Request.blank('/images.xxx') res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) req = webob.Request.blank('/images/new') res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) req = webob.Request.blank("/images/%s/members" % UUID1) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank("/images/%s/members.xxx" % UUID1) res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_get_index_filter_on_user_defined_properties(self): """Check that image filtering works on user-defined properties""" @@ -2514,7 +2516,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Verify both image1 and image2 are returned req = webob.Request.blank('/images?property-distro=ubuntu') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(2, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -2525,7 +2527,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Verify neither images are returned req = webob.Request.blank('/images?property-distro=fedora') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) @@ -2534,7 +2536,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Verify only image1 is returned. req = webob.Request.blank('/images?property-arch=i386') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image1_id, images[0]['id']) @@ -2544,7 +2546,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Verify only image1 is returned. req = webob.Request.blank('/images?property-arch=x86_64') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -2554,7 +2556,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Verify only image2 is returned. req = webob.Request.blank('/images?property-foo=bar') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -2564,7 +2566,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Verify neither images are returned. req = webob.Request.blank('/images?property-foo=baz') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) @@ -2574,7 +2576,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images?property-arch=x86_64&' 'property-distro=ubuntu') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -2585,7 +2587,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images?property-arch=i386&' 'property-distro=ubuntu') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image1_id, images[0]['id']) @@ -2596,7 +2598,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images?property-arch=random&' 'property-distro=ubuntu') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) @@ -2606,7 +2608,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images?property-arch=random&' 'property-distro=random') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) @@ -2616,7 +2618,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images?property-boo=far&' 'property-poo=far') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) @@ -2626,7 +2628,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images?property-foo=bar&' 'property-poo=far') res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) @@ -2635,14 +2637,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): self.set_policy_rules(rules) req = webob.Request.blank('/images/detail') res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_get_images_unauthorized(self): rules = {"get_images": '!'} self.set_policy_rules(rules) req = webob.Request.blank('/images') res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_store_location_not_revealed(self): """ @@ -2653,7 +2655,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for url in ('/images', '/images/detail'): req = webob.Request.blank(url) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -2664,14 +2666,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): # Check GET req = webob.Request.blank("/images/%s" % UUID2) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertNotIn('X-Image-Meta-Location', res.headers) # Check HEAD req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertNotIn('X-Image-Meta-Location', res.headers) # Check PUT @@ -2679,7 +2681,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.body = res.body req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) res_body = jsonutils.loads(res.body) self.assertNotIn('location', res_body['image']) @@ -2698,7 +2700,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): with mock.patch.object(http, 'get_size') as size: size.return_value = 0 res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body) self.assertNotIn('location', res_body['image']) @@ -2719,7 +2721,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = image_contents res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual(image_checksum, res_body['checksum'], @@ -2743,7 +2745,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = image_contents res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) image = jsonutils.loads(res.body)['image'] @@ -2753,7 +2755,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % image['id']) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) for key in expected_headers.keys(): self.assertIn(key, res.headers, @@ -2781,13 +2783,13 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['Content-Type'] = 'application/octet-stream' req.body = image_contents res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) # Test that only one image was returned (that already exists) req = webob.Request.blank("/images") req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) @@ -2798,7 +2800,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertFalse(res.location) for key, value in six.iteritems(expected_headers): @@ -2810,12 +2812,12 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_show_image_basic(self): req = webob.Request.blank("/images/%s" % UUID2) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertFalse(res.location) self.assertEqual('application/octet-stream', res.content_type) self.assertEqual(b'chunk00000remainder', res.body) @@ -2823,21 +2825,21 @@ class TestGlanceAPI(base.IsolatedUnitTest): def test_show_non_exists_image(self): req = webob.Request.blank("/images/%s" % _gen_uuid()) res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_show_image_unauthorized(self): rules = {"get_image": '!'} self.set_policy_rules(rules) req = webob.Request.blank("/images/%s" % UUID2) res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_show_image_unauthorized_download(self): rules = {"download_image": '!'} self.set_policy_rules(rules) req = webob.Request.blank("/images/%s" % UUID2) res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_show_image_restricted_download_for_core_property(self): rules = { @@ -2850,7 +2852,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['X-Auth-Token'] = 'user:tenant:_member_' req.headers['min_ram'] = '1024M' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_show_image_restricted_download_for_custom_property(self): rules = { @@ -2863,7 +2865,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.headers['X-Auth-Token'] = 'user:tenant:_member_' req.headers['x_test_key'] = 'test_1234' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_download_service_unavailable(self): """Test image download returns HTTPServiceUnavailable.""" @@ -2886,7 +2888,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): m_get.side_effect = store.StoreGetNotSupported() req = webob.Request.blank("/images/%s" % UUID2) res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) @mock.patch('glance_store._drivers.filesystem.Store.get') def test_show_image_store_random_get_not_support(self, m_get): @@ -2894,25 +2896,25 @@ class TestGlanceAPI(base.IsolatedUnitTest): offset=0) req = webob.Request.blank("/images/%s" % UUID2) res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_delete_image(self): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertFalse(res.location) self.assertEqual(b'', res.body) req = webob.Request.blank("/images/%s" % UUID2) req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(404, res.status_int, res.body) + self.assertEqual(http_client.NOT_FOUND, res.status_int, res.body) req = webob.Request.blank("/images/%s" % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('True', res.headers['x-image-meta-deleted']) self.assertEqual('deleted', res.headers['x-image-meta-status']) @@ -2920,7 +2922,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % _gen_uuid()) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_delete_not_allowed(self): # Verify we can get the image data @@ -2928,18 +2930,18 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'GET' req.headers['X-Auth-Token'] = 'user:tenant:' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(19, len(res.body)) # Verify we cannot delete the image req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) # Verify the image data is still there req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(19, len(res.body)) def test_delete_queued_image(self): @@ -2962,7 +2964,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -2971,12 +2973,12 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % res_body['id']) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s' % res_body['id']) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('True', res.headers['x-image-meta-deleted']) self.assertEqual('deleted', res.headers['x-image-meta-status']) @@ -2997,7 +2999,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -3006,12 +3008,12 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % res_body['id']) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s' % res_body['id']) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('True', res.headers['x-image-meta-deleted']) self.assertEqual('deleted', res.headers['x-image-meta-status']) @@ -3027,7 +3029,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): for k, v in six.iteritems(fixture_headers): req.headers[k] = v res = req.get_response(self.api) - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) res_body = jsonutils.loads(res.body)['image'] self.assertEqual('queued', res_body['status']) @@ -3036,7 +3038,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % res_body['id']) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_delete_image_unauthorized(self): rules = {"delete_image": '!'} @@ -3044,18 +3046,18 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) def test_head_details(self): req = webob.Request.blank('/images/detail') req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(405, res.status_int) + self.assertEqual(http_client.METHOD_NOT_ALLOWED, res.status_int) self.assertEqual('GET', res.headers.get('Allow')) self.assertEqual(('GET',), res.allow) req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) def test_get_details_invalid_marker(self): """ @@ -3064,7 +3066,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): """ req = webob.Request.blank('/images/detail?marker=%s' % _gen_uuid()) res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_get_image_members(self): """ @@ -3074,7 +3076,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) memb_list = jsonutils.loads(res.body) num_members = len(memb_list['members']) @@ -3088,7 +3090,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) memb_list = jsonutils.loads(res.body) num_members = len(memb_list['members']) @@ -3113,7 +3115,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_add_member_positive(self): """ @@ -3126,7 +3128,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) def test_get_member_images(self): """ @@ -3136,7 +3138,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) memb_list = jsonutils.loads(res.body) num_members = len(memb_list['shared_images']) @@ -3157,7 +3159,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(dict(image_memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(401, res.status_int) + self.assertEqual(http_client.UNAUTHORIZED, res.status_int) def test_active_image_immutable_props_for_user(self): """ @@ -3175,14 +3177,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/%s' % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) orig_value = res.headers[k] req = webob.Request.blank('/images/%s' % UUID2) req.headers[k] = v req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) prop = k[len('x-image-meta-'):] body = res.body.decode('utf-8') self.assertNotEqual(-1, body.find( @@ -3191,7 +3193,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/%s' % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(orig_value, res.headers[k]) def test_deactivated_image_immutable_props_for_user(self): @@ -3210,14 +3212,14 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/%s' % UUID3) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) orig_value = res.headers[k] req = webob.Request.blank('/images/%s' % UUID3) req.headers[k] = v req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) prop = k[len('x-image-meta-'):] body = res.body.decode('utf-8') self.assertNotEqual(-1, body.find( @@ -3226,7 +3228,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/%s' % UUID3) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(orig_value, res.headers[k]) def test_props_of_active_image_mutable_for_admin(self): @@ -3245,18 +3247,18 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/%s' % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s' % UUID2) req.headers[k] = v req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s' % UUID2) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(v, res.headers[k]) def test_props_of_deactivated_image_mutable_for_admin(self): @@ -3275,18 +3277,18 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/%s' % UUID3) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s' % UUID3) req.headers[k] = v req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s' % UUID3) req.method = 'HEAD' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(v, res.headers[k]) def test_replace_members_non_existing_image(self): @@ -3303,7 +3305,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(dict(image_memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_replace_members_bad_request(self): """ @@ -3320,7 +3322,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(dict(image_memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_replace_members_positive(self): """ @@ -3337,7 +3339,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.content_type = 'application/json' req.body = jsonutils.dump_as_bytes(dict(memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) def test_replace_members_forbidden_by_policy(self): rules = {"modify_member": '!'} @@ -3380,7 +3382,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(401, res.status_int) + self.assertEqual(http_client.UNAUTHORIZED, res.status_int) def test_add_member_non_existing_image(self): """ @@ -3394,7 +3396,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_add_member_with_body(self): """ @@ -3408,7 +3410,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.body = jsonutils.dump_as_bytes(dict(member=fixture)) res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) def test_add_member_overlimit(self): self.config(image_member_quota=0) @@ -3419,7 +3421,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(413, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) def test_add_member_unlimited(self): self.config(image_member_quota=-1) @@ -3430,7 +3432,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) def test_add_member_forbidden_by_policy(self): rules = {"modify_member": '!'} @@ -3461,7 +3463,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s/members' % UUID2) req.method = 'GET' @@ -3480,7 +3482,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s/members/pattieblack' % UUID2) req.method = 'DELETE' @@ -3500,12 +3502,12 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/%s/members/pattieblack' % UUID2) req.method = 'PUT' res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) fixture = [{'member_id': 'pattieblack', 'can_share': 'false'}] req = webob.Request.blank('/images/%s/members' % UUID2) @@ -3527,12 +3529,12 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.body = jsonutils.dump_as_bytes(dict(memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) req = webob.Request.blank('/images/%s/members' % UUID2) req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) memb_list = jsonutils.loads(res.body) self.assertEqual(1, len(memb_list)) @@ -3549,13 +3551,13 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.body = jsonutils.dump_as_bytes(dict(memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) # GET original image member list req = webob.Request.blank('/images/%s/members' % UUID2) req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) original_members = jsonutils.loads(res.body)['members'] self.assertEqual(1, len(original_members)) @@ -3566,13 +3568,13 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.body = jsonutils.dump_as_bytes(dict(memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(413, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) # GET member list req = webob.Request.blank('/images/%s/members' % UUID2) req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) # Assert the member list was not changed memb_list = jsonutils.loads(res.body)['members'] @@ -3589,12 +3591,12 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'PUT' req.body = jsonutils.dump_as_bytes(dict(memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) req = webob.Request.blank('/images/%s/members' % UUID2) req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) memb_list = jsonutils.loads(res.body)['members'] self.assertEqual(fixture, memb_list) @@ -3608,7 +3610,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank("/images/%s" % UUID2) req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) req = webob.Request.blank('/images/%s/members/pattieblack' % UUID2) req.method = 'PUT' @@ -3629,7 +3631,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'DELETE' res = req.get_response(self.api) - self.assertEqual(401, res.status_int) + self.assertEqual(http_client.UNAUTHORIZED, res.status_int) def test_delete_member_on_non_existing_image(self): """ @@ -3642,7 +3644,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'DELETE' res = req.get_response(api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_delete_non_exist_member(self): """ @@ -3654,7 +3656,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req = webob.Request.blank('/images/%s/members/test_user' % UUID2) req.method = 'DELETE' res = req.get_response(api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def test_delete_image_member(self): test_rserver = router.API(self.mapper) @@ -3669,7 +3671,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.content_type = 'application/json' req.body = jsonutils.dump_as_bytes(dict(member=fixture)) res = req.get_response(self.api) - self.assertEqual(204, res.status_int) + self.assertEqual(http_client.NO_CONTENT, res.status_int) # Delete member test_uri = '/images/%s/members/test_add_member_positive' @@ -3678,7 +3680,7 @@ class TestGlanceAPI(base.IsolatedUnitTest): req.method = 'DELETE' req.content_type = 'application/json' res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) self.assertIn(b'Forbidden', res.body) def test_delete_member_allowed_by_policy(self): @@ -4006,7 +4008,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) res_body = jsonutils.loads(output.body)['image'] self.assertEqual('bar', res_body['properties']['spl_create_prop_policy']) @@ -4059,7 +4061,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertEqual(b'', output.body) self.assertNotIn('x-image-meta-property-x_owner_foo', output.headers) @@ -4093,7 +4095,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertEqual(b'', output.body) self.assertNotIn('x-image-meta-property-x_owner_foo', output.headers) @@ -4110,7 +4112,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) res_body = jsonutils.loads(output.body)['images'][0] self.assertEqual('bar', res_body['properties']['x_owner_foo']) @@ -4128,7 +4130,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) res_body = jsonutils.loads(output.body)['images'][0] self.assertEqual('bar', res_body['properties']['x_owner_foo']) @@ -4145,7 +4147,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) res_body = jsonutils.loads(output.body)['images'][0] self.assertNotIn('x-image-meta-property-x_owner_foo', res_body['properties']) @@ -4164,7 +4166,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) res_body = jsonutils.loads(output.body)['images'][0] self.assertNotIn('x-image-meta-property-x_owner_foo', res_body['properties']) @@ -4274,7 +4276,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): output = another_request.get_response(self.api) res_body = jsonutils.loads(output.body)['image'] self.assertEqual('foo', res_body['properties']['spl_read_prop']) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) def test_prop_protection_with_delete_and_permitted_role(self): """ @@ -4325,7 +4327,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertNotIn('x-image-meta-property-x_owner_foo', output.headers) another_request = unit_test_utils.get_fake_request( @@ -4334,7 +4336,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertEqual(b'', output.body) self.assertEqual('bar', output.headers['x-image-meta-property-x_owner_foo']) @@ -4353,7 +4355,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) self.assertIn("Property '%s' is protected" % "spl_update_prop", output.body.decode()) @@ -4363,7 +4365,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertEqual(b'', output.body) self.assertEqual( 'foo', output.headers['x-image-meta-property-spl_update_prop']) @@ -4431,7 +4433,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): another_request.headers[k] = v output = another_request.get_response(self.api) res_body = jsonutils.loads(output.body)['image'] - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertEqual('1', res_body['properties']['spl_read_only_prop']) self.assertEqual('1', res_body['properties']['spl_update_prop']) @@ -4442,7 +4444,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) def test_delete_protected_props_mix_no_read(self): """ @@ -4483,7 +4485,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) def test_create_protected_prop_check_case_insensitive(self): """ @@ -4516,7 +4518,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertEqual(b'', output.body) self.assertEqual( '1', output.headers['x-image-meta-property-x_case_insensitive']) @@ -4586,7 +4588,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertEqual(b'', output.body) self.assertEqual( '1', output.headers['x-image-meta-property-x_all_permitted']) @@ -4637,7 +4639,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) # also check admin can not create another_request = unit_test_utils.get_fake_request( path='/images/%s' % image_id, method='PUT') @@ -4646,7 +4648,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) def test_read_locked_down_protected_prop(self): """ @@ -4662,7 +4664,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertNotIn('x_none_read', output.headers) # also check admin can not read another_request = unit_test_utils.get_fake_request( @@ -4671,7 +4673,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) self.assertNotIn('x_none_read', output.headers) def test_update_locked_down_protected_prop(self): @@ -4687,7 +4689,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) # also check admin can't update property another_request = unit_test_utils.get_fake_request( path='/images/%s' % image_id, method='PUT') @@ -4696,7 +4698,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) def test_delete_locked_down_protected_prop(self): """ @@ -4711,7 +4713,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) # also check admin can't delete another_request = unit_test_utils.get_fake_request( path='/images/%s' % image_id, method='PUT') @@ -4720,7 +4722,7 @@ class TestAPIProtectedProps(base.IsolatedUnitTest): for k, v in six.iteritems(headers): another_request.headers[k] = v output = another_request.get_response(self.api) - self.assertEqual(403, output.status_int) + self.assertEqual(http_client.FORBIDDEN, output.status_int) class TestAPIPropertyQuotas(base.IsolatedUnitTest): @@ -4766,7 +4768,8 @@ class TestAPIPropertyQuotas(base.IsolatedUnitTest): output = another_request.get_response(self.api) - self.assertEqual(413, output.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + output.status_int) self.assertIn("Attempted: 2, Maximum: 1", output.text) def test_update_image_with_too_many_properties_without_purge_props(self): @@ -4798,7 +4801,8 @@ class TestAPIPropertyQuotas(base.IsolatedUnitTest): output = another_request.get_response(self.api) - self.assertEqual(413, output.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + output.status_int) self.assertIn("Attempted: 2, Maximum: 1", output.text) def test_update_properties_without_purge_props_overwrite_value(self): @@ -4831,7 +4835,7 @@ class TestAPIPropertyQuotas(base.IsolatedUnitTest): output = another_request.get_response(self.api) - self.assertEqual(200, output.status_int) + self.assertEqual(http_client.OK, output.status_int) res_body = jsonutils.loads(output.body)['image'] self.assertEqual('1', res_body['properties']['x_all_permitted']) self.assertEqual('3', res_body['properties']['x_all_permitted_create']) diff --git a/glance/tests/unit/v1/test_registry_api.py b/glance/tests/unit/v1/test_registry_api.py index e6a800de3e..6ef1e9b762 100644 --- a/glance/tests/unit/v1/test_registry_api.py +++ b/glance/tests/unit/v1/test_registry_api.py @@ -23,6 +23,7 @@ from oslo_config import cfg from oslo_serialization import jsonutils import routes import six +from six.moves import http_client as http import webob import glance.api.common @@ -87,7 +88,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): 'min_ram': 256, 'min_disk': 5, 'checksum': None} - res = self.get_api_response_ext(200, '/images/%s' % UUID2) + res = self.get_api_response_ext(http.OK, '/images/%s' % UUID2) res_dict = jsonutils.loads(res.body) image = res_dict['image'] for k, v in six.iteritems(fixture): @@ -98,14 +99,14 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): Tests that the /images/ registry API endpoint returns a 404 for an unknown image id """ - self.get_api_response_ext(404, '/images/%s' % _gen_uuid()) + self.get_api_response_ext(http.NOT_FOUND, '/images/%s' % _gen_uuid()) def test_show_invalid(self): """ Tests that the /images/ registry API endpoint returns a 404 for an invalid (therefore unknown) image id """ - self.get_api_response_ext(404, '/images/%s' % _gen_uuid()) + self.get_api_response_ext(http.NOT_FOUND, '/images/%s' % _gen_uuid()) def test_show_deleted_image_as_admin(self): """ @@ -113,9 +114,10 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): returns a 200 for deleted image to admin user. """ # Delete image #2 - self.get_api_response_ext(200, '/images/%s' % UUID2, method='DELETE') + self.get_api_response_ext(http.OK, '/images/%s' % UUID2, + method='DELETE') - self.get_api_response_ext(200, '/images/%s' % UUID2) + self.get_api_response_ext(http.OK, '/images/%s' % UUID2) def test_show_deleted_image_as_nonadmin(self): """ @@ -123,11 +125,13 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): returns a 404 for deleted image to non-admin user. """ # Delete image #2 - self.get_api_response_ext(200, '/images/%s' % UUID2, method='DELETE') + self.get_api_response_ext(http.OK, '/images/%s' % UUID2, + method='DELETE') api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper), is_admin=False) - self.get_api_response_ext(404, '/images/%s' % UUID2, api=api) + self.get_api_response_ext(http.NOT_FOUND, '/images/%s' % UUID2, + api=api) def test_show_private_image_with_no_admin_user(self): UUID4 = _gen_uuid() @@ -136,7 +140,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) test_rserv = rserver.API(self.mapper) api = test_utils.FakeAuthMiddleware(test_rserv, is_admin=False) - self.get_api_response_ext(404, '/images/%s' % UUID4, api=api) + self.get_api_response_ext(http.NOT_FOUND, '/images/%s' % UUID4, + api=api) def test_get_root(self): """ @@ -144,7 +149,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): which is a list of public images """ fixture = {'id': UUID2, 'size': 19, 'checksum': None} - res = self.get_api_response_ext(200, url='/') + res = self.get_api_response_ext(http.OK, url='/') res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -159,7 +164,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): public images """ fixture = {'id': UUID2, 'size': 19, 'checksum': None} - res = self.get_api_response_ext(200) + res = self.get_api_response_ext(http.OK) res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -192,7 +197,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url='/images?marker=%s' % UUID4) + res = self.get_api_response_ext(http.OK, + url='/images?marker=%s' % UUID4) self.assertEqualImages(res, (UUID5, UUID2)) def test_get_index_unknown_marker(self): @@ -200,14 +206,16 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): Tests that the /images registry API returns a 400 when an unknown marker is provided """ - self.get_api_response_ext(400, url='/images?marker=%s' % _gen_uuid()) + self.get_api_response_ext(http.BAD_REQUEST, + url='/images?marker=%s' % _gen_uuid()) def test_get_index_malformed_marker(self): """ Tests that the /images registry API returns a 400 when a malformed marker is provided """ - res = self.get_api_response_ext(400, url='/images?marker=4') + res = self.get_api_response_ext(http.BAD_REQUEST, + url='/images?marker=4') self.assertIn(b'marker', res.body) def test_get_index_forbidden_marker(self): @@ -217,8 +225,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): """ test_rserv = rserver.API(self.mapper) api = test_utils.FakeAuthMiddleware(test_rserv, is_admin=False) - self.get_api_response_ext(400, url='/images?marker=%s' % UUID1, - api=api) + self.get_api_response_ext(http.BAD_REQUEST, + url='/images?marker=%s' % UUID1, api=api) def test_get_index_limit(self): """ @@ -235,7 +243,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url='/images?limit=1') + res = self.get_api_response_ext(http.OK, url='/images?limit=1') res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -249,14 +257,14 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): Tests that the /images registry API returns list of public images that conforms to a limit query param """ - self.get_api_response_ext(400, url='/images?limit=-1') + self.get_api_response_ext(http.BAD_REQUEST, url='/images?limit=-1') def test_get_index_limit_non_int(self): """ Tests that the /images registry API returns list of public images that conforms to a limit query param """ - self.get_api_response_ext(400, url='/images?limit=a') + self.get_api_response_ext(http.BAD_REQUEST, url='/images?limit=a') def test_get_index_limit_marker(self): """ @@ -273,7 +281,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) res = self.get_api_response_ext( - 200, url='/images?marker=%s&limit=1' % UUID3) + http.OK, url='/images?marker=%s&limit=1' % UUID3) self.assertEqualImages(res, (UUID2,)) def test_get_index_filter_on_user_defined_properties(self): @@ -296,8 +304,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): # Test index with filter containing one user-defined property. # Filter is 'property-distro=ubuntu'. # Verify both image1 and image2 are returned - res = self.get_api_response_ext(200, url='/images?' - 'property-distro=ubuntu') + res = self.get_api_response_ext(http.OK, url='/images?' + 'property-distro=ubuntu') images = jsonutils.loads(res.body)['images'] self.assertEqual(2, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -306,16 +314,16 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): # Test index with filter containing one user-defined property but # non-existent value. Filter is 'property-distro=fedora'. # Verify neither images are returned - res = self.get_api_response_ext(200, url='/images?' - 'property-distro=fedora') + res = self.get_api_response_ext(http.OK, url='/images?' + 'property-distro=fedora') images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) # Test index with filter containing one user-defined property but # unique value. Filter is 'property-arch=i386'. # Verify only image1 is returned. - res = self.get_api_response_ext(200, url='/images?' - 'property-arch=i386') + res = self.get_api_response_ext(http.OK, url='/images?' + 'property-arch=i386') images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image1_id, images[0]['id']) @@ -323,8 +331,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): # Test index with filter containing one user-defined property but # unique value. Filter is 'property-arch=x86_64'. # Verify only image1 is returned. - res = self.get_api_response_ext(200, url='/images?' - 'property-arch=x86_64') + res = self.get_api_response_ext(http.OK, url='/images?' + 'property-arch=x86_64') images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -332,7 +340,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): # Test index with filter containing unique user-defined property. # Filter is 'property-foo=bar'. # Verify only image2 is returned. - res = self.get_api_response_ext(200, url='/images?property-foo=bar') + res = self.get_api_response_ext(http.OK, + url='/images?property-foo=bar') images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -340,16 +349,17 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): # Test index with filter containing unique user-defined property but # .value is non-existent. Filter is 'property-foo=baz'. # Verify neither images are returned. - res = self.get_api_response_ext(200, url='/images?property-foo=baz') + res = self.get_api_response_ext(http.OK, + url='/images?property-foo=baz') images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) # Test index with filter containing multiple user-defined properties # Filter is 'property-arch=x86_64&property-distro=ubuntu'. # Verify only image2 is returned. - res = self.get_api_response_ext(200, url='/images?' - 'property-arch=x86_64&' - 'property-distro=ubuntu') + res = self.get_api_response_ext(http.OK, url='/images?' + 'property-arch=x86_64&' + 'property-distro=ubuntu') images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image2_id, images[0]['id']) @@ -357,8 +367,9 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): # Test index with filter containing multiple user-defined properties # Filter is 'property-arch=i386&property-distro=ubuntu'. # Verify only image1 is returned. - res = self.get_api_response_ext(200, url='/images?property-arch=i386&' - 'property-distro=ubuntu') + res = self.get_api_response_ext(http.OK, + url='/images?property-arch=i386&' + 'property-distro=ubuntu') images = jsonutils.loads(res.body)['images'] self.assertEqual(1, len(images)) self.assertEqual(image1_id, images[0]['id']) @@ -366,34 +377,36 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): # Test index with filter containing multiple user-defined properties. # Filter is 'property-arch=random&property-distro=ubuntu'. # Verify neither images are returned. - res = self.get_api_response_ext(200, url='/images?' - 'property-arch=random&' - 'property-distro=ubuntu') + res = self.get_api_response_ext(http.OK, url='/images?' + 'property-arch=random&' + 'property-distro=ubuntu') images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) # Test index with filter containing multiple user-defined properties. # Filter is 'property-arch=random&property-distro=random'. # Verify neither images are returned. - res = self.get_api_response_ext(200, url='/images?' - 'property-arch=random&' - 'property-distro=random') + res = self.get_api_response_ext(http.OK, url='/images?' + 'property-arch=random&' + 'property-distro=random') images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) # Test index with filter containing multiple user-defined properties. # Filter is 'property-boo=far&property-poo=far'. # Verify neither images are returned. - res = self.get_api_response_ext(200, url='/images?property-boo=far&' - 'property-poo=far') + res = self.get_api_response_ext(http.OK, + url='/images?property-boo=far&' + 'property-poo=far') images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) # Test index with filter containing multiple user-defined properties. # Filter is 'property-foo=bar&property-poo=far'. # Verify neither images are returned. - res = self.get_api_response_ext(200, url='/images?property-foo=bar&' - 'property-poo=far') + res = self.get_api_response_ext(http.OK, + url='/images?property-foo=bar&' + 'property-poo=far') images = jsonutils.loads(res.body)['images'] self.assertEqual(0, len(images)) @@ -412,7 +425,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): extra_fixture = self.get_fixture(id=_gen_uuid(), name='new name! #123') db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url='/images?name=new name! #123') + res = self.get_api_response_ext(http.OK, + url='/images?name=new name! #123') res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -445,16 +459,18 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url='/images') + res = self.get_api_response_ext(http.OK, url='/images') self.assertEqualImages(res, (UUID3, UUID4, UUID5, UUID2)) def test_get_index_bad_sort_key(self): """Ensure a 400 is returned when a bad sort_key is provided.""" - self.get_api_response_ext(400, url='/images?sort_key=asdf') + self.get_api_response_ext(http.BAD_REQUEST, + url='/images?sort_key=asdf') def test_get_index_bad_sort_dir(self): """Ensure a 400 is returned when a bad sort_dir is provided.""" - self.get_api_response_ext(400, url='/images?sort_dir=asdf') + self.get_api_response_ext(http.BAD_REQUEST, + url='/images?sort_dir=asdf') def test_get_index_null_name(self): """Check 200 is returned when sort_key is null name @@ -467,7 +483,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) self.get_api_response_ext( - 200, url='/images?sort_key=name&marker=%s' % UUID6) + http.OK, url='/images?sort_key=name&marker=%s' % UUID6) def test_get_index_null_disk_format(self): """Check 200 is returned when sort_key is null disk_format @@ -480,7 +496,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) self.get_api_response_ext( - 200, url='/images?sort_key=disk_format&marker=%s' % UUID6) + http.OK, url='/images?sort_key=disk_format&marker=%s' % UUID6) def test_get_index_null_container_format(self): """Check 200 is returned when sort_key is null container_format @@ -493,7 +509,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) self.get_api_response_ext( - 200, url='/images?sort_key=container_format&marker=%s' % UUID6) + http.OK, url='/images?sort_key=container_format&marker=%s' % UUID6) def test_get_index_sort_name_asc(self): """ @@ -511,7 +527,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) url = '/images?sort_key=name&sort_dir=asc' - res = self.get_api_response_ext(200, url=url) + res = self.get_api_response_ext(http.OK, url=url) self.assertEqualImages(res, (UUID3, UUID2, UUID4)) def test_get_index_sort_status_desc(self): @@ -530,7 +546,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images?sort_key=status&sort_dir=desc')) self.assertEqualImages(res, (UUID3, UUID4, UUID2)) @@ -551,7 +567,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images?sort_key=disk_format&sort_dir=asc')) self.assertEqualImages(res, (UUID3, UUID4, UUID2)) @@ -574,7 +590,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) url = '/images?sort_key=container_format&sort_dir=desc' - res = self.get_api_response_ext(200, url=url) + res = self.get_api_response_ext(http.OK, url=url) self.assertEqualImages(res, (UUID2, UUID4, UUID3)) def test_get_index_sort_size_asc(self): @@ -595,7 +611,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) url = '/images?sort_key=size&sort_dir=asc' - res = self.get_api_response_ext(200, url=url) + res = self.get_api_response_ext(http.OK, url=url) self.assertEqualImages(res, (UUID4, UUID2, UUID3)) def test_get_index_sort_created_at_asc(self): @@ -617,7 +633,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images?sort_key=created_at&sort_dir=asc')) self.assertEqualImages(res, (UUID2, UUID4, UUID3)) @@ -642,7 +658,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images?sort_key=updated_at&sort_dir=desc')) self.assertEqualImages(res, (UUID3, UUID4, UUID2)) @@ -662,7 +678,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): 'container_format': 'ovf', 'status': 'active'} - res = self.get_api_response_ext(200, url='/images/detail') + res = self.get_api_response_ext(http.OK, url='/images/detail') res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -688,7 +704,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) url = '/images/detail?marker=%s&limit=1' % UUID3 - res = self.get_api_response_ext(200, url=url) + res = self.get_api_response_ext(http.OK, url=url) res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -703,14 +719,15 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): when an invalid marker is provided """ url = '/images/detail?marker=%s' % _gen_uuid() - self.get_api_response_ext(400, url=url) + self.get_api_response_ext(http.BAD_REQUEST, url=url) def test_get_details_malformed_marker(self): """ Tests that the /images/detail registry API returns a 400 when a malformed marker is provided """ - res = self.get_api_response_ext(400, url='/images/detail?marker=4') + res = self.get_api_response_ext(http.BAD_REQUEST, + url='/images/detail?marker=4') self.assertIn(b'marker', res.body) def test_get_details_forbidden_marker(self): @@ -720,7 +737,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): """ test_rserv = rserver.API(self.mapper) api = test_utils.FakeAuthMiddleware(test_rserv, is_admin=False) - self.get_api_response_ext(400, api=api, + self.get_api_response_ext(http.BAD_REQUEST, api=api, url='/images/detail?marker=%s' % UUID1) def test_get_details_filter_name(self): @@ -739,7 +756,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) url = '/images/detail?name=new name! #123' - res = self.get_api_response_ext(200, url=url) + res = self.get_api_response_ext(http.OK, url=url) res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -762,7 +779,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, + res = self.get_api_response_ext(http.OK, url='/images/detail?status=saving') res_dict = jsonutils.loads(res.body) @@ -788,7 +805,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) url = '/images/detail?container_format=ovf' - res = self.get_api_response_ext(200, url=url) + res = self.get_api_response_ext(http.OK, url=url) res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -811,7 +828,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url='/images/detail?min_disk=7') + res = self.get_api_response_ext(http.OK, + url='/images/detail?min_disk=7') res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -834,7 +852,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url='/images/detail?min_ram=514') + res = self.get_api_response_ext(http.OK, + url='/images/detail?min_ram=514') res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -857,7 +876,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, + res = self.get_api_response_ext(http.OK, url='/images/detail?disk_format=vhd') res_dict = jsonutils.loads(res.body) @@ -881,7 +900,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url='/images/detail?size_min=19') + res = self.get_api_response_ext(http.OK, + url='/images/detail?size_min=19') res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -904,7 +924,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url='/images/detail?size_max=19') + res = self.get_api_response_ext(http.OK, + url='/images/detail?size_max=19') res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -933,7 +954,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) url = '/images/detail?size_min=18&size_max=19' - res = self.get_api_response_ext(200, url=url) + res = self.get_api_response_ext(http.OK, url=url) res_dict = jsonutils.loads(res.body) images = res_dict['images'] @@ -980,42 +1001,42 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) # Check a standard list, 4 images in db (2 deleted) - res = self.get_api_response_ext(200, url='/images/detail') + res = self.get_api_response_ext(http.OK, url='/images/detail') self.assertEqualImages(res, (UUID4, UUID2)) # Expect 3 images (1 deleted) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images/detail?changes-since=%s' % iso1)) self.assertEqualImages(res, (UUID4, UUID3, UUID2)) # Expect 1 images (0 deleted) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images/detail?changes-since=%s' % iso2)) self.assertEqualImages(res, (UUID4,)) # Expect 1 images (0 deleted) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images/detail?changes-since=%s' % hour_before)) self.assertEqualImages(res, (UUID4,)) # Expect 0 images (0 deleted) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images/detail?changes-since=%s' % hour_after)) self.assertEqualImages(res, ()) # Expect 0 images (0 deleted) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images/detail?changes-since=%s' % iso4)) self.assertEqualImages(res, ()) for param in [date_only1, date_only2, date_only3]: # Expect 3 images (1 deleted) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images/detail?changes-since=%s' % param)) self.assertEqualImages(res, (UUID4, UUID3, UUID2)) # Bad request (empty changes-since param) - self.get_api_response_ext(400, + self.get_api_response_ext(http.BAD_REQUEST, url='/images/detail?changes-since=') def test_get_details_filter_property(self): @@ -1035,7 +1056,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images/detail?property-prop_123=v%20a')) res_dict = jsonutils.loads(res.body) @@ -1055,7 +1076,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, + res = self.get_api_response_ext(http.OK, url='/images/detail?is_public=None') res_dict = jsonutils.loads(res.body) @@ -1072,7 +1093,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, + res = self.get_api_response_ext(http.OK, url='/images/detail?is_public=False') res_dict = jsonutils.loads(res.body) @@ -1092,7 +1113,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, + res = self.get_api_response_ext(http.OK, url='/images/detail?is_public=True') res_dict = jsonutils.loads(res.body) @@ -1112,7 +1133,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - self.get_api_response_ext(400, url='/images/detail?is_public=public') + self.get_api_response_ext(http.BAD_REQUEST, + url='/images/detail?is_public=public') def test_get_details_filter_deleted_false(self): """ @@ -1131,7 +1153,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, + res = self.get_api_response_ext(http.OK, url='/images/detail?deleted=False') res_dict = jsonutils.loads(res.body) @@ -1152,7 +1174,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) test_rserv = rserver.API(self.mapper) api = test_utils.FakeAuthMiddleware(test_rserv, is_admin=False) - res = self.get_api_response_ext(200, api=api, + res = self.get_api_response_ext(http.OK, api=api, url='/images/detail?is_public=False') res_dict = jsonutils.loads(res.body) @@ -1170,7 +1192,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): protected="False") db_api.image_create(self.context, extra_fixture) - self.get_api_response_ext(400, url='/images/detail?protected=') + self.get_api_response_ext(http.BAD_REQUEST, + url='/images/detail?protected=') def test_get_filter_protected_with_True_value(self): """ @@ -1180,7 +1203,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): size=18, protected="True") db_api.image_create(self.context, extra_fixture) - self.get_api_response_ext(200, url='/images/detail?protected=True') + self.get_api_response_ext(http.OK, url='/images/detail?protected=True') def test_get_details_sort_name_asc(self): """ @@ -1198,7 +1221,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) - res = self.get_api_response_ext(200, url=( + res = self.get_api_response_ext(http.OK, url=( '/images/detail?sort_key=name&sort_dir=asc')) self.assertEqualImages(res, (UUID3, UUID2, UUID4)) @@ -1208,7 +1231,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = self.get_minimal_fixture() body = jsonutils.dump_as_bytes(dict(image=fixture)) - res = self.get_api_response_ext(200, body=body, + res = self.get_api_response_ext(http.OK, body=body, method='POST', content_type='json') res_dict = jsonutils.loads(res.body) @@ -1223,7 +1246,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = self.get_minimal_fixture(min_disk=5) body = jsonutils.dump_as_bytes(dict(image=fixture)) - res = self.get_api_response_ext(200, body=body, + res = self.get_api_response_ext(http.OK, body=body, method='POST', content_type='json') res_dict = jsonutils.loads(res.body) @@ -1234,7 +1257,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = self.get_minimal_fixture(min_ram=256) body = jsonutils.dump_as_bytes(dict(image=fixture)) - res = self.get_api_response_ext(200, body=body, + res = self.get_api_response_ext(http.OK, body=body, method='POST', content_type='json') res_dict = jsonutils.loads(res.body) @@ -1245,7 +1268,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = self.get_minimal_fixture() body = jsonutils.dump_as_bytes(dict(image=fixture)) - res = self.get_api_response_ext(200, body=body, + res = self.get_api_response_ext(http.OK, body=body, method='POST', content_type='json') res_dict = jsonutils.loads(res.body) @@ -1256,7 +1279,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = self.get_minimal_fixture() body = jsonutils.dump_as_bytes(dict(image=fixture)) - res = self.get_api_response_ext(200, body=body, + res = self.get_api_response_ext(http.OK, body=body, method='POST', content_type='json') res_dict = jsonutils.loads(res.body) @@ -1267,7 +1290,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = self.get_minimal_fixture(id=_gen_uuid(), status='bad status') body = jsonutils.dump_as_bytes(dict(image=fixture)) - res = self.get_api_response_ext(400, body=body, + res = self.get_api_response_ext(http.BAD_REQUEST, body=body, method='POST', content_type='json') self.assertIn(b'Invalid image status', res.body) @@ -1276,8 +1299,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = self.get_minimal_fixture(id='asdf') body = jsonutils.dump_as_bytes(dict(image=fixture)) - self.get_api_response_ext(400, content_type='json', method='POST', - body=body) + self.get_api_response_ext(http.BAD_REQUEST, content_type='json', + method='POST', body=body) def test_create_image_with_image_id_in_log(self): """Tests correct image id in log message when creating image""" @@ -1293,7 +1316,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): self.stubs.Set(rserver.images.LOG, 'info', fake_log_info) body = jsonutils.dump_as_bytes(dict(image=fixture)) - self.get_api_response_ext(200, content_type='json', method='POST', + self.get_api_response_ext(http.OK, content_type='json', method='POST', body=body) self.assertTrue(self.log_image_id) @@ -1305,7 +1328,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): 'disk_format': 'raw'} body = jsonutils.dump_as_bytes(dict(image=fixture)) - res = self.get_api_response_ext(200, url='/images/%s' % UUID2, + res = self.get_api_response_ext(http.OK, url='/images/%s' % UUID2, body=body, method='PUT', content_type='json') @@ -1336,7 +1359,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): log_debug.side_effect = fake_log_debug - res = self.get_api_response_ext(200, url='/images/%s' % UUID2, + res = self.get_api_response_ext(http.OK, url='/images/%s' % UUID2, body=body, method='PUT', content_type='json') @@ -1356,7 +1379,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = {'status': 'killed'} body = jsonutils.dump_as_bytes(dict(image=fixture)) - self.get_api_response_ext(404, url='/images/%s' % _gen_uuid(), + self.get_api_response_ext(http.NOT_FOUND, + url='/images/%s' % _gen_uuid(), method='PUT', body=body, content_type='json') def test_update_image_with_bad_status(self): @@ -1364,7 +1388,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = {'status': 'invalid'} body = jsonutils.dump_as_bytes(dict(image=fixture)) - res = self.get_api_response_ext(400, method='PUT', body=body, + res = self.get_api_response_ext(http.BAD_REQUEST, method='PUT', + body=body, url='/images/%s' % UUID2, content_type='json') self.assertIn(b'Invalid image status', res.body) @@ -1382,7 +1407,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): test_rserv = rserver.API(self.mapper) api = test_utils.FakeAuthMiddleware(test_rserv, is_admin=False) body = jsonutils.dump_as_bytes(dict(image=extra_fixture)) - self.get_api_response_ext(404, body=body, api=api, + self.get_api_response_ext(http.NOT_FOUND, body=body, api=api, url='/images/%s' % UUID8, method='PUT', content_type='json') @@ -1390,17 +1415,17 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): """Tests that the /images DELETE registry API deletes the image""" # Grab the original number of images - res = self.get_api_response_ext(200) + res = self.get_api_response_ext(http.OK) res_dict = jsonutils.loads(res.body) orig_num_images = len(res_dict['images']) # Delete image #2 - self.get_api_response_ext(200, url='/images/%s' % UUID2, + self.get_api_response_ext(http.OK, url='/images/%s' % UUID2, method='DELETE') # Verify one less image - res = self.get_api_response_ext(200) + res = self.get_api_response_ext(http.OK) res_dict = jsonutils.loads(res.body) new_num_images = len(res_dict['images']) @@ -1410,7 +1435,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): """Tests that the registry API delete returns the image metadata""" image = self.FIXTURES[0] - res = self.get_api_response_ext(200, url='/images/%s' % image['id'], + res = self.get_api_response_ext(http.OK, + url='/images/%s' % image['id'], method='DELETE') deleted_image = jsonutils.loads(res.body)['image'] @@ -1423,7 +1449,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): Tests proper exception is raised if attempt to delete non-existing image """ - self.get_api_response_ext(404, url='/images/%s' % _gen_uuid(), + self.get_api_response_ext(http.NOT_FOUND, + url='/images/%s' % _gen_uuid(), method='DELETE') def test_delete_public_image_no_admin(self): @@ -1438,7 +1465,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) test_rserv = rserver.API(self.mapper) api = test_utils.FakeAuthMiddleware(test_rserv, is_admin=False) - self.get_api_response_ext(403, url='/images/%s' % UUID8, + self.get_api_response_ext(http.FORBIDDEN, url='/images/%s' % UUID8, method='DELETE', api=api) def test_delete_private_image_no_admin(self): @@ -1453,14 +1480,15 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) test_rserv = rserver.API(self.mapper) api = test_utils.FakeAuthMiddleware(test_rserv, is_admin=False) - self.get_api_response_ext(404, url='/images/%s' % UUID8, + self.get_api_response_ext(http.NOT_FOUND, url='/images/%s' % UUID8, method='DELETE', api=api) def test_get_image_members(self): """ Tests members listing for existing images """ - res = self.get_api_response_ext(200, url='/images/%s/members' % UUID2, + res = self.get_api_response_ext(http.OK, + url='/images/%s/members' % UUID2, method='GET') memb_list = jsonutils.loads(res.body) @@ -1472,7 +1500,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): Tests proper exception is raised if attempt to get members of non-existing image """ - self.get_api_response_ext(404, method='GET', + self.get_api_response_ext(http.NOT_FOUND, method='GET', url='/images/%s/members' % _gen_uuid()) def test_get_image_members_forbidden(self): @@ -1488,14 +1516,16 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): db_api.image_create(self.context, extra_fixture) test_rserv = rserver.API(self.mapper) api = test_utils.FakeAuthMiddleware(test_rserv, is_admin=False) - self.get_api_response_ext(404, url='/images/%s/members' % UUID8, + self.get_api_response_ext(http.NOT_FOUND, + url='/images/%s/members' % UUID8, method='GET', api=api) def test_get_member_images(self): """ Tests image listing for members """ - res = self.get_api_response_ext(200, url='/shared-images/pattieblack', + res = self.get_api_response_ext(http.OK, + url='/shared-images/pattieblack', method='GET') memb_list = jsonutils.loads(res.body) @@ -1511,7 +1541,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = dict(member_id='pattieblack') body = jsonutils.dump_as_bytes(dict(image_memberships=fixture)) - self.get_api_response_ext(401, method='PUT', body=body, + self.get_api_response_ext(http.UNAUTHORIZED, method='PUT', body=body, url='/images/%s/members' % UUID2, content_type='json') @@ -1527,7 +1557,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): req.content_type = 'application/json' req.body = jsonutils.dump_as_bytes(dict(image_memberships=fixture)) res = req.get_response(self.api) - self.assertEqual(404, res.status_int) + self.assertEqual(http.NOT_FOUND, res.status_int) def test_update_all_image_members_invalid_membership_association(self): """ @@ -1544,7 +1574,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): req.method = 'PUT' res = req.get_response(self.api) # Get all image members: - res = self.get_api_response_ext(200, url='/images/%s/members' % UUID8, + res = self.get_api_response_ext(http.OK, + url='/images/%s/members' % UUID8, method='GET') memb_list = jsonutils.loads(res.body) @@ -1553,7 +1584,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = dict(member_id='test1') body = jsonutils.dump_as_bytes(dict(image_memberships=fixture)) - self.get_api_response_ext(400, url='/images/%s/members' % UUID8, + self.get_api_response_ext(http.BAD_REQUEST, + url='/images/%s/members' % UUID8, method='PUT', body=body, content_type='json') @@ -1575,7 +1607,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): req.body = jsonutils.dump_as_bytes(dict(image_memberships=fixture)) res = req.get_response(api) - self.assertEqual(403, res.status_int) + self.assertEqual(http.FORBIDDEN, res.status_int) def test_update_all_image_members(self): """ @@ -1594,7 +1626,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = [dict(member_id='test2', can_share=True)] body = jsonutils.dump_as_bytes(dict(memberships=fixture)) - self.get_api_response_ext(204, url='/images/%s/members' % UUID8, + self.get_api_response_ext(http.NO_CONTENT, + url='/images/%s/members' % UUID8, method='PUT', body=body, content_type='json') @@ -1615,7 +1648,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): req.get_response(self.api) fixture = dict(member_id='test3') body = jsonutils.dump_as_bytes(dict(memberships=fixture)) - self.get_api_response_ext(400, url='/images/%s/members' % UUID8, + self.get_api_response_ext(http.BAD_REQUEST, + url='/images/%s/members' % UUID8, method='PUT', body=body, content_type='json') @@ -1636,7 +1670,8 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = [dict(member_id='test1', can_share=False)] body = jsonutils.dump_as_bytes(dict(memberships=fixture)) - self.get_api_response_ext(204, url='/images/%s/members' % UUID8, + self.get_api_response_ext(http.NO_CONTENT, + url='/images/%s/members' % UUID8, method='PUT', body=body, content_type='json') @@ -1656,13 +1691,14 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): req.get_response(self.api) # Delete the existing member - self.get_api_response_ext(204, method='DELETE', + self.get_api_response_ext(http.NO_CONTENT, method='DELETE', url='/images/%s/members/test1' % UUID8) # Re-add the deleted member by replacing membership list fixture = [dict(member_id='test1', can_share=False)] body = jsonutils.dump_as_bytes(dict(memberships=fixture)) - self.get_api_response_ext(204, url='/images/%s/members' % UUID8, + self.get_api_response_ext(http.NO_CONTENT, + url='/images/%s/members' % UUID8, method='PUT', body=body, content_type='json') memb_list = db_api.image_member_find(self.context, image_id=UUID8) @@ -1674,7 +1710,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): """ self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper), is_admin=False) - self.get_api_response_ext(401, method='PUT', + self.get_api_response_ext(http.UNAUTHORIZED, method='PUT', url=('/images/%s/members/pattieblack' % UUID2)) @@ -1690,7 +1726,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = dict(can_share=True) test_uri = '/images/%s/members/test_add_member_positive' body = jsonutils.dump_as_bytes(dict(member=fixture)) - self.get_api_response_ext(204, url=test_uri % UUID8, + self.get_api_response_ext(http.NO_CONTENT, url=test_uri % UUID8, method='PUT', body=body, content_type='json') @@ -1702,7 +1738,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = dict(can_share=True) test_uri = '/images/%s/members/test_add_member_positive' body = jsonutils.dump_as_bytes(dict(member=fixture)) - self.get_api_response_ext(404, url=test_uri % _gen_uuid(), + self.get_api_response_ext(http.NOT_FOUND, url=test_uri % _gen_uuid(), method='PUT', body=body, content_type='json') @@ -1725,7 +1761,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): req.body = jsonutils.dump_as_bytes(dict(member=fixture)) res = req.get_response(api) - self.assertEqual(403, res.status_int) + self.assertEqual(http.FORBIDDEN, res.status_int) def test_add_member_to_image_bad_request(self): """ @@ -1740,7 +1776,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = [dict(can_share=True)] test_uri = '/images/%s/members/test_add_member_bad_request' body = jsonutils.dump_as_bytes(dict(member=fixture)) - self.get_api_response_ext(400, url=test_uri % UUID8, + self.get_api_response_ext(http.BAD_REQUEST, url=test_uri % UUID8, method='PUT', body=body, content_type='json') @@ -1750,7 +1786,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): """ self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper), is_admin=False) - self.get_api_response_ext(401, method='DELETE', + self.get_api_response_ext(http.UNAUTHORIZED, method='DELETE', url=('/images/%s/members/pattieblack' % UUID2)) @@ -1760,9 +1796,9 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): """ self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper), is_admin=True) - res = self.get_api_response_ext(404, method='DELETE', - url=('/images/%s/members/pattieblack' % - UUID2)) + res = self.get_api_response_ext( + http.NOT_FOUND, method='DELETE', + url=('/images/%s/members/pattieblack' % UUID2)) self.assertIn(b'Membership could not be found', res.body) def test_delete_member_from_non_exist_image(self): @@ -1773,7 +1809,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): self.api = test_utils.FakeAuthMiddleware( test_rserver_api, is_admin=True) test_uri = '/images/%s/members/pattieblack' - self.get_api_response_ext(404, method='DELETE', + self.get_api_response_ext(http.NOT_FOUND, method='DELETE', url=test_uri % _gen_uuid()) def test_delete_image_member_non_shared_image_forbidden(self): @@ -1794,7 +1830,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): req.content_type = 'application/json' res = req.get_response(api) - self.assertEqual(403, res.status_int) + self.assertEqual(http.FORBIDDEN, res.status_int) def test_add_member_delete_create(self): """ @@ -1810,7 +1846,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): fixture = dict(can_share=True) test_uri = '/images/%s/members/test_add_member_delete_create' body = jsonutils.dump_as_bytes(dict(member=fixture)) - self.get_api_response_ext(204, url=test_uri % UUID8, + self.get_api_response_ext(http.NO_CONTENT, url=test_uri % UUID8, method='PUT', body=body, content_type='json') memb_list = db_api.image_member_find(self.context, image_id=UUID8) @@ -1820,7 +1856,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): include_deleted=True) self.assertEqual(1, len(memb_list2)) # delete the member - self.get_api_response_ext(204, method='DELETE', + self.get_api_response_ext(http.NO_CONTENT, method='DELETE', url=test_uri % UUID8) memb_list = db_api.image_member_find(self.context, image_id=UUID8) self.assertEqual(0, len(memb_list)) @@ -1829,7 +1865,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): include_deleted=True) self.assertEqual(1, len(memb_list2)) # create it again - self.get_api_response_ext(204, url=test_uri % UUID8, + self.get_api_response_ext(http.NO_CONTENT, url=test_uri % UUID8, method='PUT', body=body, content_type='json') memb_list = db_api.image_member_find(self.context, image_id=UUID8) @@ -1841,7 +1877,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): def test_get_on_image_member(self): """ - Test GET on image members raises 405 and produces correct Allow headers + Test GET on image members raises 404 and produces correct Allow headers """ self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper), is_admin=False) @@ -1849,20 +1885,21 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): req = webob.Request.blank(uri) req.method = 'GET' res = req.get_response(self.api) - self.assertEqual(405, res.status_int) + self.assertEqual(http.METHOD_NOT_ALLOWED, res.status_int) self.assertIn(('Allow', 'PUT, DELETE'), res.headerlist) def test_get_images_bad_urls(self): """Check that routes collections are not on (LP bug 1185828)""" - self.get_api_response_ext(404, url='/images/detail.xxx') + self.get_api_response_ext(http.NOT_FOUND, url='/images/detail.xxx') - self.get_api_response_ext(404, url='/images.xxx') + self.get_api_response_ext(http.NOT_FOUND, url='/images.xxx') - self.get_api_response_ext(404, url='/images/new') + self.get_api_response_ext(http.NOT_FOUND, url='/images/new') - self.get_api_response_ext(200, url='/images/%s/members' % UUID1) + self.get_api_response_ext(http.OK, url='/images/%s/members' % UUID1) - self.get_api_response_ext(404, url='/images/%s/members.xxx' % UUID1) + self.get_api_response_ext(http.NOT_FOUND, + url='/images/%s/members.xxx' % UUID1) class TestRegistryAPILocations(base.IsolatedUnitTest, @@ -1901,7 +1938,7 @@ class TestRegistryAPILocations(base.IsolatedUnitTest, def test_show_from_locations(self): req = webob.Request.blank('/images/%s' % UUID1) 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) image = res_dict['image'] self.assertIn('id', image['location_data'][0]) @@ -1916,7 +1953,7 @@ class TestRegistryAPILocations(base.IsolatedUnitTest, def test_show_from_location_data(self): req = webob.Request.blank('/images/%s' % UUID2) 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) image = res_dict['image'] self.assertIn('id', image['location_data'][0]) @@ -1960,7 +1997,7 @@ class TestRegistryAPILocations(base.IsolatedUnitTest, req.body = jsonutils.dump_as_bytes(dict(image=fixture)) 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) image = res_dict['image'] # NOTE(zhiyan) _normalize_image_location_for_db() function will diff --git a/glance/tests/unit/v1/test_registry_client.py b/glance/tests/unit/v1/test_registry_client.py index 3c8f2fa9e4..147ef8f31f 100644 --- a/glance/tests/unit/v1/test_registry_client.py +++ b/glance/tests/unit/v1/test_registry_client.py @@ -19,6 +19,7 @@ import os import uuid from mock import patch +from six.moves import http_client as http from six.moves import reload_module import testtools @@ -913,7 +914,7 @@ class TestRegistryV1ClientApi(base.IsolatedUnitTest): class FakeResponse(object): - status = 202 + status = http.ACCEPTED def getheader(*args, **kwargs): return None diff --git a/glance/tests/unit/v2/test_image_data_resource.py b/glance/tests/unit/v2/test_image_data_resource.py index 87a2bea160..ef5147251a 100644 --- a/glance/tests/unit/v2/test_image_data_resource.py +++ b/glance/tests/unit/v2/test_image_data_resource.py @@ -18,6 +18,7 @@ from cursive import exception as cursive_exception import glance_store import mock import six +from six.moves import http_client as http import webob import glance.api.policy @@ -662,5 +663,5 @@ class TestImageDataSerializer(test_utils.BaseTestCase): response = webob.Response() response.request = request self.serializer.upload(response, {}) - self.assertEqual(204, response.status_int) + self.assertEqual(http.NO_CONTENT, response.status_int) self.assertEqual('0', response.headers['Content-Length']) diff --git a/glance/tests/unit/v2/test_image_members_resource.py b/glance/tests/unit/v2/test_image_members_resource.py index 98b26bcc76..7f8c98de38 100644 --- a/glance/tests/unit/v2/test_image_members_resource.py +++ b/glance/tests/unit/v2/test_image_members_resource.py @@ -18,6 +18,7 @@ import datetime import glance_store from oslo_config import cfg from oslo_serialization import jsonutils +from six.moves import http_client as http import webob import glance.api.v2.image_members @@ -346,7 +347,7 @@ class TestImageMembersController(test_utils.BaseTestCase): image_id = UUID2 res = self.controller.delete(request, image_id, member_id) self.assertEqual(b'', res.body) - self.assertEqual(204, res.status_code) + self.assertEqual(http.NO_CONTENT, res.status_code) found_member = self.db.image_member_find( request.context, image_id=image_id, member=member_id) self.assertEqual([], found_member) diff --git a/glance/tests/unit/v2/test_image_tags_resource.py b/glance/tests/unit/v2/test_image_tags_resource.py index 6c68e2b655..7684197539 100644 --- a/glance/tests/unit/v2/test_image_tags_resource.py +++ b/glance/tests/unit/v2/test_image_tags_resource.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from six.moves import http_client as http import webob import glance.api.v2.image_tags @@ -96,9 +97,9 @@ class TestImagesSerializer(test_utils.BaseTestCase): def test_create_tag(self): response = webob.Response() self.serializer.update(response, None) - self.assertEqual(204, response.status_int) + self.assertEqual(http.NO_CONTENT, response.status_int) def test_delete_tag(self): response = webob.Response() self.serializer.delete(response, None) - self.assertEqual(204, response.status_int) + self.assertEqual(http.NO_CONTENT, response.status_int) diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py index a0fe9f2515..5ea477eed4 100644 --- a/glance/tests/unit/v2/test_images_resource.py +++ b/glance/tests/unit/v2/test_images_resource.py @@ -21,6 +21,7 @@ import mock from oslo_config import cfg from oslo_serialization import jsonutils import six +from six.moves import http_client as http # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range import testtools @@ -3260,12 +3261,12 @@ class TestImagesSerializer(test_utils.BaseTestCase): request = webob.Request.blank(url) response = webob.Response(request=request) result = {'images': self.fixtures} - self.assertEqual(200, response.status_int) + self.assertEqual(http.OK, response.status_int) # The image index should work though the user is forbidden result['images'][0].locations = ImageLocations() self.serializer.index(response, result) - self.assertEqual(200, response.status_int) + self.assertEqual(http.OK, response.status_int) def test_show_full_fixture(self): expected = { @@ -3346,7 +3347,7 @@ class TestImagesSerializer(test_utils.BaseTestCase): } response = webob.Response() self.serializer.create(response, self.fixtures[0]) - self.assertEqual(201, response.status_int) + self.assertEqual(http.CREATED, response.status_int) actual = jsonutils.loads(response.body) actual['tags'] = sorted(actual['tags']) self.assertEqual(expected, actual) @@ -3505,7 +3506,7 @@ class TestImagesSerializerWithUnicode(test_utils.BaseTestCase): } response = webob.Response() self.serializer.create(response, self.fixtures[0]) - self.assertEqual(201, response.status_int) + self.assertEqual(http.CREATED, response.status_int) actual = jsonutils.loads(response.body) actual['tags'] = sorted(actual['tags']) self.assertEqual(expected, actual) diff --git a/glance/tests/unit/v2/test_registry_api.py b/glance/tests/unit/v2/test_registry_api.py index 6adf55fe03..44626753a6 100644 --- a/glance/tests/unit/v2/test_registry_api.py +++ b/glance/tests/unit/v2/test_registry_api.py @@ -22,6 +22,7 @@ from oslo_config import cfg from oslo_serialization import jsonutils import routes import six +from six.moves import http_client as http import webob import glance.api.common @@ -131,7 +132,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] image = res_dict for k, v in six.iteritems(fixture): @@ -167,7 +168,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(1, len(images)) @@ -235,7 +236,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] # should be sorted by created_at desc, id desc @@ -272,7 +273,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(2, len(images)) @@ -305,7 +306,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -338,7 +339,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(2, len(images)) @@ -371,7 +372,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -404,7 +405,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(2, len(images)) @@ -437,7 +438,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -501,7 +502,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) images = jsonutils.loads(res.body)[0] - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) self._compare_images_and_uuids([UUID4], images) @@ -549,7 +550,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) res_dict = jsonutils.loads(res.body)[0] - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = res_dict self._compare_images_and_uuids([UUID2], images) @@ -592,7 +593,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) res_dict = jsonutils.loads(res.body)[0] - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = res_dict self.assertEqual(2, len(images)) @@ -626,7 +627,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(2, len(images)) self.assertEqual(extra_id, images[0]['id']) @@ -639,7 +640,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -650,7 +651,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -661,7 +662,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -672,7 +673,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(1, len(images)) self.assertEqual(extra_id, images[0]['id']) @@ -684,7 +685,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -695,7 +696,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -706,7 +707,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = jsonutils.loads(res.body)[0] self.assertEqual(0, len(images)) @@ -769,7 +770,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) res_dict = jsonutils.loads(res.body)[0] - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) images = res_dict # (flaper87)registry's v1 forced is_public to True @@ -826,7 +827,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -875,7 +876,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -923,7 +924,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -972,7 +973,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1017,7 +1018,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1069,7 +1070,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1121,7 +1122,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1188,7 +1189,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1202,7 +1203,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1269,7 +1270,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1283,7 +1284,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1297,7 +1298,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1311,7 +1312,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): }] req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] images = res_dict @@ -1335,7 +1336,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] @@ -1363,7 +1364,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] @@ -1387,7 +1388,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] @@ -1410,7 +1411,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] @@ -1433,7 +1434,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] @@ -1456,7 +1457,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) res_dict = jsonutils.loads(res.body)[0] @@ -1483,7 +1484,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): self.assertEqual(error_cls, res_dict['_error']['cls']) return res_dict - def _expect_ok(self, command, kwargs, method, expected_status=200): + def _expect_ok(self, command, kwargs, method, expected_status=http.OK): code, res_dict = self._send_request(command, kwargs) self.assertEqual(expected_status, code) return res_dict @@ -1558,7 +1559,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) res_dict = jsonutils.loads(res.body)[0] - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) orig_num_images = len(res_dict) @@ -1570,7 +1571,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) # Verify one less image cmd = [{ @@ -1580,7 +1581,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) res_dict = jsonutils.loads(res.body)[0] - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) new_num_images = len(res_dict) self.assertEqual(new_num_images, orig_num_images - 1) @@ -1598,7 +1599,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) deleted_image = jsonutils.loads(res.body)[0] self.assertEqual(image['id'], deleted_image['id']) @@ -1616,7 +1617,7 @@ class TestRegistryRPC(base.IsolatedUnitTest): req.body = jsonutils.dump_as_bytes(cmd) res = req.get_response(self.api) - self.assertEqual(200, res.status_int) + self.assertEqual(http.OK, res.status_int) memb_list = jsonutils.loads(res.body)[0] self.assertEqual(0, len(memb_list)) diff --git a/glance/tests/unit/v2/test_tasks_resource.py b/glance/tests/unit/v2/test_tasks_resource.py index 641002a2e5..c6f9fcb871 100644 --- a/glance/tests/unit/v2/test_tasks_resource.py +++ b/glance/tests/unit/v2/test_tasks_resource.py @@ -20,6 +20,7 @@ import uuid import mock from oslo_config import cfg from oslo_serialization import jsonutils +from six.moves import http_client as http # NOTE(jokke): simplified transition to py3, behaves like py2 xrange from six.moves import range import webob @@ -811,7 +812,7 @@ class TestTasksSerializer(test_utils.BaseTestCase): self.serializer.create(response, self.fixtures[3]) serialized_task = jsonutils.loads(response.body) - self.assertEqual(201, response.status_int) + self.assertEqual(http.CREATED, response.status_int) self.assertEqual(self.fixtures[3].task_id, serialized_task['id']) self.assertEqual(self.fixtures[3].task_input, @@ -825,7 +826,7 @@ class TestTasksSerializer(test_utils.BaseTestCase): self.serializer.create(response, self.fixtures[0]) serialized_task = jsonutils.loads(response.body) - self.assertEqual(201, response.status_int) + self.assertEqual(http.CREATED, response.status_int) self.assertEqual(self.fixtures[0].task_id, serialized_task['id']) self.assertEqual(self.fixtures[0].task_input, @@ -838,7 +839,7 @@ class TestTasksSerializer(test_utils.BaseTestCase): self.serializer.create(response, self.fixtures[1]) serialized_task = jsonutils.loads(response.body) - self.assertEqual(201, response.status_int) + self.assertEqual(http.CREATED, response.status_int) self.assertEqual(self.fixtures[1].task_id, serialized_task['id']) self.assertEqual(self.fixtures[1].task_input, diff --git a/glance/tests/utils.py b/glance/tests/utils.py index 802dbce55e..3757483ac7 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -31,6 +31,7 @@ from oslo_serialization import jsonutils from oslotest import moxstubout import six from six.moves import BaseHTTPServer +from six.moves import http_client as http import testtools import webob @@ -437,7 +438,7 @@ def start_http_server(image_id, image_data): def _get_http_handler_class(fixture): class StaticHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): - self.send_response(200) + self.send_response(http.OK) self.send_header('Content-Length', str(len(fixture))) self.end_headers() self.wfile.write(fixture) @@ -447,9 +448,9 @@ def start_http_server(image_id, image_data): # reserve non_existing_image_path for the cases where we expect # 404 from the server if 'non_existing_image_path' in self.path: - self.send_response(404) + self.send_response(http.NOT_FOUND) else: - self.send_response(200) + self.send_response(http.OK) self.send_header('Content-Length', str(len(fixture))) self.end_headers() return @@ -574,7 +575,8 @@ class FakeAuthMiddleware(wsgi.Middleware): class FakeHTTPResponse(object): - def __init__(self, status=200, headers=None, data=None, *args, **kwargs): + def __init__(self, status=http.OK, headers=None, data=None, + *args, **kwargs): data = data or b'I am a teapot, short and stout\n' self.data = six.BytesIO(data) self.read = self.data.read