def create_team(syn, team_name, desc, can_public_join=False): ''' Convenience function to create Synapse Team Args: syn: Synpase object team_name: Name of team desc: Description of team can_public_join: true for teams which members can join without an invitation or approval. Default to False Returns: Synapse Team id ''' try: # raises a ValueError if a team does not exist team = syn.getTeam(team_name) logger.info('The team %s already exists.' % team_name) logger.info(team) user_input = input('Do you want to use this team? (Y/n) ') or 'y' if user_input.lower() not in ('y', 'yes'): logger.info('Please specify another team. Exiting.') sys.exit(1) except ValueError: team = synapseclient.Team(name=team_name, description=desc, canPublicJoin=can_public_join) # raises a ValueError if a team with this name already exists team = syn.store(team) logger.info('Created Team %s (%s)' % (team.name, team.id)) return (team.id)
def test__create_synapse_resources_team(self): """Test team gets created""" team_config = [{ 'name': 'Test Configuration', 'type': 'Team', 'can_public_join': False, 'description': 'Test team description' }] expected_config = [{ 'name': 'Test Configuration', 'type': 'Team', 'can_public_join': False, 'description': 'Test team description', 'id': '11111' }] team_ent = synapseclient.Team(id="11111") with patch.object(self.create_cls, "get_or_create_team", return_value=team_ent) as patch_create: client._create_synapse_resources(config_list=team_config, creation_cls=self.create_cls) patch_create.assert_called_once_with( name=team_config[0]['name'], description=team_config[0]['description'], canPublicJoin=team_config[0]['can_public_join'] ) assert team_config == expected_config
def test__create_synapse_resources_team_invite(self): """Test team members are invited""" team_config = [{ 'name': 'Test Configuration', 'type': 'Team', 'can_public_join': False, 'description': 'Test team description', 'invitations': [ { 'message': 'Welcome to the Test Team!', 'members': [ {"principal_id": 3426116}, {"email": "*****@*****.**"} ] } ] }] team_ent = synapseclient.Team(id="11111") expected_calls = [ mock.call(team=team_ent, user=3426116, inviteeEmail=None, message='Welcome to the Test Team!'), mock.call(team=team_ent, user=None, inviteeEmail="*****@*****.**", message='Welcome to the Test Team!') ] with patch.object(self.create_cls, "get_or_create_team", return_value=team_ent) as patch_create,\ patch.object(self.create_cls.syn, "invite_to_team") as patch_invite: client._create_synapse_resources(config_list=team_config, creation_cls=self.create_cls) patch_invite.assert_has_calls(expected_calls)
def create_team(syn, team_name, desc, can_public_join=False): """Creates Synapse Team Args: syn: Synpase object team_name: Name of team desc: Description of team can_public_join: true for teams which members can join without an invitation or approval. Default to False Returns: Synapse Team id """ try: # raises a ValueError if a team does not exist team = syn.getTeam(team_name) logger.info('The team {} already exists.'.format(team_name)) logger.info(team) # If you press enter, this will default to 'y' user_input = input('Do you want to use this team? (Y/n) ') or 'y' if user_input.lower() not in ('y', 'yes'): logger.info('Please specify a new challenge name. Exiting.') sys.exit(1) except ValueError: team = synapseclient.Team(name=team_name, description=desc, canPublicJoin=can_public_join) # raises a ValueError if a team with this name already exists team = syn.store(team) logger.info('Created Team {} ({})'.format(team.name, team.id)) return team
def test_remove_team_member(self): team = synapseclient.Team(id=123) user = synapseclient.UserProfile(ownerId=2222) with patch.object(self.syn, "restDELETE") as patch_rest: teams.remove_team_member(self.syn, team, user) patch_rest.assert_called_once_with("/team/123/member/2222")
def createTeam(syn, name, *args, **kwargs): """Create an empty team.""" try: return syn.getTeam(name) except ValueError: sys.stderr.write("Can't find team \"%s\", creating it.\n" % name) return syn.store(synapseclient.Team(name=name, *args, **kwargs))
def test_get_or_create_team__call(): """Tests creation of team""" team_name = str(uuid.uuid1()) description = str(uuid.uuid1()) public_join = True team_ent = synapseclient.Team(name=team_name, description=description, canPublicJoin=public_join) returned = synapseclient.Team(name=team_name, description=description, id=str(uuid.uuid1()), canPublicJoin=public_join) with patch.object(CREATE_CLS, "_find_by_obj_or_create", return_value=returned) as patch_find_or_create: new_team = CREATE_CLS.get_or_create_team(name=team_name, description=description, canPublicJoin=public_join) assert new_team == returned patch_find_or_create.assert_called_once_with(team_ent)
def test_existing_create_team(): """Tests existing challenge widget""" team_name = str(uuid.uuid1()) desc = str(uuid.uuid1()) can_public_join = True expected_team = synapseclient.Team(name=team_name, description=desc, canPublicJoin=can_public_join, id=1111) with patch.object(SYN, "getTeam", return_value=expected_team) as patch_get,\ patch("builtins.input", return_value="y"): team = createchallenge.create_team(SYN, team_name, desc, can_public_join=can_public_join) assert team == expected_team patch_get.assert_called_once_with(team_name)
def create_team(syn, team_name, desc, can_public_join): team = syn.store(synapseclient.Team(name=team_name, description=desc, canPublicJoin=can_public_join)) logger.info("Created Team %s(%s)" % (team.name, team.id)) return(team.id)
synapseclient.Schema(name="foo", parentId="syn12345")] ) def test__get_obj__entity(obj): """Test getting of entities""" with patch.object(GET_CLS, "_find_entity_by_name", return_value=obj) as patch_get: return_obj = GET_CLS._get_obj(obj) patch_get.assert_called_once_with( parentid=obj.properties.get("parentId", None), entity_name=obj.name, concrete_type=obj.properties.concreteType) assert obj == return_obj @pytest.mark.parametrize("obj,get_func", [(synapseclient.Team(name="foo"), "getTeam"), (synapseclient.Wiki(owner="foo"), "getWiki"), (synapseclient.Evaluation(name="foo", contentSource="syn123"), "getEvaluationByName")]) def test__get_obj__nonentity(obj, get_func): """Test getting of entities""" with patch.object(SYN, get_func, return_value=obj) as patch_get: return_obj = GET_CLS._get_obj(obj) if isinstance(obj, (synapseclient.Team, synapseclient.Evaluation)): patch_get.assert_called_once_with(obj.name) elif isinstance(obj, synapseclient.Wiki): patch_get.assert_called_once_with(obj.ownerId) assert return_obj == obj