Merge "Deduplicate client unit tests"
diff --git a/tempest/tests/services/compute/base.py b/tempest/tests/services/compute/base.py
new file mode 100644
index 0000000..379d513
--- /dev/null
+++ b/tempest/tests/services/compute/base.py
@@ -0,0 +1,41 @@
+# Copyright 2015 Deutsche Telekom AG.  All rights reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import httplib2
+
+from oslo_serialization import jsonutils as json
+from oslotest import mockpatch
+
+from tempest.tests import base
+
+
+class BaseComputeServiceTest(base.TestCase):
+    def create_response(self, body, to_utf=False, status=200):
+        json_body = json.dumps(body)
+        if to_utf:
+            json_body = json_body.encode('utf-8')
+        response = (httplib2.Response({'status': status}), json_body)
+        return response
+
+    def check_service_client_function(self, function, function2mock,
+                                      body, to_utf=False, status=200,
+                                      **kwargs):
+        mocked_response = self.create_response(body, to_utf, status)
+        self.useFixture(mockpatch.Patch(
+            function2mock, return_value=mocked_response))
+        if kwargs:
+            resp = function(**kwargs)
+        else:
+            resp = function()
+        self.assertEqual(body, resp)
diff --git a/tempest/tests/services/compute/test_agents_client.py b/tempest/tests/services/compute/test_agents_client.py
index d14d8bf..a8d4c87 100644
--- a/tempest/tests/services/compute/test_agents_client.py
+++ b/tempest/tests/services/compute/test_agents_client.py
@@ -14,15 +14,39 @@
 
 import httplib2
 
-from oslo_serialization import jsonutils as json
 from oslotest import mockpatch
 
 from tempest.services.compute.json import agents_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestAgentsClient(base.TestCase):
+class TestAgentsClient(base.BaseComputeServiceTest):
+    FAKE_CREATE_AGENT = {
+        "agent":
+        {
+            "url": "http://foo.com",
+            "hypervisor": "kvm",
+            "md5hash": "md5",
+            "version": "2",
+            "architecture": "x86_64",
+            "os": "linux",
+            "agent_id": 1
+        }
+    }
+
+    FAKE_UPDATE_AGENT = {
+        "agent":
+        {
+            "url": "http://foo.com",
+            "hypervisor": "kvm",
+            "md5hash": "md5",
+            "version": "2",
+            "architecture": "x86_64",
+            "os": "linux",
+            "agent_id": 1
+        }
+    }
 
     def setUp(self):
         super(TestAgentsClient, self).setUp()
@@ -31,34 +55,20 @@
                                                  'compute', 'regionOne')
 
     def _test_list_agents(self, bytes_body=False):
-        body = '{"agents": []}'
-        if bytes_body:
-            body = body.encode('utf-8')
-        expected = {"agents": []}
-        response = (httplib2.Response({'status': 200}), body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.list_agents,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=response))
-        self.assertEqual(expected, self.client.list_agents())
+            {"agents": []},
+            bytes_body)
 
     def _test_create_agent(self, bytes_body=False):
-        expected = {"agent": {"url": "http://foo.com", "hypervisor": "kvm",
-                              "md5hash": "md5", "version": "2",
-                              "architecture": "x86_64",
-                              "os": "linux", "agent_id": 1}}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.create_agent,
             'tempest.common.service_client.ServiceClient.post',
-            return_value=mocked_resp))
-        resp = self.client.create_agent(
+            self.FAKE_CREATE_AGENT,
+            bytes_body,
             url="http://foo.com", hypervisor="kvm", md5hash="md5",
-            version="2", architecture="x86_64", os="linux"
-        )
-        self.assertEqual(expected, resp)
+            version="2", architecture="x86_64", os="linux")
 
     def _test_delete_agent(self):
         mocked_resp = (httplib2.Response({'status': 200}), None)
@@ -68,20 +78,12 @@
         self.client.delete_agent("1")
 
     def _test_update_agent(self, bytes_body=False):
-        expected = {"agent": {"url": "http://foo.com", "md5hash": "md5",
-                              "version": "2", "agent_id": 1}}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.update_agent,
             'tempest.common.service_client.ServiceClient.put',
