Merge "Adds new v3 projects tests to Keystone"
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/services/identity/v3/json/identity_client.py b/tempest/services/identity/v3/json/identity_client.py
index 0188c2a..d57b931 100644
--- a/tempest/services/identity/v3/json/identity_client.py
+++ b/tempest/services/identity/v3/json/identity_client.py
@@ -135,8 +135,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 f3e084e..c2bd77e 100644
--- a/tempest/services/identity/v3/xml/identity_client.py
+++ b/tempest/services/identity/v3/xml/identity_client.py
@@ -197,9 +197,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