summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYun Huang <yun.huang@windriver.com>2018-03-27 16:52:58 +0800
committerYun Huang <yun.huang@windriver.com>2018-03-27 16:52:58 +0800
commit7a1fb391f3c04900a8f3c93fd821e19c338106d7 (patch)
treeba00e116274a7efa98f2ad71608cebfd41717db4
parentd9f30f113d6972d7a4afcf7796bf2cae54de151f (diff)
Add ocata UT for v2.0 token API with tenant name
Change-Id: I0c82642b23cda80ab3b723c58efd14a4d8867590 Issue-ID: MULTICLOUD-203 Signed-off-by: Yun Huang <yun.huang@windriver.com>
-rw-r--r--ocata/ocata/proxy/tests/test_identity_proxy.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/ocata/ocata/proxy/tests/test_identity_proxy.py b/ocata/ocata/proxy/tests/test_identity_proxy.py
index 759556a1..0b0db059 100644
--- a/ocata/ocata/proxy/tests/test_identity_proxy.py
+++ b/ocata/ocata/proxy/tests/test_identity_proxy.py
@@ -634,3 +634,54 @@ class TestIdentityService(unittest.TestCase):
self.assertEqual(mock_info.MOCK_TOKEN_ID,
response['X-Subject-Token'])
self.assertIsNotNone(context['token']['catalog'])
+
+ @mock.patch.object(VimDriverUtils, 'get_vim_info')
+ @mock.patch.object(VimDriverUtils, 'get_session')
+ @mock.patch.object(VimDriverUtils, 'get_auth_state')
+ @mock.patch.object(VimDriverUtils, 'update_token_cache')
+ def test_tokensV2_with_tenantname(self, mock_update_token_cache, mock_get_auth_state,
+ mock_get_session, mock_get_vim_info):
+ '''
+ test API: get token
+ :param mock_update_token_cache:
+ :param mock_get_auth_state:
+ :param mock_get_session:
+ :param mock_get_vim_info:
+ :return:
+ '''
+
+ # mock VimDriverUtils APIs
+ mock_session_specs = ["get"]
+ mock_session_get_response = {'status': 200}
+ mock_session = mock.Mock(name='mock_session',
+ spec=mock_session_specs)
+ mock_session.get.return_value = mock_session_get_response
+
+ mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
+ mock_get_session.return_value = mock_session
+ mock_get_auth_state.return_value = json.dumps(mock_auth_state)
+ mock_update_token_cache.return_value = mock_info.MOCK_TOKEN_ID
+
+ # simulate client to make the request
+ token_data = {
+ "auth": {
+ "tenantName": "Integration",
+ "passwordCredentials": {
+ "username": "demo",
+ "password": "demo"
+ }
+ }
+ }
+
+ response = self.client.post(
+ "/api/multicloud-ocata/v0/windriver-hudson-dc_RegionOne/identity/v2.0/tokens",
+ data=json.dumps(token_data), content_type='application/json')
+ self.failUnlessEqual(status.HTTP_200_OK,
+ response.status_code)
+ context = response.json()
+
+ self.assertIsNotNone(context['access']['token'])
+ self.assertEqual(mock_info.MOCK_TOKEN_ID,
+ context['access']['token']["id"])
+ self.assertIsNotNone(context['access']['serviceCatalog'])
+