-            return_value=mocked_resp))
-        resp = self.client.update_agent(
-            "1", url="http://foo.com", md5hash="md5", version="2"
-        )
-        self.assertEqual(expected, resp)
+            self.FAKE_UPDATE_AGENT,
+            bytes_body,
+            agent_id="1", url="http://foo.com", md5hash="md5", version="2")
 
     def test_list_agents_with_str_body(self):
         self._test_list_agents()
diff --git a/tempest/tests/services/compute/test_aggregates_client.py b/tempest/tests/services/compute/test_aggregates_client.py
index 14930a7..83514e5 100644
--- a/tempest/tests/services/compute/test_aggregates_client.py
+++ b/tempest/tests/services/compute/test_aggregates_client.py
@@ -14,15 +14,57 @@
 
 import httplib2
 
-from oslo_serialization import jsonutils as json
 from oslotest import mockpatch
 
 from tempest.services.compute.json import aggregates_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestAggregatesClient(base.TestCase):
+class TestAggregatesClient(base.BaseComputeServiceTest):
+    FAKE_SHOW_AGGREGATE = {
+        "aggregate":
+        {
+            "name": "hoge",
+            "availability_zone": None,
+            "deleted": False,
+            "created_at":
+            "2015-07-16T03:07:32.000000",
+            "updated_at": None,
+            "hosts": [],
+            "deleted_at": None,
+            "id": 1,
+            "metadata": {}
+        }
+    }
+
+    FAKE_CREATE_AGGREGATE = {
+        "aggregate":
+        {
+            "name": u'\xf4',
+            "availability_zone": None,
+            "deleted": False,
+            "created_at": "2015-07-21T04:11:18.000000",
+            "updated_at": None,
+            "deleted_at": None,
+            "id": 1
+        }
+    }
+
+    FAKE_UPDATE_AGGREGATE = {
+        "aggregate":
+        {
+            "name": u'\xe9',
+            "availability_zone": None,
+            "deleted": False,
+            "created_at": "2015-07-16T03:07:32.000000",
+            "updated_at": "2015-07-23T05:16:29.000000",
+            "hosts": [],
+            "deleted_at": None,
+            "id": 1,
+            "metadata": {}
+        }
+    }
 
     def setUp(self):
         super(TestAggregatesClient, self).setUp()
@@ -31,15 +73,11 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_list_aggregates(self, bytes_body=False):
-        body = '{"aggregates": []}'
-        if bytes_body:
-            body = body.encode('utf-8')
-        expected = {"aggregates": []}
-        response = (httplib2.Response({'status': 200}), body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.list_aggregates,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=response))
-        self.assertEqual(expected, self.client.list_aggregates())
+            {"aggregates": []},
+            bytes_body)
 
     def test_list_aggregates_with_str_body(self):
         self._test_list_aggregates()
@@ -48,26 +86,12 @@
         self._test_list_aggregates(bytes_body=True)
 
     def _test_show_aggregate(self, bytes_body=False):
-        expected = {"aggregate": {"name": "hoge",
-                                  "availability_zone": None,
-                                  "deleted": False,
-                                  "created_at":
-                                  "2015-07-16T03:07:32.000000",
-                                  "updated_at": None,
-                                  "hosts": [],
-                                  "deleted_at": None,
-                                  "id": 1,
-                                  "metadata": {}}}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.show_aggregate,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_aggregate(1)
-        self.assertEqual(expected, resp)
+            self.FAKE_SHOW_AGGREGATE,
+            bytes_body,
+            aggregate_id=1)
 
     def test_show_aggregate_with_str_body(self):
         self._test_show_aggregate()
@@ -76,23 +100,12 @@
         self._test_show_aggregate(bytes_body=True)
 
     def _test_create_aggregate(self, bytes_body=False):
-        expected = {"aggregate": {"name": u'\xf4',
-                                  "availability_zone": None,
-                                  "deleted": False,
-                                  "created_at": "2015-07-21T04:11:18.000000",
-                                  "updated_at": None,
-                                  "deleted_at": None,
-                                  "id": 1}}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.create_aggregate,
             'tempest.common.service_client.ServiceClient.post',
-            return_value=mocked_resp))
-        resp = self.client.create_aggregate(name='hoge')
-        self.assertEqual(expected, resp)
+            self.FAKE_CREATE_AGGREGATE,
+            bytes_body,
+            name='hoge')
 
     def test_create_aggregate_with_str_body(self):
         self._test_create_aggregate()
