Kenji Yasui | 0d649b2 | 2015-07-21 11:26:56 +0000 | [diff] [blame] | 1 | # 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 | |
| 15 | import httplib2 |
| 16 | |
| 17 | from oslo_serialization import jsonutils as json |
| 18 | from oslotest import mockpatch |
| 19 | |
| 20 | from tempest.services.compute.json import extensions_client |
| 21 | from tempest.tests import base |
| 22 | from tempest.tests import fake_auth_provider |
| 23 | |
| 24 | |
| 25 | class 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') |
ghanshyam | f1f0e19 | 2015-08-04 15:56:29 +0900 | [diff] [blame] | 37 | expected = {"extensions": []} |
Kenji Yasui | 0d649b2 | 2015-07-21 11:26:56 +0000 | [diff] [blame] | 38 | 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): |
ghanshyam | f1f0e19 | 2015-08-04 15:56:29 +0900 | [diff] [blame] | 51 | expected = {"extension": { |
Kenji Yasui | 0d649b2 | 2015-07-21 11:26:56 +0000 | [diff] [blame] | 52 | "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' |
ghanshyam | f1f0e19 | 2015-08-04 15:56:29 +0900 | [diff] [blame] | 59 | }} |
| 60 | serialized_body = json.dumps(expected) |
Kenji Yasui | 0d649b2 | 2015-07-21 11:26:56 +0000 | [diff] [blame] | 61 | 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) |