Define v3 policies_client as library

Migrate v3 API policies_client to tempest.lib

Partially implements blueprint consistent-service-method-names

Change-Id: I8126f5c48784e39ad4c7ce25b0b85ba66d90c2a3
diff --git a/releasenotes/notes/identity-clients-as-library-e663c6132fcac6c2.yaml b/releasenotes/notes/identity-clients-as-library-e663c6132fcac6c2.yaml
index 1f3d930..b8f3c0e 100644
--- a/releasenotes/notes/identity-clients-as-library-e663c6132fcac6c2.yaml
+++ b/releasenotes/notes/identity-clients-as-library-e663c6132fcac6c2.yaml
@@ -8,6 +8,7 @@
 
       * endpoints_client(v2)
       * endpoints_client(v3)
+      * policies_client (v3)
       * roles_client(v2)
       * services_client(v2)
       * tenants_client(v2)
diff --git a/tempest/services/identity/v3/json/policies_client.py b/tempest/lib/services/identity/v3/policies_client.py
similarity index 100%
rename from tempest/services/identity/v3/json/policies_client.py
rename to tempest/lib/services/identity/v3/policies_client.py
diff --git a/tempest/services/identity/v3/__init__.py b/tempest/services/identity/v3/__init__.py
index b9ed4fa..6ad8ef2 100644
--- a/tempest/services/identity/v3/__init__.py
+++ b/tempest/services/identity/v3/__init__.py
@@ -13,13 +13,13 @@
 # the License.
 
 from tempest.lib.services.identity.v3.endpoints_client import EndPointsClient
+from tempest.lib.services.identity.v3.policies_client import PoliciesClient
 from tempest.lib.services.identity.v3.token_client import V3TokenClient
 from tempest.services.identity.v3.json.credentials_client import \
     CredentialsClient
 from tempest.services.identity.v3.json.domains_client import DomainsClient
 from tempest.services.identity.v3.json.groups_client import GroupsClient
 from tempest.services.identity.v3.json.identity_client import IdentityClient
-from tempest.services.identity.v3.json.policies_client import PoliciesClient
 from tempest.services.identity.v3.json.projects_client import ProjectsClient
 from tempest.services.identity.v3.json.regions_client import RegionsClient
 from tempest.services.identity.v3.json.roles_client import RolesClient
@@ -27,7 +27,7 @@
 from tempest.services.identity.v3.json.trusts_client import TrustsClient
 from tempest.services.identity.v3.json.users_clients import UsersClient
 