@@ -101,34 +114,20 @@
         self._test_create_aggregate(bytes_body=True)
 
     def test_delete_aggregate(self):
-        expected = {}
         mocked_resp = (httplib2.Response({'status': 200}), None)
         self.useFixture(mockpatch.Patch(
             'tempest.common.service_client.ServiceClient.delete',
             return_value=mocked_resp))
         resp = self.client.delete_aggregate("1")
-        self.assertEqual(expected, resp)
+        self.assertEqual({}, resp)
 
     def _test_update_aggregate(self, bytes_body=False):
-        expected = {"aggregate": {"name": u'\xe9',
-                                  "availability_zone": None,
-                                  "deleted": False,
-                                  "created_at": "2015-07-16T03:07:32.000000",
-                                  "updated_at": "2015-07-23T05:16:29.000000",
-                                  "hosts": [],
-                                  "deleted_at": None,
-                                  "id": 1,
-                                  "metadata": {}}}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.update_aggregate,
             'tempest.common.service_client.ServiceClient.put',
-            return_value=mocked_resp))
-        resp = self.client.update_aggregate(1)
-        self.assertEqual(expected, resp)
+            self.FAKE_UPDATE_AGGREGATE,
+            bytes_body,
+            aggregate_id=1)
 
     def test_update_aggregate_with_str_body(self):
         self._test_update_aggregate()
diff --git a/tempest/tests/services/compute/test_availability_zone_client.py b/tempest/tests/services/compute/test_availability_zone_client.py
index 64efd08..715cfd7 100644
--- a/tempest/tests/services/compute/test_availability_zone_client.py
+++ b/tempest/tests/services/compute/test_availability_zone_client.py
@@ -12,27 +12,25 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import httplib2
-
-from oslo_serialization import jsonutils as json
-from oslotest import mockpatch
-
 from tempest.services.compute.json import availability_zone_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestAvailabilityZoneClient(base.TestCase):
+class TestAvailabilityZoneClient(base.BaseComputeServiceTest):
 
-    FAKE_AVAILABIRITY_ZONE_INFO = [
-        {
-            "zoneState": {
-                "available": True
-            },
-            "hosts": None,
-            "zoneName": u'\xf4'
-        }
-    ]
+    FAKE_AVAILABIRITY_ZONE_INFO = {
+        "availabilityZoneInfo":
+        [
+            {
+                "zoneState": {
+                    "available": True
+                },
+                "hosts": None,
+                "zoneName": u'\xf4'
+            }
+        ]
+    }
 
     def setUp(self):
         super(TestAvailabilityZoneClient, self).setUp()
@@ -40,22 +38,14 @@
         self.client = availability_zone_client.AvailabilityZoneClient(
             fake_auth, 'compute', 'regionOne')
 
-    def _test_list_availability_zones(self, bytes_body=False):
-        serialized_body = json.dumps({
-            "availabilityZoneInfo": self.FAKE_AVAILABIRITY_ZONE_INFO})
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
-            'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.list_availability_zones()
-        self.assertEqual({
-            "availabilityZoneInfo": self.FAKE_AVAILABIRITY_ZONE_INFO}, resp)
-
     def test_list_availability_zones_with_str_body(self):
-        self._test_list_availability_zones()
+        self.check_service_client_function(
+            self.client.list_availability_zones,
+            'tempest.common.service_client.ServiceClient.get',
+            self.FAKE_AVAILABIRITY_ZONE_INFO)
 
     def test_list_availability_zones_with_bytes_body(self):
-        self._test_list_availability_zones(bytes_body=True)
+        self.check_service_client_function(
+            self.client.list_availability_zones,
+            'tempest.common.service_client.ServiceClient.get',
+            self.FAKE_AVAILABIRITY_ZONE_INFO, to_utf=True)
diff --git a/tempest/tests/services/compute/test_extensions_client.py b/tempest/tests/services/compute/test_extensions_client.py
index 20a5b7b..86f81f3 100644
--- a/tempest/tests/services/compute/test_extensions_client.py
+++ b/tempest/tests/services/compute/test_extensions_client.py
@@ -12,17 +12,24 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import httplib2
-
-from oslo_serialization import jsonutils as json
-from oslotest import mockpatch
-
 from tempest.services.compute.json import extensions_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestExtensionsClient(base.TestCase):
