blob: cfe17fba3baa8c146309a59a9b9c2401ebbb5682 [file] [log] [blame]
huangtianhua1b855bc2013-10-10 11:12:44 +08001# Copyright 2013 Huawei Technologies Co.,LTD.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import json
17
18from tempest.api.identity import base
19from tempest.common.utils import data_utils
20from tempest.test import attr
21
22
23class TokensTestJSON(base.BaseIdentityAdminTest):
24 _interface = 'json'
25
26 @attr(type='gate')
27 def test_create_delete_token(self):
28 # get a token by username and password
29 user_name = data_utils.rand_name(name='user-')
30 user_password = data_utils.rand_name(name='pass-')
31 # first:create a tenant
32 tenant_name = data_utils.rand_name(name='tenant-')
33 resp, tenant = self.client.create_tenant(tenant_name)
34 self.assertEqual(200, resp.status)
35 self.data.tenants.append(tenant)
36 # second:create a user
37 resp, user = self.client.create_user(user_name, user_password,
38 tenant['id'], '')
39 self.assertEqual(200, resp.status)
40 self.data.users.append(user)
41 # then get a token for the user
42 rsp, body = self.token_client.auth(user_name,
43 user_password,
44 tenant['name'])
45 access_data = json.loads(body)['access']
46 self.assertEqual(rsp['status'], '200')
47 self.assertEqual(access_data['token']['tenant']['name'],
48 tenant['name'])
49 # then delete the token
50 token_id = access_data['token']['id']
51 resp, body = self.client.delete_token(token_id)
52 self.assertEqual(resp['status'], '204')
53
54
55class TokensTestXML(TokensTestJSON):
56 _interface = 'xml'