
Add ASLv2 headers to files that were missing it. fixes bug #1211587 Change-Id: Iede918e1ce84993cee4ecbb2d9c2606627fa412e
163 lines
5.4 KiB
Python
163 lines
5.4 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import time
|
|
|
|
import mock
|
|
import mox
|
|
import requests
|
|
import testtools
|
|
|
|
from keystoneclient.v2_0 import client
|
|
|
|
|
|
class TestCase(testtools.TestCase):
|
|
TEST_DOMAIN_ID = '1'
|
|
TEST_DOMAIN_NAME = 'aDomain'
|
|
TEST_TENANT_ID = '1'
|
|
TEST_TENANT_NAME = 'aTenant'
|
|
TEST_TOKEN = 'aToken'
|
|
TEST_USER = 'test'
|
|
TEST_ROOT_URL = 'http://127.0.0.1:5000/'
|
|
TEST_URL = '%s%s' % (TEST_ROOT_URL, 'v2.0')
|
|
TEST_ROOT_ADMIN_URL = 'http://127.0.0.1:35357/'
|
|
TEST_ADMIN_URL = '%s%s' % (TEST_ROOT_ADMIN_URL, 'v2.0')
|
|
TEST_REQUEST_BASE = {
|
|
'verify': True,
|
|
}
|
|
|
|
TEST_SERVICE_CATALOG = [{
|
|
"endpoints": [{
|
|
"adminURL": "http://cdn.admin-nets.local:8774/v1.0",
|
|
"region": "RegionOne",
|
|
"internalURL": "http://127.0.0.1:8774/v1.0",
|
|
"publicURL": "http://cdn.admin-nets.local:8774/v1.0/"
|
|
}],
|
|
"type": "nova_compat",
|
|
"name": "nova_compat"
|
|
}, {
|
|
"endpoints": [{
|
|
"adminURL": "http://nova/novapi/admin",
|
|
"region": "RegionOne",
|
|
"internalURL": "http://nova/novapi/internal",
|
|
"publicURL": "http://nova/novapi/public"
|
|
}],
|
|
"type": "compute",
|
|
"name": "nova"
|
|
}, {
|
|
"endpoints": [{
|
|
"adminURL": "http://glance/glanceapi/admin",
|
|
"region": "RegionOne",
|
|
"internalURL": "http://glance/glanceapi/internal",
|
|
"publicURL": "http://glance/glanceapi/public"
|
|
}],
|
|
"type": "image",
|
|
"name": "glance"
|
|
}, {
|
|
"endpoints": [{
|
|
"adminURL": "http://127.0.0.1:35357/v2.0",
|
|
"region": "RegionOne",
|
|
"internalURL": "http://127.0.0.1:5000/v2.0",
|
|
"publicURL": "http://127.0.0.1:5000/v2.0"
|
|
}],
|
|
"type": "identity",
|
|
"name": "keystone"
|
|
}, {
|
|
"endpoints": [{
|
|
"adminURL": "http://swift/swiftapi/admin",
|
|
"region": "RegionOne",
|
|
"internalURL": "http://swift/swiftapi/internal",
|
|
"publicURL": "http://swift/swiftapi/public"
|
|
}],
|
|
"type": "object-store",
|
|
"name": "swift"
|
|
}]
|
|
|
|
def setUp(self):
|
|
super(TestCase, self).setUp()
|
|
self.mox = mox.Mox()
|
|
self.request_patcher = mock.patch.object(requests, 'request',
|
|
self.mox.CreateMockAnything())
|
|
self.time_patcher = mock.patch.object(time, 'time',
|
|
lambda: 1234)
|
|
self.request_patcher.start()
|
|
self.time_patcher.start()
|
|
self.client = client.Client(username=self.TEST_USER,
|
|
token=self.TEST_TOKEN,
|
|
tenant_name=self.TEST_TENANT_NAME,
|
|
auth_url=self.TEST_URL,
|
|
endpoint=self.TEST_URL)
|
|
|
|
def tearDown(self):
|
|
self.request_patcher.stop()
|
|
self.time_patcher.stop()
|
|
self.mox.UnsetStubs()
|
|
self.mox.VerifyAll()
|
|
super(TestCase, self).tearDown()
|
|
|
|
|
|
class UnauthenticatedTestCase(testtools.TestCase):
|
|
"""Class used as base for unauthenticated calls."""
|
|
TEST_ROOT_URL = 'http://127.0.0.1:5000/'
|
|
TEST_URL = '%s%s' % (TEST_ROOT_URL, 'v2.0')
|
|
TEST_ROOT_ADMIN_URL = 'http://127.0.0.1:35357/'
|
|
TEST_ADMIN_URL = '%s%s' % (TEST_ROOT_ADMIN_URL, 'v2.0')
|
|
TEST_REQUEST_BASE = {
|
|
'verify': True,
|
|
}
|
|
|
|
def setUp(self):
|
|
super(UnauthenticatedTestCase, self).setUp()
|
|
self.mox = mox.Mox()
|
|
self.request_patcher = mock.patch.object(requests, 'request',
|
|
self.mox.CreateMockAnything())
|
|
self.time_patcher = mock.patch.object(time, 'time',
|
|
lambda: 1234)
|
|
self.request_patcher.start()
|
|
self.time_patcher.start()
|
|
|
|
def tearDown(self):
|
|
self.request_patcher.stop()
|
|
self.time_patcher.stop()
|
|
self.mox.UnsetStubs()
|
|
self.mox.VerifyAll()
|
|
super(UnauthenticatedTestCase, self).tearDown()
|
|
|
|
|
|
class TestResponse(requests.Response):
|
|
"""Class used to wrap requests.Response and provide some
|
|
convenience to initialize with a dict.
|
|
"""
|
|
|
|
def __init__(self, data):
|
|
self._text = None
|
|
super(TestResponse, self).__init__()
|
|
if isinstance(data, dict):
|
|
self.status_code = data.get('status_code', None)
|
|
headers = data.get('headers')
|
|
if headers:
|
|
self.headers.update(headers)
|
|
# Fake the text attribute to streamline Response creation
|
|
# _content is defined by requests.Response
|
|
self._content = data.get('text', None)
|
|
else:
|
|
self.status_code = data
|
|
|
|
def __eq__(self, other):
|
|
return self.__dict__ == other.__dict__
|
|
|
|
@property
|
|
def text(self):
|
|
return self.content
|