+class TestExtensionsClient(base.BaseComputeServiceTest):
+
+    FAKE_SHOW_EXTENSION = {
+        "extension": {
+            "updated": "2011-06-09T00:00:00Z",
+            "name": "Multinic",
+            "links": [],
+            "namespace":
+            "http://docs.openstack.org/compute/ext/multinic/api/v1.1",
+            "alias": "NMN",
+            "description": u'\u2740(*\xb4\u25e1`*)\u2740'
+        }
+    }
 
     def setUp(self):
         super(TestExtensionsClient, self).setUp()
@@ -31,15 +38,11 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_list_extensions(self, bytes_body=False):
-        body = '{"extensions": []}'
-        if bytes_body:
-            body = body.encode('utf-8')
-        expected = {"extensions": []}
-        response = (httplib2.Response({'status': 200}), body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.list_extensions,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=response))
-        self.assertEqual(expected, self.client.list_extensions())
+            {"extensions": []},
+            bytes_body)
 
     def test_list_extensions_with_str_body(self):
         self._test_list_extensions()
@@ -48,25 +51,12 @@
         self._test_list_extensions(bytes_body=True)
 
     def _test_show_extension(self, bytes_body=False):
-        expected = {"extension": {
-            "updated": "2011-06-09T00:00:00Z",
-            "name": "Multinic",
-            "links": [],
-            "namespace":
-            "http://docs.openstack.org/compute/ext/multinic/api/v1.1",
-            "alias": "NMN",
-            "description": u'\u2740(*\xb4\u25e1`*)\u2740'
-        }}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.show_extension,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_extension("NMN")
-        self.assertEqual(expected, resp)
+            self.FAKE_SHOW_EXTENSION,
+            bytes_body,
+            extension_alias="NMN")
 
     def test_show_extension_with_str_body(self):
         self._test_show_extension()
diff --git a/tempest/tests/services/compute/test_keypairs_client.py b/tempest/tests/services/compute/test_keypairs_client.py
index 8a0edd0..ba91757 100644
--- a/tempest/tests/services/compute/test_keypairs_client.py
+++ b/tempest/tests/services/compute/test_keypairs_client.py
@@ -15,15 +15,14 @@
 import copy
 import httplib2
 
-from oslo_serialization import jsonutils as json
 from oslotest import mockpatch
 
 from tempest.services.compute.json import keypairs_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestKeyPairsClient(base.TestCase):
+class TestKeyPairsClient(base.BaseComputeServiceTest):
 
     FAKE_KEYPAIR = {"keypair": {
         "public_key": "ssh-rsa foo Generated-by-Nova",
@@ -39,15 +38,11 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_list_keypairs(self, bytes_body=False):
-        body = '{"keypairs": []}'
-        if bytes_body:
-            body = body.encode('utf-8')
-        expected = {"keypairs": []}
-        response = (httplib2.Response({'status': 200}), body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.list_keypairs,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=response))
-        self.assertEqual(expected, self.client.list_keypairs())
+            {"keypairs": []},
+            bytes_body)
 
     def test_list_keypairs_with_str_body(self):
         self._test_list_keypairs()
@@ -64,16 +59,13 @@
             "deleted_at": None,
             "id": 1
             })
-        serialized_body = json.dumps(fake_keypair)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
 
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.show_keypair,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_keypair("test")
-        self.assertEqual(fake_keypair, resp)
+            fake_keypair,
+            bytes_body,
+            keypair_name="test")
 
     def test_show_keypair_with_str_body(self):
         self._test_show_keypair()
@@ -84,16 +76,13 @@
     def _test_create_keypair(self, bytes_body=False):
         fake_keypair = copy.deepcopy(self.FAKE_KEYPAIR)
         fake_keypair["keypair"].update({"private_key": "foo"})
-        serialized_body = json.dumps(fake_keypair)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
 
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.create_keypair,
             'tempest.common.service_client.ServiceClient.post',
-            return_value=mocked_resp))
-        resp = self.client.create_keypair(name='test')
-        self.assertEqual(fake_keypair, resp)
+            fake_keypair,
+            bytes_body,
+            name="test")
 
     def test_create_keypair_with_str_body(self):
         self._test_create_keypair()
