5
import unittest2 as unittest
7
7
from keystoneclient.v2_0 import client
10
class TestCase(unittest.TestCase):
10
class TestCase(testtools.TestCase):
11
11
TEST_TENANT_ID = '1'
12
12
TEST_TENANT_NAME = 'aTenant'
13
13
TEST_TOKEN = 'aToken'
16
16
TEST_URL = '%s%s' % (TEST_ROOT_URL, 'v2.0')
17
17
TEST_ROOT_ADMIN_URL = 'http://127.0.0.1:35357/'
18
18
TEST_ADMIN_URL = '%s%s' % (TEST_ROOT_ADMIN_URL, 'v2.0')
20
'config': {'danger_mode': False},
20
24
TEST_SERVICE_CATALOG = [{
69
73
self.mox = mox.Mox()
70
74
self._original_time = time.time
71
75
time.time = lambda: 1234
72
httplib2.Http.request = self.mox.CreateMockAnything()
76
requests.request = self.mox.CreateMockAnything()
73
77
self.client = client.Client(username=self.TEST_USER,
74
78
token=self.TEST_TOKEN,
75
79
tenant_name=self.TEST_TENANT_NAME,
79
83
def tearDown(self):
80
84
time.time = self._original_time
81
87
super(TestCase, self).tearDown()
86
class UnauthenticatedTestCase(unittest.TestCase):
90
class UnauthenticatedTestCase(testtools.TestCase):
87
91
""" Class used as base for unauthenticated calls """
88
92
TEST_ROOT_URL = 'http://127.0.0.1:5000/'
89
93
TEST_URL = '%s%s' % (TEST_ROOT_URL, 'v2.0')
90
94
TEST_ROOT_ADMIN_URL = 'http://127.0.0.1:35357/'
91
95
TEST_ADMIN_URL = '%s%s' % (TEST_ROOT_ADMIN_URL, 'v2.0')
97
'config': {'danger_mode': False},
94
102
super(UnauthenticatedTestCase, self).setUp()
95
103
self.mox = mox.Mox()
96
104
self._original_time = time.time
97
105
time.time = lambda: 1234
98
httplib2.Http.request = self.mox.CreateMockAnything()
106
requests.request = self.mox.CreateMockAnything()
100
108
def tearDown(self):
101
109
time.time = self._original_time
110
self.mox.UnsetStubs()
102
112
super(UnauthenticatedTestCase, self).tearDown()
103
self.mox.UnsetStubs()
115
class TestResponse(requests.Response):
116
""" Class used to wrap requests.Response and provide some
117
convenience to initialize with a dict """
119
def __init__(self, data):
121
super(TestResponse, self)
122
if isinstance(data, dict):
123
self.status_code = data.get('status_code', None)
124
self.headers = data.get('headers', None)
125
# Fake the text attribute to streamline Response creation
126
self._text = data.get('text', None)
128
self.status_code = data
130
def __eq__(self, other):
131
return self.__dict__ == other.__dict__