Merge "Refactor API function test class"
This commit is contained in:
commit
31221b1904
@ -22,13 +22,11 @@ from oslo.serialization import jsonutils
|
|||||||
from glance.tests import functional
|
from glance.tests import functional
|
||||||
|
|
||||||
|
|
||||||
class TestRootApi(functional.FunctionalTest):
|
class TestApiVersions(functional.FunctionalTest):
|
||||||
|
|
||||||
def test_version_configurations(self):
|
def test_version_configurations(self):
|
||||||
"""Test that versioning is handled properly through all channels"""
|
"""Test that versioning is handled properly through all channels"""
|
||||||
|
|
||||||
# v1 and v2 api enabled
|
# v1 and v2 api enabled
|
||||||
self.cleanup()
|
|
||||||
self.start_servers(**self.__dict__.copy())
|
self.start_servers(**self.__dict__.copy())
|
||||||
|
|
||||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||||
@ -72,10 +70,8 @@ class TestRootApi(functional.FunctionalTest):
|
|||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(versions_json, content)
|
||||||
self.stop_servers()
|
|
||||||
|
|
||||||
# v2 api enabled
|
def test_v2_api_configuration(self):
|
||||||
self.cleanup()
|
|
||||||
self.api_server.enable_v1_api = False
|
self.api_server.enable_v1_api = False
|
||||||
self.api_server.enable_v2_api = True
|
self.api_server.enable_v2_api = True
|
||||||
self.start_servers(**self.__dict__.copy())
|
self.start_servers(**self.__dict__.copy())
|
||||||
@ -111,10 +107,8 @@ class TestRootApi(functional.FunctionalTest):
|
|||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(versions_json, content)
|
||||||
self.stop_servers()
|
|
||||||
|
|
||||||
# v1 api enabled
|
def test_v1_api_configuration(self):
|
||||||
self.cleanup()
|
|
||||||
self.api_server.enable_v1_api = True
|
self.api_server.enable_v1_api = True
|
||||||
self.api_server.enable_v2_api = False
|
self.api_server.enable_v2_api = False
|
||||||
self.start_servers(**self.__dict__.copy())
|
self.start_servers(**self.__dict__.copy())
|
||||||
@ -140,12 +134,11 @@ class TestRootApi(functional.FunctionalTest):
|
|||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(versions_json, content)
|
||||||
self.stop_servers()
|
|
||||||
|
|
||||||
def test_version_variations(self):
|
|
||||||
"""Test that versioning is handled properly through all channels"""
|
|
||||||
|
|
||||||
self.cleanup()
|
class TestApiPaths(functional.FunctionalTest):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestApiPaths, self).setUp()
|
||||||
self.start_servers(**self.__dict__.copy())
|
self.start_servers(**self.__dict__.copy())
|
||||||
|
|
||||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||||
@ -181,133 +174,162 @@ class TestRootApi(functional.FunctionalTest):
|
|||||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
versions_json = jsonutils.dumps(versions)
|
self.versions_json = jsonutils.dumps(versions)
|
||||||
images = {'images': []}
|
images = {'images': []}
|
||||||
images_json = jsonutils.dumps(images)
|
self.images_json = jsonutils.dumps(images)
|
||||||
|
|
||||||
# 0. GET / with no Accept: header
|
def test_get_root_path(self):
|
||||||
# Verify version choices returned.
|
"""Assert GET / with `no Accept:` header.
|
||||||
# Bug lp:803260 no Accept header causes a 500 in glance-api
|
Verify version choices returned.
|
||||||
|
Bug lp:803260 no Accept header causes a 500 in glance-api
|
||||||
|
"""
|
||||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 1. GET /images with no Accept: header
|
def test_get_images_path(self):
|
||||||
# Verify version choices returned.
|
"""Assert GET /images with `no Accept:` header.
|
||||||
|
Verify version choices returned.
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 2. GET /v1/images with no Accept: header
|
def test_get_v1_images_path(self):
|
||||||
# Verify empty images list returned.
|
"""GET /v1/images with `no Accept:` header.
|
||||||
|
Verify empty images list returned.
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/v1/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/v1/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(200, response.status)
|
||||||
self.assertEqual(images_json, content)
|
|
||||||
|
|
||||||
# 3. GET / with Accept: unknown header
|
def test_get_root_path_with_unknown_header(self):
|
||||||
# Verify version choices returned. Verify message in API log about
|
"""Assert GET / with Accept: unknown header
|
||||||
# unknown accept header.
|
Verify version choices returned. Verify message in API log about
|
||||||
|
unknown accept header.
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'unknown'}
|
headers = {'Accept': 'unknown'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
response, content = http.request(path, 'GET', headers=headers)
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 4. GET / with an Accept: application/vnd.openstack.images-v1
|
def test_get_root_path_with_openstack_header(self):
|
||||||
# Verify empty image list returned
|
"""Assert GET / with an Accept: application/vnd.openstack.images-v1
|
||||||
|
Verify empty image list returned
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
response, content = http.request(path, 'GET', headers=headers)
|
||||||
self.assertEqual(200, response.status)
|
self.assertEqual(200, response.status)
|
||||||
self.assertEqual(images_json, content)
|
self.assertEqual(self.images_json, content)
|
||||||
|
|
||||||
# 5. GET /images with a Accept: application/vnd.openstack.compute-v1
|
def test_get_images_path_with_openstack_header(self):
|
||||||
# header. Verify version choices returned. Verify message in API log
|
"""Assert GET /images with a
|
||||||
# about unknown accept header.
|
`Accept: application/vnd.openstack.compute-v1` header.
|
||||||
|
Verify version choices returned. Verify message in API log
|
||||||
|
about unknown accept header.
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'application/vnd.openstack.compute-v1'}
|
headers = {'Accept': 'application/vnd.openstack.compute-v1'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
response, content = http.request(path, 'GET', headers=headers)
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 6. GET /v1.0/images with no Accept: header
|
def test_get_v10_images_path(self):
|
||||||
# Verify version choices returned
|
"""Assert GET /v1.0/images with no Accept: header
|
||||||
|
Verify version choices returned
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
|
|
||||||
# 7. GET /v1.a/images with no Accept: header
|
def test_get_v1a_images_path(self):
|
||||||
# Verify version choices returned
|
"""Assert GET /v1.a/images with no Accept: header
|
||||||
|
Verify version choices returned
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
|
|
||||||
# 8. GET /va.1/images with no Accept: header
|
def test_get_va1_images_path(self):
|
||||||
# Verify version choices returned
|
"""Assert GET /va.1/images with no Accept: header
|
||||||
|
Verify version choices returned
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/va.1/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/va.1/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 9. GET /versions with no Accept: header
|
def test_get_versions_path(self):
|
||||||
# Verify version choices returned
|
"""Assert GET /versions with no Accept: header
|
||||||
|
Verify version choices returned
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 10. GET /versions with a Accept: application/vnd.openstack.images-v1
|
def test_get_versions_path_with_openstack_header(self):
|
||||||
# header. Verify version choices returned.
|
"""Assert GET /versions with the
|
||||||
|
`Accept: application/vnd.openstack.images-v1` header.
|
||||||
|
Verify version choices returned.
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
response, content = http.request(path, 'GET', headers=headers)
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 11. GET /v1/versions with no Accept: header
|
def test_get_v1_versions_path(self):
|
||||||
# Verify 404 returned
|
"""Assert GET /v1/versions with `no Accept:` header
|
||||||
|
Verify 404 returned
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/v1/versions' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/v1/versions' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(404, response.status)
|
self.assertEqual(404, response.status)
|
||||||
|
|
||||||
# Verify version choices returned
|
def test_get_versions_choices(self):
|
||||||
|
"""Verify version choices returned"""
|
||||||
path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 13. GET /images with a Accept: application/vnd.openstack.compute-v2
|
def test_get_images_path_with_openstack_v2_header(self):
|
||||||
# header. Verify version choices returned. Verify message in API log
|
"""Assert GET /images with a
|
||||||
# about unknown version in accept header.
|
`Accept: application/vnd.openstack.compute-v2` header.
|
||||||
|
Verify version choices returned. Verify message in API log
|
||||||
|
about unknown version in accept header.
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
headers = {'Accept': 'application/vnd.openstack.images-v10'}
|
headers = {'Accept': 'application/vnd.openstack.images-v10'}
|
||||||
response, content = http.request(path, 'GET', headers=headers)
|
response, content = http.request(path, 'GET', headers=headers)
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
# 14. GET /v1.2/images with no Accept: header
|
def test_get_v12_images_path(self):
|
||||||
# Verify version choices returned
|
"""Assert GET /v1.2/images with `no Accept:` header
|
||||||
|
Verify version choices returned
|
||||||
|
"""
|
||||||
path = 'http://%s:%d/v1.2/images' % ('127.0.0.1', self.api_port)
|
path = 'http://%s:%d/v1.2/images' % ('127.0.0.1', self.api_port)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
response, content = http.request(path, 'GET')
|
response, content = http.request(path, 'GET')
|
||||||
self.assertEqual(300, response.status)
|
self.assertEqual(300, response.status)
|
||||||
self.assertEqual(versions_json, content)
|
self.assertEqual(self.versions_json, content)
|
||||||
|
|
||||||
self.stop_servers()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user