blob: 20a5b7bbb4c003518ef043dcd1377ceec51c054c [file] [log] [blame]
Kenji Yasui0d649b22015-07-21 11:26:56 +00001# Copyright 2015 NEC Corporation. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import httplib2
16
17from oslo_serialization import jsonutils as json
18from oslotest import mockpatch
19
20from tempest.services.compute.json import extensions_client
21from tempest.tests import base
22from tempest.tests import fake_auth_provider
23
24
25class TestExtensionsClient(base.TestCase):
26
27 def setUp(self):
28 super(TestExtensionsClient, self).setUp()
29 fake_auth = fake_auth_provider.FakeAuthProvider()
30 self.client = extensions_client.ExtensionsClient(
31 fake_auth, 'compute', 'regionOne')
32
33 def _test_list_extensions(self, bytes_body=False):
34 body = '{"extensions": []}'
35 if bytes_body:
36 body = body.encode('utf-8')
ghanshyamf1f0e192015-08-04 15:56:29 +090037 expected = {"extensions": []}
Kenji Yasui0d649b22015-07-21 11:26:56 +000038 response = (httplib2.Response({'status': 200}), body)
39 self.useFixture(mockpatch.Patch(
40 'tempest.common.service_client.ServiceClient.get',
41 return_value=response))
42 self.assertEqual(expected, self.client.list_extensions())
43
44 def test_list_extensions_with_str_body(self):
45 self._test_list_extensions()
46
47 def test_list_extensions_with_bytes_body(self):
48 self._test_list_extensions(bytes_body=True)
49
50 def _test_show_extension(self, bytes_body=False):
ghanshyamf1f0e192015-08-04 15:56:29 +090051 expected = {"extension": {
Kenji Yasui0d649b22015-07-21 11:26:56 +000052 "updated": "2011-06-09T00:00:00Z",
53 "name": "Multinic",
54 "links": [],
55 "namespace":
56 "http://docs.openstack.org/compute/ext/multinic/api/v1.1",
57 "alias": "NMN",
58 "description": u'\u2740(*\xb4\u25e1`*)\u2740'
ghanshyamf1f0e192015-08-04 15:56:29 +090059 }}
60 serialized_body = json.dumps(expected)
Kenji Yasui0d649b22015-07-21 11:26:56 +000061 if bytes_body:
62 serialized_body = serialized_body.encode('utf-8')
63
64 mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
65 self.useFixture(mockpatch.Patch(
66 'tempest.common.service_client.ServiceClient.get',
67 return_value=mocked_resp))
68 resp = self.client.show_extension("NMN")
69 self.assertEqual(expected, resp)
70
71 def test_show_extension_with_str_body(self):
72 self._test_show_extension()
73
74 def test_show_extension_with_bytes_body(self):
75 self._test_show_extension(bytes_body=True)