def test_create_group(mocker): target_group = TargetGroup.from_dict({ "name": "Fake Group", "id": "id123", "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, '_post', return_value=target_group) # run test response = GsGroupsApi.create_group(target_group) GsSession.current._post.assert_called_with('/groups', target_group, cls=TargetGroup) assert response.name == 'Fake Group'
def save(self): """ If the group id already exists in Marquee, update it. If not, create a new Marquee Group """ if self._group_exists(): _logger.info(f'Updating group "{self.id}"') result = GsGroupsApi.update_group(group_id=self.id, group=self.to_target()) else: _logger.info(f'Creating group "{self.id}"') result = GsGroupsApi.create_group(group=self.to_target()) return Group(group_id=result.id, name=result.name, entitlements=Entitlements.from_target(result.entitlements) if result.entitlements else None if result.entitlements else None, description=result.description, tags=result.tags)