Debian Codegraph @

heatclient/tests/unit/test_service.py

raw symbols SCIP
1 # Copyright 2012 OpenStack Foundation
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
16 import testtools
17
18 from heatclient import exc
19 from heatclient.v1 import services
20
21
22 class ManageServiceTest(testtools.TestCase):
23 def setUp(self):
24 super().setUp()
25
26 def test_service_list(self):
27 class FakeResponse:
28 def json(self):
29 return {'services': []}
30
31 class FakeClient:
32 def get(self, *args, **kwargs):
33 assert args[0] == ('/services')
34 return FakeResponse()
35
36 manager = services.ServiceManager(FakeClient())
37 self.assertEqual([], manager.list())
38
39 def test_service_list_403(self):
40 class FakeClient403:
41
42 def get(self, *args, **kwargs):
43 assert args[0] == ('/services')
44 raise exc.HTTPForbidden()
45
46 manager = services.ServiceManager(FakeClient403())
47 self.assertRaises(exc.HTTPForbidden,
48 manager.list)
49
50 def test_service_list_503(self):
51 class FakeClient503:
52 def get(self, *args, **kwargs):
53 assert args[0] == ('/services')
54 raise exc.HTTPServiceUnavailable()
55
56 manager = services.ServiceManager(FakeClient503())
57 self.assertRaises(exc.HTTPServiceUnavailable,
58 manager.list)