diff --git a/tempest/tests/services/compute/test_limits_client.py b/tempest/tests/services/compute/test_limits_client.py
index 099d5ca..0036a3d 100644
--- a/tempest/tests/services/compute/test_limits_client.py
+++ b/tempest/tests/services/compute/test_limits_client.py
@@ -12,17 +12,12 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import httplib2
-
-from oslo_serialization import jsonutils as json
-from oslotest import mockpatch
-
 from tempest.services.compute.json import limits_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestLimitsClient(base.TestCase):
+class TestLimitsClient(base.BaseComputeServiceTest):
 
     def setUp(self):
         super(TestLimitsClient, self).setUp()
@@ -54,19 +49,15 @@
                     "maxTotalInstances": 10,
                     "maxTotalRAMSize": 51200,
                     "maxServerGroupMembers": 10
-                }
+                    }
             }
         }
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
 
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.show_limits,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_limits()
-        self.assertEqual(expected, resp)
+            expected,
+            bytes_body)
 
     def test_show_limits_with_str_body(self):
         self._test_show_limits()
diff --git a/tempest/tests/services/compute/test_networks_client.py b/tempest/tests/services/compute/test_networks_client.py
index cbeaefc..49a2344 100644
--- a/tempest/tests/services/compute/test_networks_client.py
+++ b/tempest/tests/services/compute/test_networks_client.py
@@ -12,17 +12,12 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import httplib2
-
-from oslo_serialization import jsonutils as json
-from oslotest import mockpatch
-
 from tempest.services.compute.json import networks_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestNetworksClient(base.TestCase):
+class TestNetworksClient(base.BaseComputeServiceTest):
 
     FAKE_NETWORK = {
         "bridge": None,
@@ -70,17 +65,12 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_list_networks(self, bytes_body=False):
-        expected = {"networks": self.FAKE_NETWORKS}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        fake_list = {"networks": self.FAKE_NETWORKS}
+        self.check_service_client_function(
+            self.client.list_networks,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.list_networks()
-        self.assertEqual(expected, resp)
+            fake_list,
+            bytes_body)
 
     def test_list_networks_with_str_body(self):
         self._test_list_networks()
@@ -89,17 +79,13 @@
         self._test_list_networks(bytes_body=True)
 
     def _test_show_network(self, bytes_body=False):
-        expected = {"network": self.FAKE_NETWORKS}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.show_network,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_network(self.network_id)
-        self.assertEqual(expected, resp)
+            {"network": self.FAKE_NETWORKS},
+            bytes_body,
+            network_id=self.network_id
+            )
 
     def test_show_network_with_str_body(self):
         self._test_show_network()
diff --git a/tempest/tests/services/compute/test_quota_classes_client.py b/tempest/tests/services/compute/test_quota_classes_client.py
index bc52511..f4fc51a 100644
--- a/tempest/tests/services/compute/test_quota_classes_client.py
+++ b/tempest/tests/services/compute/test_quota_classes_client.py
@@ -13,17 +13,13 @@
 #    under the License.
 
 import copy
-import httplib2
-
-from oslo_serialization import jsonutils as json
-from oslotest import mockpatch
 
 from tempest.services.compute.json import quota_classes_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestQuotaClassesClient(base.TestCase):
+class TestQuotaClassesClient(base.BaseComputeServiceTest):
 
     FAKE_QUOTA_CLASS_SET = {
         "injected_file_content_bytes": 10240,
@@ -50,17 +46,13 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_show_quota_class_set(self, bytes_body=False):
-        expected = {'quota_class_set': self.FAKE_QUOTA_CLASS_SET}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        fake_body = {'quota_class_set': self.FAKE_QUOTA_CLASS_SET}
+        self.check_service_client_function(
+            self.client.show_quota_class_set,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_quota_class_set("test")
-        self.assertEqual(expected, resp)
+            fake_body,
+            bytes_body,
+            quota_class_id="test")
 
     def test_show_quota_class_set_with_str_body(self):
         self._test_show_quota_class_set()
@@ -71,12 +63,9 @@
     def test_update_quota_class_set(self):
         fake_quota_class_set = copy.deepcopy(self.FAKE_QUOTA_CLASS_SET)
         fake_quota_class_set.pop("id")
-        expected = {'quota_class_set': fake_quota_class_set}
-        serialized_body = json.dumps(expected)
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        fake_body = {'quota_class_set': fake_quota_class_set}
+        self.check_service_client_function(
+            self.client.update_quota_class_set,
             'tempest.common.service_client.ServiceClient.put',
-            return_value=mocked_resp))
-        resp = self.client.update_quota_class_set("test")
-        self.assertEqual(expected, resp)
+            fake_body,
+            quota_class_id="test")
diff --git a/tempest/tests/services/compute/test_quotas_client.py b/tempest/tests/services/compute/test_quotas_client.py
index 0f72b3d..e2e6546 100644
--- a/tempest/tests/services/compute/test_quotas_client.py
+++ b/tempest/tests/services/compute/test_quotas_client.py
@@ -15,15 +15,14 @@
 import copy
 import httplib2
 
