Debian Codegraph @

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