Skip to content

Commit f58be9d

Browse files
author
Huanxuan Ao
committed
Add unit tests for group commands in identity v3
Add unit tests for commands below in identity v3: group create group delete group show group set group add user group remove user group contains user Change-Id: I02f3b49e93582245a2749492bba1dfc4c5e0258d
1 parent 06ea247 commit f58be9d

2 files changed

Lines changed: 429 additions & 0 deletions

File tree

openstackclient/tests/identity/v3/fakes.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,44 @@ def create_one_group(attrs=None):
769769
loaded=True)
770770
return group
771771

772+
@staticmethod
773+
def create_groups(attrs=None, count=2):
774+
"""Create multiple fake groups.
775+
776+
:param Dictionary attrs:
777+
A dictionary with all attributes
778+
:param int count:
779+
The number of groups to fake
780+
:return:
781+
A list of FakeResource objects faking the groups
782+
"""
783+
groups = []
784+
for i in range(0, count):
785+
group = FakeGroup.create_one_group(attrs)
786+
groups.append(group)
787+
788+
return groups
789+
790+
@staticmethod
791+
def get_groups(groups=None, count=2):
792+
"""Get an iterable MagicMock object with a list of faked groups.
793+
794+
If groups list is provided, then initialize the Mock object with
795+
the list. Otherwise create one.
796+
797+
:param List groups:
798+
A list of FakeResource objects faking groups
799+
:param Integer count:
800+
The number of groups to be faked
801+
:return
802+
An iterable Mock object with side_effect set to a list of faked
803+
groups
804+
"""
805+
if groups is None:
806+
groups = FakeGroup.create_groups(count)
807+
808+
return mock.MagicMock(side_effect=groups)
809+
772810

773811
class FakeEndpoint(object):
774812
"""Fake one or more endpoint."""

0 commit comments

Comments
 (0)