Browse Source

Merge "Add parent project filter for listing projects"

tags/3.21.0
Zuul 1 week ago
parent
commit
4e812b673b

+ 24
- 0
keystoneclient/tests/functional/v3/test_projects.py View File

@@ -157,6 +157,30 @@ class ProjectsTestCase(base.V3ClientTestCase, ProjectsTestMixin):
157 157
         self.assertIn(project_one.entity, projects)
158 158
         self.assertIn(project_two.entity, projects)
159 159
 
160
+    def test_list_subprojects(self):
161
+        parent_project = fixtures.Project(self.client, self.test_domain.id)
162
+        self.useFixture(parent_project)
163
+
164
+        child_project_one = fixtures.Project(self.client, self.test_domain.id,
165
+                                             parent=parent_project.id)
166
+        self.useFixture(child_project_one)
167
+
168
+        child_project_two = fixtures.Project(self.client, self.test_domain.id,
169
+                                             parent=parent_project.id)
170
+        self.useFixture(child_project_two)
171
+
172
+        projects = self.client.projects.list(parent=parent_project.id)
173
+
174
+        # All projects are valid
175
+        for project in projects:
176
+            self.check_project(project)
177
+
178
+        self.assertIn(child_project_one.entity, projects)
179
+        self.assertIn(child_project_two.entity, projects)
180
+
181
+        # Parent project should not be included in the result
182
+        self.assertNotIn(parent_project.entity, projects)
183
+
160 184
     def test_update_project(self):
161 185
         project = fixtures.Project(self.client, self.test_domain.id)
162 186
         self.useFixture(project)

+ 13
- 2
keystoneclient/tests/unit/v3/test_projects.py View File

@@ -55,8 +55,7 @@ class ProjectTests(utils.ClientTestCase, utils.CrudTests):
55 55
         ref_list = [self.new_ref(), self.new_ref()]
56 56
         domain_id = uuid.uuid4().hex
57 57
 
58
-        self.stub_entity('GET', [self.collection_key],
59
-                         entity=ref_list)
58
+        self.stub_entity('GET', [self.collection_key], entity=ref_list)
60 59
 
61 60
         returned_list = self.manager.list(domain=domain_id)
62 61
         self.assertEqual(len(ref_list), len(returned_list))
@@ -64,6 +63,18 @@ class ProjectTests(utils.ClientTestCase, utils.CrudTests):
64 63
 
65 64
         self.assertQueryStringIs('domain_id=%s' % domain_id)
66 65
 
66
+    def test_list_projects_for_parent(self):
67
+        ref_list = [self.new_ref(), self.new_ref()]
68
+        parent_id = uuid.uuid4().hex
69
+
70
+        self.stub_entity('GET', [self.collection_key], entity=ref_list)
71
+
72
+        returned_list = self.manager.list(parent=parent_id)
73
+        self.assertEqual(len(ref_list), len(returned_list))
74
+        [self.assertIsInstance(r, self.model) for r in returned_list]
75
+
76
+        self.assertQueryStringIs('parent_id=%s' % parent_id)
77
+
67 78
     def test_create_with_parent(self):
68 79
         parent_ref = self.new_ref()
69 80
         parent_ref['parent_id'] = uuid.uuid4().hex

+ 5
- 1
keystoneclient/v3/projects.py View File

@@ -112,7 +112,7 @@ class ProjectManager(base.CrudManager):
112 112
             enabled=enabled,
113 113
             **kwargs)
114 114
 
115
-    def list(self, domain=None, user=None, **kwargs):
115
+    def list(self, domain=None, user=None, parent=None, **kwargs):
116 116
         """List projects.
117 117
 
118 118
         :param domain: the domain of the projects to be filtered on.
@@ -120,6 +120,9 @@ class ProjectManager(base.CrudManager):
120 120
         :param user: filter in projects the specified user has role
121 121
                      assignments on.
122 122
         :type user: str or :class:`keystoneclient.v3.users.User`
123
+        :param parent: filter in projects the specified project is a parent
124
+                       for
125
+        :type parent: str or :class:`keystoneclient.v3.projects.Project`
123 126
         :param kwargs: any other attribute provided will filter projects on.
124 127
                        Project tags filter keyword: ``tags``, ``tags_any``,
125 128
                        ``not_tags``, and ``not_tags_any``. tag attribute type
@@ -134,6 +137,7 @@ class ProjectManager(base.CrudManager):
134 137
         projects = super(ProjectManager, self).list(
135 138
             base_url=base_url,
136 139
             domain_id=base.getid(domain),
140
+            parent_id=base.getid(parent),
137 141
             fallback_to_auth=True,
138 142
             **kwargs)
139 143
 

+ 5
- 0
releasenotes/notes/list_projects_filtered_by_the_parent_project-a873974f197c1e37.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+features:
3
+  - |
4
+    Now keystone client supports to list projects which belongs to the given
5
+    parent project.

Loading…
Cancel
Save