def get_many(cls, group_ids: List[str] = None, names: List[str] = None): """ Resolve requested parameters into a list of Group objects :param group_ids: Group's unique GS Marquee IDs :param names: Group's names :return: A list of Group objects that corresponds to requested parameters """ group_ids = group_ids if group_ids else [] names = names if names else [] if not group_ids + names: return [] group_ids = [ id_[6:] if id_.startswith('group:') else id_ for id_ in group_ids ] results = GsGroupsApi.get_groups(ids=group_ids, names=names) all_groups = [] for group in results: all_groups.append( Group(group_id=group.id, name=group.name, entitlements=Entitlements.from_target(group.entitlements) if group.entitlements else None, description=group.description, tags=group.tags)) return all_groups
def test_get_groups(mocker): mock_response = { "totalResults": 1, "results": [{ "name": "GSOE Real Time Sync - gsoe.c3e2418dcfd0c6590134deb4caa9b7d65a92a4a761cf20436298560a9ed410a0", "id": "gsoe.c3e2418dcfd0c6590134deb4caa9b7d65a92a4a761cf20436298560a9ed410a0", "createdById": "3563ed98a93f44c0a016fed2e5c8ce9d", "lastUpdatedById": "3563ed98a93f44c0a016fed2e5c8ce9d", "ownerId": "3563ed98a93f44c0a016fed2e5c8ce9d", "createdTime": "2020-05-22T10:57:40.449-04:00", "lastUpdatedTime": "2020-05-22T10:57:40.449-04:00" }] } # mock GsSession mocker.patch.object(GsSession.__class__, 'default_value', return_value=GsSession.get(Environment.QA, 'client_id', 'secret')) mocker.patch.object(GsSession.current, '_get', return_value=mock_response) # run test response = GsGroupsApi.get_groups(ids=['id1', 'id2'], names=['name1'], tags=['tag1'], limit=1) GsSession.current._get.assert_called_with( '/groups?limit=1&offset=0&id=id1&id=id2&name=name1&tags=tag1', cls=TargetGroup) assert len(response) == 1