diff options
author | Yun Huang <yun.huang@windriver.com> | 2018-03-26 22:41:55 +0800 |
---|---|---|
committer | Yun Huang <yun.huang@windriver.com> | 2018-03-26 22:41:55 +0800 |
commit | 4a3fecf928fa8046d2fa139a0b754c4d6e819b84 (patch) | |
tree | acc2012923ef2fc3f76e72a6bb877834677b87de | |
parent | ce19f09adcb0de2eec3a97b81227e3f0cf49d76e (diff) |
Add UT for newton token v2 identity
Change-Id: I3846afa19aa619b3fc7e98bc31cb0e192a402f8f
Issue-ID: MULTICLOUD-203
Signed-off-by: Yun Huang <yun.huang@windriver.com>
-rw-r--r-- | newton/newton/proxy/tests/test_identity_proxy.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/newton/newton/proxy/tests/test_identity_proxy.py b/newton/newton/proxy/tests/test_identity_proxy.py index f61ba699..adece80b 100644 --- a/newton/newton/proxy/tests/test_identity_proxy.py +++ b/newton/newton/proxy/tests/test_identity_proxy.py @@ -514,3 +514,46 @@ 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(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/%s/v0/windriver-hudson-dc_RegionOne/identity/v2.0/" + "tokens" % test_base.MULTIVIM_VERSION, + 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'])
\ No newline at end of file |