Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 1 | # Copyright 2015 Deutsche Telekom AG. 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.tests import base |
| 21 | |
| 22 | |
| 23 | class BaseComputeServiceTest(base.TestCase): |
| 24 | def create_response(self, body, to_utf=False, status=200): |
Anusha Ramineni | c254c7a | 2015-09-07 15:32:23 +0530 | [diff] [blame] | 25 | json_body = {} |
| 26 | if body: |
| 27 | json_body = json.dumps(body) |
| 28 | if to_utf: |
| 29 | json_body = json_body.encode('utf-8') |
Marc Koderer | db19acd | 2015-09-03 16:03:58 +0200 | [diff] [blame] | 30 | response = (httplib2.Response({'status': status}), json_body) |
| 31 | return response |
| 32 | |
| 33 | def check_service_client_function(self, function, function2mock, |
| 34 | body, to_utf=False, status=200, |
| 35 | **kwargs): |
| 36 | mocked_response = self.create_response(body, to_utf, status) |
| 37 | self.useFixture(mockpatch.Patch( |
| 38 | function2mock, return_value=mocked_response)) |
| 39 | if kwargs: |
| 40 | resp = function(**kwargs) |
| 41 | else: |
| 42 | resp = function() |
| 43 | self.assertEqual(body, resp) |