-from oslo_serialization import jsonutils as json
 from oslotest import mockpatch
 
 from tempest.services.compute.json import quotas_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestQuotasClient(base.TestCase):
+class TestQuotasClient(base.BaseComputeServiceTest):
 
     FAKE_QUOTA_SET = {
         "quota_set": {
@@ -53,16 +52,12 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_show_quota_set(self, bytes_body=False):
-        serialized_body = json.dumps(self.FAKE_QUOTA_SET)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.show_quota_set,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_quota_set(self.project_id)
-        self.assertEqual(self.FAKE_QUOTA_SET, resp)
+            self.FAKE_QUOTA_SET,
+            to_utf=bytes_body,
+            tenant_id=self.project_id)
 
     def test_show_quota_set_with_str_body(self):
         self._test_show_quota_set()
@@ -71,16 +66,12 @@
         self._test_show_quota_set(bytes_body=True)
 
     def _test_show_default_quota_set(self, bytes_body=False):
-        serialized_body = json.dumps(self.FAKE_QUOTA_SET)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.show_default_quota_set,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_default_quota_set(self.project_id)
-        self.assertEqual(self.FAKE_QUOTA_SET, resp)
+            self.FAKE_QUOTA_SET,
+            to_utf=bytes_body,
+            tenant_id=self.project_id)
 
     def test_show_default_quota_set_with_str_body(self):
         self._test_show_quota_set()
@@ -91,13 +82,11 @@
     def test_update_quota_set(self):
         fake_quota_set = copy.deepcopy(self.FAKE_QUOTA_SET)
         fake_quota_set['quota_set'].pop("id")
-        serialized_body = json.dumps(fake_quota_set)
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.update_quota_set,
             'tempest.common.service_client.ServiceClient.put',
-            return_value=mocked_resp))
-        resp = self.client.update_quota_set(self.project_id)
-        self.assertEqual(fake_quota_set, resp)
+            fake_quota_set,
+            tenant_id=self.project_id)
 
     def test_delete_quota_set(self):
         expected = {}
diff --git a/tempest/tests/services/compute/test_services_client.py b/tempest/tests/services/compute/test_services_client.py
index 7d87711..fe63de9 100644
--- a/tempest/tests/services/compute/test_services_client.py
+++ b/tempest/tests/services/compute/test_services_client.py
@@ -13,34 +13,36 @@
 #    under the License.
 
 import copy
-import httplib2
-
-from oslo_serialization import jsonutils as json
-from oslotest import mockpatch
 
 from tempest.services.compute.json import services_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestServicesClient(base.TestCase):
+class TestServicesClient(base.BaseComputeServiceTest):
 
