blob: a35a87cc9ba3ef470a2a0ce00aafe5436f23b489 [file] [log] [blame]
Marc Kodererdb19acd2015-09-03 16:03:58 +02001# 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
15import httplib2
16
17from oslo_serialization import jsonutils as json
18from oslotest import mockpatch
19
20from tempest.tests import base
21
22
23class BaseComputeServiceTest(base.TestCase):
24 def create_response(self, body, to_utf=False, status=200):
Anusha Raminenic254c7a2015-09-07 15:32:23 +053025 json_body = {}
26 if body:
27 json_body = json.dumps(body)
28 if to_utf:
29 json_body = json_body.encode('utf-8')
Marc Kodererdb19acd2015-09-03 16:03:58 +020030 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)