summaryrefslogtreecommitdiffstats
path: root/windriver/titanium_cloud/proxy
diff options
context:
space:
mode:
authorYun Huang <yun.huang@windriver.com>2018-03-26 23:18:11 +0800
committerYun Huang <yun.huang@windriver.com>2018-03-26 23:18:11 +0800
commitec35e070f380d2188fca9305f1bbe3375ae6cd6f (patch)
tree62b1a0cc6436fa3e9caf426cd83902ecc89ddbcc /windriver/titanium_cloud/proxy
parent045b5f84b7483f2ed7e97a821e70c26231101239 (diff)
Add UT for titanium cloud token v2 identity
Change-Id: I653bd2cdad59115928005c616c26a78ad6a215ee Issue-ID: MULTICLOUD-203 Signed-off-by: Yun Huang <yun.huang@windriver.com>
Diffstat (limited to 'windriver/titanium_cloud/proxy')
-rw-r--r--windriver/titanium_cloud/proxy/tests/test_identity_proxy.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py b/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py
index 5dc061fa..cd7dd23c 100644
--- a/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py
+++ b/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py
@@ -25,6 +25,7 @@ from keystoneauth1.exceptions import HttpError
from newton_base.util import VimDriverUtils
from titanium_cloud.proxy.views.identityV3 import Tokens
+from newton_base.tests import mock_info
mock_viminfo = {
"createTime": "2017-04-01 02:22:27",
@@ -532,3 +533,44 @@ class TestIdentityService(unittest.TestCase):
self.assertTrue(response['X-Subject-Token'] == mock_token_id)
self.assertTrue(context['token']['catalog'] != None)
+
+ @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(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
+ data = {}
+ response = self.client.post(
+ "/api/multicloud-titanium_cloud/v0/windriver-hudson-dc_RegionOne/identity/v2.0/tokens",
+ data=data, format='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'])