-    FAKE_SERVICES = [{
-        "status": "enabled",
-        "binary": "nova-conductor",
-        "zone": "internal",
-        "state": "up",
-        "updated_at": "2015-08-19T06:50:55.000000",
-        "host": "controller",
-        "disabled_reason": None,
-        "id": 1
+    FAKE_SERVICES = {
+        "services":
+        [{
+            "status": "enabled",
+            "binary": "nova-conductor",
+            "zone": "internal",
+            "state": "up",
+            "updated_at": "2015-08-19T06:50:55.000000",
+            "host": "controller",
+            "disabled_reason": None,
+            "id": 1
         }]
+    }
 
     FAKE_SERVICE = {
-        "status": "enabled",
-        "binary": "nova-conductor",
-        "host": "controller"
+        "service":
+        {
+            "status": "enabled",
+            "binary": "nova-conductor",
+            "host": "controller"
         }
+    }
 
     def setUp(self):
         super(TestServicesClient, self).setUp()
@@ -48,37 +50,25 @@
         self.client = services_client.ServicesClient(
             fake_auth, 'compute', 'regionOne')
 
-    def _test_list_services(self, bytes_body=False):
-        expected = {"services": self.FAKE_SERVICES}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
-            'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.list_services()
-        self.assertEqual(expected, resp)
-
     def test_list_services_with_str_body(self):
-        self._test_list_services()
+        self.check_service_client_function(
+            self.client.list_services,
+            'tempest.common.service_client.ServiceClient.get',
+            self.FAKE_SERVICES)
 
     def test_list_services_with_bytes_body(self):
-        self._test_list_services(bytes_body=True)
+        self.check_service_client_function(
+            self.client.list_services,
+            'tempest.common.service_client.ServiceClient.get',
+            self.FAKE_SERVICES, to_utf=True)
 
     def _test_enable_service(self, bytes_body=False):
-        expected = {"service": self.FAKE_SERVICE}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.enable_service,
             'tempest.common.service_client.ServiceClient.put',
-            return_value=mocked_resp))
-        resp = self.client.enable_service("nova-conductor", "controller")
-        self.assertEqual(expected, resp)
+            self.FAKE_SERVICE,
+            bytes_body,
+            host_name="nova-conductor", binary="controller")
 
     def test_enable_service_with_str_body(self):
         self._test_enable_service()
@@ -88,18 +78,14 @@
 
     def _test_disable_service(self, bytes_body=False):
         fake_service = copy.deepcopy(self.FAKE_SERVICE)
-        fake_service["status"] = "disable"
-        expected = {"service": self.FAKE_SERVICE}
-        serialized_body = json.dumps(expected)
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
+        fake_service["service"]["status"] = "disable"
 
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.enable_service,
             'tempest.common.service_client.ServiceClient.put',
-            return_value=mocked_resp))
-        resp = self.client.disable_service("nova-conductor", "controller")
-        self.assertEqual(expected, resp)
+            fake_service,
+            bytes_body,
+            host_name="nova-conductor", binary="controller")
 
     def test_disable_service_with_str_body(self):
         self._test_enable_service()
diff --git a/tempest/tests/services/compute/test_tenant_usages_client.py b/tempest/tests/services/compute/test_tenant_usages_client.py
index f6bcf5f..8a2c1a4 100644
--- a/tempest/tests/services/compute/test_tenant_usages_client.py
+++ b/tempest/tests/services/compute/test_tenant_usages_client.py
@@ -12,17 +12,12 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import httplib2
-
-from oslo_serialization import jsonutils as json
-from oslotest import mockpatch
-
 from tempest.services.compute.json import tenant_usages_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestTenantUsagesClient(base.TestCase):
+class TestTenantUsagesClient(base.BaseComputeServiceTest):
 
     FAKE_SERVER_USAGES = [{
         "ended_at": None,
@@ -57,17 +52,11 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_list_tenant_usages(self, bytes_body=False):
-        serialized_body = json.dumps({"tenant_usages":
-                                      self.FAKE_TENANT_USAGES})
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.list_tenant_usages,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.list_tenant_usages()
-        self.assertEqual({"tenant_usages": self.FAKE_TENANT_USAGES}, resp)
+            {"tenant_usages": self.FAKE_TENANT_USAGES},
+            to_utf=bytes_body)
 
     def test_list_tenant_usages_with_str_body(self):
         self._test_list_tenant_usages()
@@ -76,17 +65,12 @@
         self._test_list_tenant_usages(bytes_body=True)
 
     def _test_show_tenant_usage(self, bytes_body=False):
-        serialized_body = json.dumps({"tenant_usage":
-                                      self.FAKE_TENANT_USAGES[0]})
-        if bytes_body:
-            serialized_body = serialized_body.encode('utf-8')
-
-        mocked_resp = (httplib2.Response({'status': 200}), serialized_body)
-        self.useFixture(mockpatch.Patch(
+        self.check_service_client_function(
+            self.client.show_tenant_usage,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_tenant_usage('openstack')
-        self.assertEqual({"tenant_usage": self.FAKE_TENANT_USAGES[0]}, resp)
+            {"tenant_usage": self.FAKE_TENANT_USAGES[0]},
+            to_utf=bytes_body,
+            tenant_id='openstack')
 
     def test_show_tenant_usage_with_str_body(self):
         self._test_show_tenant_usage()