8
from keystoneclient.v2_0 import client
11
class TestCase(testtools.TestCase):
13
TEST_DOMAIN_NAME = 'aDomain'
15
TEST_TENANT_NAME = 'aTenant'
18
TEST_ROOT_URL = 'http://127.0.0.1:5000/'
19
TEST_URL = '%s%s' % (TEST_ROOT_URL, 'v2.0')
20
TEST_ROOT_ADMIN_URL = 'http://127.0.0.1:35357/'
21
TEST_ADMIN_URL = '%s%s' % (TEST_ROOT_ADMIN_URL, 'v2.0')
26
TEST_SERVICE_CATALOG = [{
28
"adminURL": "http://cdn.admin-nets.local:8774/v1.0",
29
"region": "RegionOne",
30
"internalURL": "http://127.0.0.1:8774/v1.0",
31
"publicURL": "http://cdn.admin-nets.local:8774/v1.0/"
33
"type": "nova_compat",
37
"adminURL": "http://nova/novapi/admin",
38
"region": "RegionOne",
39
"internalURL": "http://nova/novapi/internal",
40
"publicURL": "http://nova/novapi/public"
46
"adminURL": "http://glance/glanceapi/admin",
47
"region": "RegionOne",
48
"internalURL": "http://glance/glanceapi/internal",
49
"publicURL": "http://glance/glanceapi/public"
55
"adminURL": "http://127.0.0.1:35357/v2.0",
56
"region": "RegionOne",
57
"internalURL": "http://127.0.0.1:5000/v2.0",
58
"publicURL": "http://127.0.0.1:5000/v2.0"
64
"adminURL": "http://swift/swiftapi/admin",
65
"region": "RegionOne",
66
"internalURL": "http://swift/swiftapi/internal",
67
"publicURL": "http://swift/swiftapi/public"
69
"type": "object-store",
74
super(TestCase, self).setUp()
76
self.request_patcher = mock.patch.object(requests, 'request',
77
self.mox.CreateMockAnything())
78
self.time_patcher = mock.patch.object(time, 'time',
80
self.request_patcher.start()
81
self.time_patcher.start()
82
self.client = client.Client(username=self.TEST_USER,
83
token=self.TEST_TOKEN,
84
tenant_name=self.TEST_TENANT_NAME,
85
auth_url=self.TEST_URL,
86
endpoint=self.TEST_URL)
89
self.request_patcher.stop()
90
self.time_patcher.stop()
93
super(TestCase, self).tearDown()
96
class UnauthenticatedTestCase(testtools.TestCase):
97
"""Class used as base for unauthenticated calls."""
98
TEST_ROOT_URL = 'http://127.0.0.1:5000/'
99
TEST_URL = '%s%s' % (TEST_ROOT_URL, 'v2.0')
100
TEST_ROOT_ADMIN_URL = 'http://127.0.0.1:35357/'
101
TEST_ADMIN_URL = '%s%s' % (TEST_ROOT_ADMIN_URL, 'v2.0')
102
TEST_REQUEST_BASE = {
107
super(UnauthenticatedTestCase, self).setUp()
109
self.request_patcher = mock.patch.object(requests, 'request',
110
self.mox.CreateMockAnything())
111
self.time_patcher = mock.patch.object(time, 'time',
113
self.request_patcher.start()
114
self.time_patcher.start()
117
self.request_patcher.stop()
118
self.time_patcher.stop()
119
self.mox.UnsetStubs()
121
super(UnauthenticatedTestCase, self).tearDown()
124
class TestResponse(requests.Response):
125
"""Class used to wrap requests.Response and provide some
126
convenience to initialize with a dict.
129
def __init__(self, data):
131
super(TestResponse, self).__init__()
132
if isinstance(data, dict):
133
self.status_code = data.get('status_code', None)
134
headers = data.get('headers')
136
self.headers.update(headers)
137
# Fake the text attribute to streamline Response creation
138
# _content is defined by requests.Response
139
self._content = data.get('text', None)
141
self.status_code = data
143
def __eq__(self, other):
144
return self.__dict__ == other.__dict__