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