blob: 620e293c45cadbd0ec0b2c8ed01d5a9f80d46622 [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
huangtianhua1b855bc2013-10-10 11:12:44 +080016from tempest.api.identity import base
17from tempest.common.utils import data_utils
18from tempest.test import attr
19
20
21class TokensTestJSON(base.BaseIdentityAdminTest):
22 _interface = 'json'
23
24 @attr(type='gate')
25 def test_create_delete_token(self):
26 # get a token by username and password
27 user_name = data_utils.rand_name(name='user-')
28 user_password = data_utils.rand_name(name='pass-')
29 # first:create a tenant
30 tenant_name = data_utils.rand_name(name='tenant-')
31 resp, tenant = self.client.create_tenant(tenant_name)
32 self.assertEqual(200, resp.status)
33 self.data.tenants.append(tenant)
34 # second:create a user
35 resp, user = self.client.create_user(user_name, user_password,
36 tenant['id'], '')
37 self.assertEqual(200, resp.status)
38 self.data.users.append(user)
39 # then get a token for the user
40 rsp, body = self.token_client.auth(user_name,
41 user_password,
42 tenant['name'])
huangtianhua1b855bc2013-10-10 11:12:44 +080043 self.assertEqual(rsp['status'], '200')
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000044 self.assertEqual(body['token']['tenant']['name'],
huangtianhua1b855bc2013-10-10 11:12:44 +080045 tenant['name'])
46 # then delete the token
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000047 token_id = body['token']['id']
huangtianhua1b855bc2013-10-10 11:12:44 +080048 resp, body = self.client.delete_token(token_id)
49 self.assertEqual(resp['status'], '204')
50
51
52class TokensTestXML(TokensTestJSON):
53 _interface = 'xml'