Merge "Deduplicate cert, audit_log and tenant_net client"
diff --git a/tempest/tests/services/compute/test_certificates_client.py b/tempest/tests/services/compute/test_certificates_client.py
index 51c3e85..c926fce 100644
--- a/tempest/tests/services/compute/test_certificates_client.py
+++ b/tempest/tests/services/compute/test_certificates_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 certificates_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestCertificatesClient(base.TestCase):
+class TestCertificatesClient(base.BaseComputeServiceTest):
 
     FAKE_CERTIFICATE = {
         "certificate": {
@@ -39,16 +35,12 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_show_certificate(self, bytes_body=False):
-        serialized_body = json.dumps(self.FAKE_CERTIFICATE)
-        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_certificate,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_certificate("fake-id")
-        self.assertEqual(self.FAKE_CERTIFICATE, resp)
+            self.FAKE_CERTIFICATE,
+            bytes_body,
+            certificate_id="fake-id")
 
     def test_show_certificate_with_str_body(self):
         self._test_show_certificate()
@@ -59,16 +51,11 @@
     def _test_create_certificate(self, bytes_body=False):
         cert = copy.deepcopy(self.FAKE_CERTIFICATE)
         cert['certificate']['private_key'] = "my_private_key"
-        serialized_body = json.dumps(cert)
-        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_certificate,
             'tempest.common.service_client.ServiceClient.post',
-            return_value=mocked_resp))
-        resp = self.client.create_certificate()
-        self.assertEqual(cert, resp)
+            cert,
+            bytes_body)
 
     def test_create_certificate_with_str_body(self):
         self._test_create_certificate()
diff --git a/tempest/tests/services/compute/test_instance_usage_audit_log_client.py b/tempest/tests/services/compute/test_instance_usage_audit_log_client.py
index 07efeca..d4bc889 100644
--- a/tempest/tests/services/compute/test_instance_usage_audit_log_client.py
+++ b/tempest/tests/services/compute/test_instance_usage_audit_log_client.py
@@ -13,17 +13,13 @@
 #    under the License.
 
 import datetime
-import httplib2
-
-from oslo_serialization import jsonutils as json
-from oslotest import mockpatch
 
 from tempest.services.compute.json import instance_usage_audit_log_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestInstanceUsagesAuditLogClient(base.TestCase):
+class TestInstanceUsagesAuditLogClient(base.BaseComputeServiceTest):
 
     FAKE_AUDIT_LOG = {
         "hosts_not_run": [
@@ -49,18 +45,11 @@
                                                     'regionOne'))
 
     def _test_list_instance_usage_audit_logs(self, bytes_body=False):
-        serialized_body = json.dumps({"instance_usage_audit_logs":
-                                      self.FAKE_AUDIT_LOG})
-        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_instance_usage_audit_logs,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.list_instance_usage_audit_logs()
-        self.assertEqual({"instance_usage_audit_logs": self.FAKE_AUDIT_LOG},
-                         resp)
+            {"instance_usage_audit_logs": self.FAKE_AUDIT_LOG},
+            bytes_body)
 
     def test_list_instance_usage_audit_logs_with_str_body(self):
         self._test_list_instance_usage_audit_logs()
@@ -70,18 +59,12 @@
 
     def _test_show_instance_usage_audit_log(self, bytes_body=False):
         before_time = datetime.datetime(2012, 12, 1, 0, 0)
-        serialized_body = json.dumps({"instance_usage_audit_log":
-                                      self.FAKE_AUDIT_LOG})
-        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_instance_usage_audit_log,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_instance_usage_audit_log(before_time)
-        self.assertEqual({"instance_usage_audit_log": self.FAKE_AUDIT_LOG},
-                         resp)
+            {"instance_usage_audit_log": self.FAKE_AUDIT_LOG},
+            bytes_body,
+            time_before=before_time)
 
     def test_show_instance_usage_audit_log_with_str_body(self):
         self._test_show_instance_usage_audit_log()
diff --git a/tempest/tests/services/compute/test_tenant_networks_client.py b/tempest/tests/services/compute/test_tenant_networks_client.py
index d7c85f0..dc2de00 100644
--- a/tempest/tests/services/compute/test_tenant_networks_client.py
+++ b/tempest/tests/services/compute/test_tenant_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 tenant_networks_client
-from tempest.tests import base
 from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
 
 
-class TestTenantNetworksClient(base.TestCase):
+class TestTenantNetworksClient(base.BaseComputeServiceTest):
 
     FAKE_NETWORK = {
         "cidr": "None",
@@ -41,16 +36,11 @@
             fake_auth, 'compute', 'regionOne')
 
     def _test_list_tenant_networks(self, bytes_body=False):
-        serialized_body = json.dumps({"networks": self.FAKE_NETWORKS})
-        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_networks,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.list_tenant_networks()
-        self.assertEqual({"networks": self.FAKE_NETWORKS}, resp)
+            {"networks": self.FAKE_NETWORKS},
+            bytes_body)
 
     def test_list_tenant_networks_with_str_body(self):
         self._test_list_tenant_networks()
@@ -59,16 +49,12 @@
         self._test_list_tenant_networks(bytes_body=True)
 
     def _test_show_tenant_network(self, bytes_body=False):
-        serialized_body = json.dumps({"network": self.FAKE_NETWORK})
-        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_network,
             'tempest.common.service_client.ServiceClient.get',
-            return_value=mocked_resp))
-        resp = self.client.show_tenant_network(self.NETWORK_ID)
-        self.assertEqual({"network": self.FAKE_NETWORK}, resp)
+            {"network": self.FAKE_NETWORK},
+            bytes_body,
+            network_id=self.NETWORK_ID)
 
     def test_show_tenant_network_with_str_body(self):
         self._test_show_tenant_network()