Adds new v3 projects tests to Keystone

This submission adds a new test script "test_list_projects.py"
which has list projects with filters test cases. Also adds
missing v2 tests in v3 projects test script. Hence made
required changes in support functions too. As there is a new
script test_list_projects.py with list cases in it, hence removed
the test_list_projects test case from test_projects.py script and
added it to test_list_projects.py

Change-Id: I2db83e7cb70d89e7516c92eba4cb24115203e143
diff --git a/tempest/api/identity/admin/v3/test_list_projects.py b/tempest/api/identity/admin/v3/test_list_projects.py
new file mode 100644
index 0000000..a3944e2
--- /dev/null
+++ b/tempest/api/identity/admin/v3/test_list_projects.py
@@ -0,0 +1,73 @@
+# Copyright 2014 Hewlett-Packard Development Company, L.P
+# 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.
+
+from tempest.api.identity import base
+from tempest.common.utils import data_utils
+from tempest import test
+
+
+class ListProjectsTestJSON(base.BaseIdentityV3AdminTest):
+    _interface = 'json'
+
+    @classmethod
+    def setUpClass(cls):
+        super(ListProjectsTestJSON, cls).setUpClass()
+        cls.project_ids = list()
+        cls.data.setup_test_domain()
+        # Create project with domain
+        cls.p1_name = data_utils.rand_name('project')
+        _, cls.p1 = cls.client.create_project(
+            cls.p1_name, enabled=False, domain_id=cls.data.domain['id'])
+        cls.data.projects.append(cls.p1)
+        cls.project_ids.append(cls.p1['id'])
+        # Create default project
+        p2_name = data_utils.rand_name('project')
+        _, cls.p2 = cls.client.create_project(p2_name)
+        cls.data.projects.append(cls.p2)
+        cls.project_ids.append(cls.p2['id'])
+
+    @test.attr(type='gate')
+    def test_projects_list(self):
+        # List projects
+        resp, list_projects = self.client.list_projects()
+
+        for p in self.project_ids:
+            _, get_project = self.client.get_project(p)
+            self.assertIn(get_project, list_projects)
+
+    @test.attr(type='gate')
+    def test_list_projects_with_domains(self):
+        # List projects with domain
+        self._list_projects_with_params(
+            {'domain_id': self.data.domain['id']}, 'domain_id')
+
+    @test.attr(type='gate')
+    def test_list_projects_with_enabled(self):
+        # List the projects with enabled
+        self._list_projects_with_params({'enabled': False}, 'enabled')
+
+    @test.attr(type='gate')
+    def test_list_projects_with_name(self):
+        # List projects with name
+        self._list_projects_with_params({'name': self.p1_name}, 'name')
+
+    def _list_projects_with_params(self, params, key):
+        resp, body = self.client.list_projects(params)
+        self.assertIn(self.p1[key], map(lambda x: x[key], body))
+        self.assertNotIn(self.p2[key], map(lambda x: x[key], body))
+
+
+class ListProjectsTestXML(ListProjectsTestJSON):
+    _interface = 'xml'
diff --git a/tempest/api/identity/admin/v3/test_projects.py b/tempest/api/identity/admin/v3/test_projects.py
index 77acd57..5890eab 100644
--- a/tempest/api/identity/admin/v3/test_projects.py
+++ b/tempest/api/identity/admin/v3/test_projects.py
@@ -13,35 +13,14 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-from six import moves
-
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
-from tempest import exceptions
 from tempest import test
 
 
 class ProjectsTestJSON(base.BaseIdentityV3AdminTest):
     _interface = 'json'
 
-    def _delete_project(self, project_id):
-        self.client.delete_project(project_id)
-        self.assertRaises(
-            exceptions.NotFound, self.client.get_project, project_id)
-
-    @test.attr(type='gate')
-    def test_project_list_delete(self):
-        # Create several projects and delete them
-        for _ in moves.xrange(3):
-            _, project = self.client.create_project(
-                data_utils.rand_name('project-new'))
-            self.addCleanup(self._delete_project, project['id'])
-
-        _, list_projects = self.client.list_projects()
-
-        _, get_project = self.client.get_project(project['id'])
-        self.assertIn(get_project, list_projects)
-
     @test.attr(type='gate')
     def test_project_create_with_description(self):
         # Create project with a description
