Add unit test for xmlns version matching request version.
This commit is contained in:
@@ -36,6 +36,7 @@ from nova.auth import manager
|
|||||||
class FakeHttplibSocket(object):
|
class FakeHttplibSocket(object):
|
||||||
"""a fake socket implementation for httplib.HTTPResponse, trivial"""
|
"""a fake socket implementation for httplib.HTTPResponse, trivial"""
|
||||||
def __init__(self, response_string):
|
def __init__(self, response_string):
|
||||||
|
self.response_string = response_string
|
||||||
self._buffer = StringIO.StringIO(response_string)
|
self._buffer = StringIO.StringIO(response_string)
|
||||||
|
|
||||||
def makefile(self, _mode, _other):
|
def makefile(self, _mode, _other):
|
||||||
@@ -66,13 +67,16 @@ class FakeHttplibConnection(object):
|
|||||||
# For some reason, the response doesn't have "HTTP/1.0 " prepended; I
|
# For some reason, the response doesn't have "HTTP/1.0 " prepended; I
|
||||||
# guess that's a function the web server usually provides.
|
# guess that's a function the web server usually provides.
|
||||||
resp = "HTTP/1.0 %s" % resp
|
resp = "HTTP/1.0 %s" % resp
|
||||||
sock = FakeHttplibSocket(resp)
|
self.sock = FakeHttplibSocket(resp)
|
||||||
self.http_response = httplib.HTTPResponse(sock)
|
self.http_response = httplib.HTTPResponse(self.sock)
|
||||||
self.http_response.begin()
|
self.http_response.begin()
|
||||||
|
|
||||||
def getresponse(self):
|
def getresponse(self):
|
||||||
return self.http_response
|
return self.http_response
|
||||||
|
|
||||||
|
def getresponsebody(self):
|
||||||
|
return self.sock.response_string
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Required for compatibility with boto/tornado"""
|
"""Required for compatibility with boto/tornado"""
|
||||||
pass
|
pass
|
||||||
@@ -104,7 +108,7 @@ class ApiEc2TestCase(test.TestCase):
|
|||||||
self.app = ec2.Authenticate(ec2.Requestify(ec2.Executor(),
|
self.app = ec2.Authenticate(ec2.Requestify(ec2.Executor(),
|
||||||
'nova.api.ec2.cloud.CloudController'))
|
'nova.api.ec2.cloud.CloudController'))
|
||||||
|
|
||||||
def expect_http(self, host=None, is_secure=False):
|
def expect_http(self, host=None, is_secure=False, api_version=None):
|
||||||
"""Returns a new EC2 connection"""
|
"""Returns a new EC2 connection"""
|
||||||
self.ec2 = boto.connect_ec2(
|
self.ec2 = boto.connect_ec2(
|
||||||
aws_access_key_id='fake',
|
aws_access_key_id='fake',
|
||||||
@@ -113,13 +117,31 @@ class ApiEc2TestCase(test.TestCase):
|
|||||||
region=regioninfo.RegionInfo(None, 'test', self.host),
|
region=regioninfo.RegionInfo(None, 'test', self.host),
|
||||||
port=8773,
|
port=8773,
|
||||||
path='/services/Cloud')
|
path='/services/Cloud')
|
||||||
|
if api_version:
|
||||||
|
self.ec2.APIVersion = api_version
|
||||||
|
|
||||||
self.mox.StubOutWithMock(self.ec2, 'new_http_connection')
|
self.mox.StubOutWithMock(self.ec2, 'new_http_connection')
|
||||||
http = FakeHttplibConnection(
|
self.http = FakeHttplibConnection(
|
||||||
self.app, '%s:8773' % (self.host), False)
|
self.app, '%s:8773' % (self.host), False)
|
||||||
# pylint: disable-msg=E1103
|
# pylint: disable-msg=E1103
|
||||||
self.ec2.new_http_connection(host, is_secure).AndReturn(http)
|
self.ec2.new_http_connection(host, is_secure).AndReturn(self.http)
|
||||||
return http
|
return self.http
|
||||||
|
|
||||||
|
def test_xmlns_version_matches_request_version(self):
|
||||||
|
self.expect_http(api_version='2010-10-30')
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
user = self.manager.create_user('fake', 'fake', 'fake')
|
||||||
|
project = self.manager.create_project('fake', 'fake', 'fake')
|
||||||
|
|
||||||
|
# Any request should be fine
|
||||||
|
self.ec2.get_all_instances()
|
||||||
|
self.assertTrue(self.ec2.APIVersion in self.http.getresponsebody(),
|
||||||
|
'The version in the xmlns of the response does '
|
||||||
|
'not match the API version given in the request.')
|
||||||
|
|
||||||
|
self.manager.delete_project(project)
|
||||||
|
self.manager.delete_user(user)
|
||||||
|
|
||||||
def test_describe_instances(self):
|
def test_describe_instances(self):
|
||||||
"""Test that, after creating a user and a project, the describe
|
"""Test that, after creating a user and a project, the describe
|
||||||
|
|||||||
Reference in New Issue
Block a user