From f58be9d4ddc4d395e209015e8735f6cb4258a566 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Thu, 4 Aug 2016 15:46:50 +0800 Subject: 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 --- openstackclient/tests/identity/v3/fakes.py | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'openstackclient/tests/identity/v3/fakes.py') diff --git a/openstackclient/tests/identity/v3/fakes.py b/openstackclient/tests/identity/v3/fakes.py index 50e901c9..8c138f7b 100644 --- a/openstackclient/tests/identity/v3/fakes.py +++ b/openstackclient/tests/identity/v3/fakes.py @@ -769,6 +769,44 @@ class FakeGroup(object): loaded=True) return group + @staticmethod + def create_groups(attrs=None, count=2): + """Create multiple fake groups. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of groups to fake + :return: + A list of FakeResource objects faking the groups + """ + groups = [] + for i in range(0, count): + group = FakeGroup.create_one_group(attrs) + groups.append(group) + + return groups + + @staticmethod + def get_groups(groups=None, count=2): + """Get an iterable MagicMock object with a list of faked groups. + + If groups list is provided, then initialize the Mock object with + the list. Otherwise create one. + + :param List groups: + A list of FakeResource objects faking groups + :param Integer count: + The number of groups to be faked + :return + An iterable Mock object with side_effect set to a list of faked + groups + """ + if groups is None: + groups = FakeGroup.create_groups(count) + + return mock.MagicMock(side_effect=groups) + class FakeEndpoint(object): """Fake one or more endpoint.""" -- cgit v1.2.1