Debian Codegraph @

keystoneclient/tests/unit/auth/test_token_endpoint.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from testtools import matchers
14
15 from keystoneclient.auth import token_endpoint
16 from keystoneclient import session
17 from keystoneclient.tests.unit import utils
18
19
20 class TokenEndpointTest(utils.TestCase):
21
22 TEST_TOKEN = 'aToken'
23 TEST_URL = 'http://server/prefix'
24
25 def setUp(self):
26 super(TokenEndpointTest, self).setUp()
27 self.deprecations.expect_deprecations()
28
29 def test_basic_case(self):
30 self.requests_mock.get(self.TEST_URL, text='body')
31
32 a = token_endpoint.Token(self.TEST_URL, self.TEST_TOKEN)
33 s = session.Session(auth=a)
34
35 data = s.get(self.TEST_URL, authenticated=True)
36
37 self.assertEqual(data.text, 'body')
38 self.assertRequestHeaderEqual('X-Auth-Token', self.TEST_TOKEN)
39
40 def test_basic_endpoint_case(self):
41 self.stub_url('GET', ['p'], text='body')
42 a = token_endpoint.Token(self.TEST_URL, self.TEST_TOKEN)
43 s = session.Session(auth=a)
44
45 data = s.get('/p',
46 authenticated=True,
47 endpoint_filter={'service': 'identity'})
48
49 self.assertEqual(self.TEST_URL, a.get_endpoint(s))
50 self.assertEqual('body', data.text)
51 self.assertRequestHeaderEqual('X-Auth-Token', self.TEST_TOKEN)
52
53 def test_token_endpoint_options(self):
54 opt_names = [opt.name for opt in token_endpoint.Token.get_options()]
55
56 self.assertThat(opt_names, matchers.HasLength(2))
57
58 self.assertIn('token', opt_names)
59 self.assertIn('endpoint', opt_names)
60
61 def test_token_endpoint_user_id(self):
62 a = token_endpoint.Token(self.TEST_URL, self.TEST_TOKEN)
63 s = session.Session()
64
65 # we can't know this information about this sort of plugin
66 self.assertIsNone(a.get_user_id(s))
67 self.assertIsNone(a.get_project_id(s))