def test_teams(syn, project, schedule_for_cleanup): name = "My Uniquely Named Team " + str(uuid.uuid4()) team = syn.store(Team(name=name, description="A fake team for testing...")) schedule_for_cleanup(team) # not logged in, teams are public anonymous_syn = Synapse() found_team = anonymous_syn.getTeam(team.id) assert team == found_team p = syn.getUserProfile() found = None for m in anonymous_syn.getTeamMembers(team): if m.member.ownerId == p.ownerId: found = m break assert found is not None, "Couldn't find user {} in team".format( p.userName) # needs to be retried 'cause appending to the search index is asynchronous tries = 8 sleep_time = 1 found_team = None while tries > 0: try: found_team = anonymous_syn.getTeam(name) break except ValueError: tries -= 1 if tries > 0: time.sleep(sleep_time) sleep_time *= 2 assert team == found_team
def get_team_count(syn: Synapse, team: Union[int, str, Team]) -> int: """Get number of team members Args: syn: Synapse object team: synaspeclient.Team, its id, or name. """ team_obj = syn.getTeam(team) count = _get_team_count(syn, team_obj.id) return count['count']
def main(): # Parse command-line arguments args = parse_arguments() # Set up Synapse syn = Synapse() syn.login(args.username, args.password, rememberMe=args.remember) # Retrieve Synapse entity (e.g., project, folder) entity = syn.get(args.synid, downloadFile=False) log("Entity", entity) # Retrieve team team = syn.getTeam(args.team) # TODO: Handle users with try-catch log("Team", team) # Assign specified permissions for given entity and team permissions = syn.setPermissions(entity, team.id, accessType=args.permissions) log("Permissions", permissions) # Celebrate print("Success!")