diff options
author | Yun Huang <yun.huang@windriver.com> | 2018-03-27 17:19:35 +0800 |
---|---|---|
committer | Yun Huang <yun.huang@windriver.com> | 2018-03-27 17:19:35 +0800 |
commit | 4c866a246727f1911320ef9f66252a0a8faa6998 (patch) | |
tree | 6fb2d72fa94f96db1e340203e5453737fd92b445 /newton | |
parent | e3ac33a32b29a25cc55458f2ccdf8b787cc34db1 (diff) |
Add newton UT for token test with project id
Change-Id: If55ebc5cfe951c496373fa78f52dd8aac77c0eff
Issue-ID: MULTICLOUD-203
Signed-off-by: Yun Huang <yun.huang@windriver.com>
Diffstat (limited to 'newton')
-rw-r--r-- | newton/newton/proxy/tests/test_identity_proxy.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/newton/newton/proxy/tests/test_identity_proxy.py b/newton/newton/proxy/tests/test_identity_proxy.py index 68d2f033..b9b256dc 100644 --- a/newton/newton/proxy/tests/test_identity_proxy.py +++ b/newton/newton/proxy/tests/test_identity_proxy.py @@ -671,3 +671,61 @@ class TestIdentityService(unittest.TestCase): context['access']['token']["id"]) self.assertIsNotNone(context['access']['serviceCatalog']) + @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_token_with_projectid(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": { + "identity": { + "methods": ["password"], + "password": { + "user": { + "name": "demo", + "password": "demo" + } + } + }, + "scope": { + "project": {"id": "dd327af0542e47d7853e0470fe9ad625"} + } + } + } + + response = self.client.post( + "/api/%s/v0/windriver-hudson-dc_RegionOne/identity/v3/" + "auth/tokens" % test_base.MULTIVIM_VERSION, + data=json.dumps(token_data), content_type='application/json') + self.failUnlessEqual(status.HTTP_201_CREATED, + response.status_code) + context = response.json() + + self.assertEqual(mock_info.MOCK_TOKEN_ID, + response['X-Subject-Token']) + self.assertIsNotNone(context['token']['catalog']) + + |