@@ -60,6 +39,21 @@
                          'to be set')
 
     @test.attr(type='gate')
+    def test_project_create_with_domain(self):
+        # Create project with a domain
+        self.data.setup_test_domain()
+        project_name = data_utils.rand_name('project')
+        resp, project = self.client.create_project(
+            project_name, domain_id=self.data.domain['id'])
+        self.data.projects.append(project)
+        project_id = project['id']
+        self.assertEqual(project_name, project['name'])
+        self.assertEqual(self.data.domain['id'], project['domain_id'])
+        _, body = self.client.get_project(project_id)
+        self.assertEqual(project_name, body['name'])
+        self.assertEqual(self.data.domain['id'], body['domain_id'])
+
+    @test.attr(type='gate')
     def test_project_create_enabled(self):
         # Create a project that is enabled
         project_name = data_utils.rand_name('project-')
diff --git a/tempest/api/identity/base.py b/tempest/api/identity/base.py
index 0991576..3bb33f7 100644
--- a/tempest/api/identity/base.py
+++ b/tempest/api/identity/base.py
@@ -121,6 +121,7 @@
             self.v3_users = []
             self.projects = []
             self.v3_roles = []
+            self.domains = []
 
         @property
         def test_credentials(self):
@@ -185,6 +186,15 @@
             _, self.v3_role = self.client.create_role(self.test_role)
             self.v3_roles.append(self.v3_role)
 
+        def setup_test_domain(self):
+            """Set up a test domain."""
+            self.test_domain = data_utils.rand_name('test_domain')
+            self.test_description = data_utils.rand_name('desc')
+            _, self.domain = self.client.create_domain(
+                name=self.test_domain,
+                description=self.test_description)
+            self.domains.append(self.domain)
+
         def teardown_all(self):
             for user in self.users:
                 self.client.delete_user(user['id'])
diff --git a/tempest/services/identity/v3/json/identity_client.py b/tempest/services/identity/v3/json/identity_client.py
index 8c72dfa..b389501 100644
--- a/tempest/services/identity/v3/json/identity_client.py
+++ b/tempest/services/identity/v3/json/identity_client.py
@@ -14,6 +14,7 @@
 #    under the License.
 
 import json
+import urllib
 
 from tempest.common import rest_client
 from tempest import config
@@ -120,8 +121,11 @@
         body = json.loads(body)
         return resp, body['project']
 
-    def list_projects(self):
-        resp, body = self.get("projects")
+    def list_projects(self, params=None):
+        url = "projects"
+        if params:
+            url += '?%s' % urllib.urlencode(params)
+        resp, body = self.get(url)
         self.expected_success(200, resp.status)
         body = json.loads(body)
         return resp, body['projects']
diff --git a/tempest/services/identity/v3/xml/identity_client.py b/tempest/services/identity/v3/xml/identity_client.py
index 242b032..ea10716 100644
--- a/tempest/services/identity/v3/xml/identity_client.py
+++ b/tempest/services/identity/v3/xml/identity_client.py
@@ -14,6 +14,7 @@
 #    under the License.
 
 import json
+import urllib
 
 from lxml import etree
 
@@ -174,9 +175,12 @@
         body = self._parse_body(etree.fromstring(body))
         return resp, body
 
-    def list_projects(self):
+    def list_projects(self, params=None):
         """Get the list of projects."""
-        resp, body = self.get("projects")
+        url = 'projects'
+        if params:
+            url += '?%s' % urllib.urlencode(params)
+        resp, body = self.get(url)
         self.expected_success(200, resp.status)
         body = self._parse_projects(etree.fromstring(body))
         return resp, body