-__all__ = ['EndPointsClient', 'V3TokenClient', 'CredentialsClient',
-           'DomainsClient', 'GroupsClient', 'IdentityClient', 'PoliciesClient',
-           'ProjectsClient', 'RegionsClient', 'RolesClient', 'ServicesClient',
-           'TrustsClient', 'UsersClient', ]
+__all__ = ['EndPointsClient', 'PoliciesClient', 'V3TokenClient',
+           'CredentialsClient', 'DomainsClient', 'GroupsClient',
+           'IdentityClient', 'ProjectsClient', 'RegionsClient', 'RolesClient',
+           'ServicesClient', 'TrustsClient', 'UsersClient', ]
diff --git a/tempest/tests/lib/services/identity/v3/test_policies_client.py b/tempest/tests/lib/services/identity/v3/test_policies_client.py
new file mode 100644
index 0000000..66c3d65
--- /dev/null
+++ b/tempest/tests/lib/services/identity/v3/test_policies_client.py
@@ -0,0 +1,152 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# 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.
+
+from tempest.lib.services.identity.v3 import policies_client
+from tempest.tests.lib import fake_auth_provider
+from tempest.tests.lib.services import base
+
+
+class TestPoliciesClient(base.BaseServiceTest):
+    FAKE_CREATE_POLICY = {
+        "policy": {
+            "blob": "{'foobar_user': 'role:compute-user'}",
+            "project_id": "0426ac1e48f642ef9544c2251e07e261",
+            "type": "application/json",
+            "user_id": "0ffd248c55b443eaac5253b4e9cbf9b5"
+            }
+        }
+
+    FAKE_POLICY_INFO = {
+        "policy": {
+            "blob": {
+                "foobar_user": [
+                    "role:compute-user"
+                    ]
+                },
+            "id": "717273",
+            "links": {
+                "self": "http://example.com/identity/v3/policies/717273"
+                },
+            "project_id": "456789",
+            "type": "application/json",
+            "user_id": "616263"
+            }
+        }
+
+    FAKE_LIST_POLICIES = {
+        "links": {
+            "next": None,
+            "previous": None,
+            "self": "http://example.com/identity/v3/policies"
+            },
+        "policies": [
+            {
+                "blob": {
+                    "foobar_user": [
+                        "role:compute-user"
+                        ]
+                    },
+                "id": "717273",
+                "links": {
+                    "self": "http://example.com/identity/v3/policies/717273"
+                    },
+                "project_id": "456789",
+                "type": "application/json",
+                "user_id": "616263"
+                },
+            {
+                "blob": {
+                    "foobar_user": [
+                        "role:compute-user"
+                        ]
+                    },
+                "id": "717274",
+                "links": {
+                    "self": "http://example.com/identity/v3/policies/717274"
+                    },
+                "project_id": "456789",
+                "type": "application/json",
+                "user_id": "616263"
+                }
+            ]
+    }
+
+    def setUp(self):
+        super(TestPoliciesClient, self).setUp()
+        fake_auth = fake_auth_provider.FakeAuthProvider()
+        self.client = policies_client.PoliciesClient(fake_auth,
+                                                     'identity', 'regionOne')
+
+    def _test_create_policy(self, bytes_body=False):
+        self.check_service_client_function(
+            self.client.create_policy,
+            'tempest.lib.common.rest_client.RestClient.post',
+            self.FAKE_CREATE_POLICY,
+            bytes_body,
+            status=201)
+
+    def _test_show_policy(self, bytes_body=False):
+        self.check_service_client_function(
+            self.client.show_policy,
+            'tempest.lib.common.rest_client.RestClient.get',
+            self.FAKE_POLICY_INFO,
+            bytes_body,
+            policy_id="717273")
+
+    def _test_list_policies(self, bytes_body=False):
+        self.check_service_client_function(
+            self.client.list_policies,
+            'tempest.lib.common.rest_client.RestClient.get',
+            self.FAKE_LIST_POLICIES,
+            bytes_body)
+
+    def _test_update_policy(self, bytes_body=False):
+        self.check_service_client_function(
+            self.client.update_policy,
+            'tempest.lib.common.rest_client.RestClient.patch',
+            self.FAKE_POLICY_INFO,
+            bytes_body,
+            policy_id="717273")
+
+    def test_create_policy_with_str_body(self):
+        self._test_create_policy()
+
+    def test_create_policy_with_bytes_body(self):
+        self._test_create_policy(bytes_body=True)
+
+    def test_show_policy_with_str_body(self):
+        self._test_show_policy()
+
+    def test_show_policy_with_bytes_body(self):
+        self._test_show_policy(bytes_body=True)
+
+    def test_list_policies_with_str_body(self):
+        self._test_list_policies()
+
+    def test_list_policies_with_bytes_body(self):
+        self._test_list_policies(bytes_body=True)
+
+    def test_update_policy_with_str_body(self):
+        self._test_update_policy()
+
+    def test_update_policy_with_bytes_body(self):
+        self._test_update_policy(bytes_body=True)
+
+    def test_delete_policy(self):
+        self.check_service_client_function(
+            self.client.delete_policy,
+            'tempest.lib.common.rest_client.RestClient.delete',
+            {},
+            policy_id="717273",
+            status=204)