Debian Codegraph @

keystoneclient/tests/unit/v2_0/test_discovery.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
14 from keystoneclient.generic import client
15 from keystoneclient.tests.unit.v2_0 import utils
16
17
18 class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
19 def setUp(self):
20 super(DiscoverKeystoneTests, self).setUp()
21 self.TEST_RESPONSE_DICT = {
22 "versions": {
23 "values": [{
24 "id": "v2.0",
25 "status": "beta",
26 "updated": "2011-11-19T00:00:00Z",
27 "links": [
28 {"rel": "self",
29 "href": "http://127.0.0.1:5000/v2.0/", },
30 {"rel": "describedby",
31 "type": "text/html",
32 "href": "https://docs.openstack.org/api/"
33 "openstack-identity-service/2.0/content/", },
34 {"rel": "describedby",
35 "type": "application/pdf",
36 "href": "https://docs.openstack.org/api/"
37 "openstack-identity-service/2.0/"
38 "identity-dev-guide-2.0.pdf", },
39 {"rel": "describedby",
40 "type": "application/vnd.sun.wadl+xml",
41 "href": "http://127.0.0.1:5000/v2.0/identity.wadl", }
42 ],
43 "media-types": [{
44 "base": "application/xml",
45 "type": "application/vnd.openstack.identity-v2.0+xml",
46 }, {
47 "base": "application/json",
48 "type": "application/vnd.openstack.identity-v2.0+json",
49 }],
50 }],
51 },
52 }
53
54 def test_get_versions(self):
55 self.stub_url('GET', base_url=self.TEST_ROOT_URL,
56 json=self.TEST_RESPONSE_DICT)
57
58 # Creating a HTTPClient not using session is deprecated.
59 with self.deprecations.expect_deprecations_here():
60 cs = client.Client()
61 versions = cs.discover(self.TEST_ROOT_URL)
62 self.assertIsInstance(versions, dict)
63 self.assertIn('message', versions)
64 self.assertIn('v2.0', versions)
65 self.assertEqual(
66 versions['v2.0']['url'],
67 self.TEST_RESPONSE_DICT['versions']['values'][0]['links'][0]
68 ['href'])
69
70 def test_get_version_local(self):
71 self.stub_url('GET', base_url="http://localhost:35357/",
72 json=self.TEST_RESPONSE_DICT)
73
74 # Creating a HTTPClient not using session is deprecated.
75 with self.deprecations.expect_deprecations_here():
76 cs = client.Client()
77 versions = cs.discover()
78 self.assertIsInstance(versions, dict)
79 self.assertIn('message', versions)
80 self.assertIn('v2.0', versions)
81 self.assertEqual(
82 versions['v2.0']['url'],
83 self.TEST_RESPONSE_DICT['versions']['values'][0]['links'][0]
84 ['href'])