From ce8e69f4aa4996d5f650a81fe26251f9fe44992b Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Tue, 27 Mar 2018 17:26:35 +0800 Subject: Add TC UT for token test with project id Change-Id: I43fb8c8f5ae3dbfc6e6435dafb0ad02103ea36f2 Issue-ID: MULTICLOUD-203 Signed-off-by: Yun Huang --- .../proxy/tests/test_identity_proxy.py | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'windriver/titanium_cloud/proxy') diff --git a/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py b/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py index cb4d6d79..81231220 100644 --- a/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py +++ b/windriver/titanium_cloud/proxy/tests/test_identity_proxy.py @@ -685,3 +685,59 @@ 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/multicloud-titanium_cloud/v0/windriver-hudson-dc_RegionOne/identity/v3/auth/tokens", + 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']) + -- cgit 1.2.3-korg