Debian Codegraph @

keystoneclient/tests/unit/v2_0/test_services.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 import uuid
14
15 from keystoneclient.tests.unit.v2_0 import utils
16 from keystoneclient.v2_0 import services
17
18
19 class ServiceTests(utils.ClientTestCase):
20 def setUp(self):
21 super(ServiceTests, self).setUp()
22
23 self.NOVA_SERVICE_ID = uuid.uuid4().hex
24 self.KEYSTONE_SERVICE_ID = uuid.uuid4().hex
25
26 self.TEST_SERVICES = {
27 "OS-KSADM:services": {
28 "values": [
29 {
30 "name": "nova",
31 "type": "compute",
32 "description": "Nova-compatible service.",
33 "id": self.NOVA_SERVICE_ID
34 },
35 {
36 "name": "keystone",
37 "type": "identity",
38 "description": "Keystone-compatible service.",
39 "id": self.KEYSTONE_SERVICE_ID
40 },
41 ],
42 },
43 }
44
45 def test_create_with_description(self):
46 req_body = {
47 "OS-KSADM:service": {
48 "name": "swift",
49 "type": "object-store",
50 "description": "Swift-compatible service.",
51 }
52 }
53 service_id = uuid.uuid4().hex
54 resp_body = {
55 "OS-KSADM:service": {
56 "name": "swift",
57 "type": "object-store",
58 "description": "Swift-compatible service.",
59 "id": service_id,
60 }
61 }
62 self.stub_url('POST', ['OS-KSADM', 'services'], json=resp_body)
63
64 service = self.client.services.create(
65 req_body['OS-KSADM:service']['name'],
66 req_body['OS-KSADM:service']['type'],
67 req_body['OS-KSADM:service']['description'])
68 self.assertIsInstance(service, services.Service)
69 self.assertEqual(service.id, service_id)
70 self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
71 self.assertEqual(service.description,
72 req_body['OS-KSADM:service']['description'])
73 self.assertRequestBodyIs(json=req_body)
74
75 def test_create_without_description(self):
76 req_body = {
77 "OS-KSADM:service": {
78 "name": "swift",
79 "type": "object-store",
80 "description": None,
81 }
82 }
83 service_id = uuid.uuid4().hex
84 resp_body = {
85 "OS-KSADM:service": {
86 "name": "swift",
87 "type": "object-store",
88 "id": service_id,
89 "description": None,
90 }
91 }
92 self.stub_url('POST', ['OS-KSADM', 'services'], json=resp_body)
93
94 service = self.client.services.create(
95 req_body['OS-KSADM:service']['name'],
96 req_body['OS-KSADM:service']['type'],
97 req_body['OS-KSADM:service']['description'])
98 self.assertIsInstance(service, services.Service)
99 self.assertEqual(service.id, service_id)
100 self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
101 self.assertIsNone(service.description)
102 self.assertRequestBodyIs(json=req_body)
103
104 def test_delete(self):
105 self.stub_url('DELETE',
106 ['OS-KSADM', 'services', self.NOVA_SERVICE_ID],
107 status_code=204)
108
109 self.client.services.delete(self.NOVA_SERVICE_ID)
110
111 def test_get(self):
112 test_services = self.TEST_SERVICES['OS-KSADM:services']['values'][0]
113
114 self.stub_url('GET', ['OS-KSADM', 'services', self.NOVA_SERVICE_ID],
115 json={'OS-KSADM:service': test_services})
116
117 service = self.client.services.get(self.NOVA_SERVICE_ID)
118 self.assertIsInstance(service, services.Service)
119 self.assertEqual(service.id, self.NOVA_SERVICE_ID)
120 self.assertEqual(service.name, 'nova')
121 self.assertEqual(service.type, 'compute')
122
123 def test_list(self):
124 self.stub_url('GET', ['OS-KSADM', 'services'],
125 json=self.TEST_SERVICES)
126
127 service_list = self.client.services.list()
128 [self.assertIsInstance(r, services.Service)
129 for r in service_list]