Beispiel #1
0
def test_it_outputs_csv_to_file_without_entity_parent_id_for_projects(
        capsys, syn_test_helper, syn_project, syn_folder, syn_file,
        mk_tempdir):
    folder_team = syn_test_helper.create_team()
    file_team = syn_test_helper.create_team()
    SynapseProxy.client().setPermissions(
        syn_folder,
        folder_team.id,
        accessType=SynapseProxy.Permissions.CAN_EDIT_AND_DELETE,
        warn_if_inherits=False)
    SynapseProxy.client().setPermissions(
        syn_file,
        file_team.id,
        accessType=SynapseProxy.Permissions.CAN_EDIT_AND_DELETE,
        warn_if_inherits=False)

    out_file = os.path.join(mk_tempdir(), 'outfile.csv')
    report = BenefactorPermissionsReport(syn_project.id, out_path=out_file)
    report.execute()
    assert report._csv_full_path == out_file
    assert_success_from_print(capsys, syn_project)

    assert_success_from_csv(report._csv_full_path, syn_project, syn_folder,
                            syn_file)
    with open(out_file, newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if row['entity_type'] == 'Project':
                assert row['entity_parent_id'] == ''
            else:
                assert row['entity_parent_id'] == syn_project.id
Beispiel #2
0
def test__extract_concrete_type():
    assert SynapseProxy._extract_concrete_type(
        syn.Project()) == 'org.sagebionetworks.repo.model.Project'
    assert SynapseProxy._extract_concrete_type({
        'concreteType':
        'org.sagebionetworks.repo.model.Project'
    }) == 'org.sagebionetworks.repo.model.Project'
    assert SynapseProxy._extract_concrete_type({
        'type':
        'org.sagebionetworks.repo.model.Project'
    }) == 'org.sagebionetworks.repo.model.Project'

    with pytest.raises(ValueError) as err:
        SynapseProxy._extract_concrete_type({})
    assert 'Cannot extract type from' in str(err)
Beispiel #3
0
def test_it_reports_on_uniq_permissions(capsys, syn_project, syn_folder,
                                        syn_file, syn_test_helper):
    folder_team = syn_test_helper.create_team()
    file_team = syn_test_helper.create_team()
    SynapseProxy.client().setPermissions(
        syn_folder,
        folder_team.id,
        accessType=SynapseProxy.Permissions.CAN_EDIT_AND_DELETE,
        warn_if_inherits=False)
    SynapseProxy.client().setPermissions(
        syn_file,
        file_team.id,
        accessType=SynapseProxy.Permissions.CAN_EDIT_AND_DELETE,
        warn_if_inherits=False)
    BenefactorPermissionsReport(syn_project.name).execute()
    assert_success_from_print(capsys, syn_project, syn_folder, syn_file)
Beispiel #4
0
def assert_success_from_print(capsys, *entities):
    captured = capsys.readouterr()
    assert captured.err == ''
    for entity in entities:
        log_msg = '{0}: {1} ({2}) found.'.format(SynapseProxy.entity_type_display_name(entity),
                                                 entity.name,
                                                 entity.id)
        assert log_msg in captured.out
Beispiel #5
0
def test_with_cache_get_user(syn_test_helper):
    user_id = SynapseProxy.client().getUserProfile().get('ownerId')
    user = SynapseProxy.WithCache.get_user(user_id)
    assert user['ownerId'] == user_id

    # Returns None if the user does not exist
    assert SynapseProxy.WithCache.get_user('-9999999') is None
    assert SynapseProxy.WithCache.get_user('000') is None
    assert SynapseProxy.WithCache.get_user(
        syn_test_helper.uniq_name(prefix='notarealname')) is None
Beispiel #6
0
    def create_project(self, **kwargs):
        """Creates a new Project and adds it to the trash queue."""
        if 'name' not in kwargs:
            kwargs['name'] = self.uniq_name(prefix=kwargs.get('prefix', ''))

        kwargs.pop('prefix', None)

        project = SynapseProxy.client().store(Project(**kwargs))
        self.dispose_of(project)
        return project
Beispiel #7
0
    def create_file(self, **kwargs):
        """Creates a new File and adds it to the trash queue."""
        if 'name' not in kwargs:
            kwargs['name'] = self.uniq_name(prefix=kwargs.get('prefix', ''))

        kwargs.pop('prefix', None)

        file = SynapseProxy.client().store(File(**kwargs))
        self.dispose_of(file)
        return file
Beispiel #8
0
    def create_wiki(self, **kwargs):
        """Creates a new Wiki and adds it to the trash queue."""
        if 'title' not in kwargs:
            kwargs['title'] = self.uniq_name(prefix=kwargs.get('prefix', ''))
        kwargs.pop('prefix', None)

        if 'markdown' not in kwargs:
            kwargs['markdown'] = 'My Wiki {0}'.format(kwargs['title'])

        wiki = SynapseProxy.client().store(Wiki(**kwargs))
        self.dispose_of(wiki)
        return wiki
Beispiel #9
0
def test_is_synapse_id():
    assert SynapseProxy.is_synapse_id('SyN1230') is True
    assert SynapseProxy.is_synapse_id('  sYn1230  ') is True
    assert SynapseProxy.is_synapse_id('syn') is False
    assert SynapseProxy.is_synapse_id('syn 1230') is False
    assert SynapseProxy.is_synapse_id('1230') is False
    assert SynapseProxy.is_synapse_id('1230syn') is False
Beispiel #10
0
    def create_team(self, **kwargs):
        """Creates a new Team and adds it to the trash queue."""
        if 'name' not in kwargs:
            kwargs['name'] = self.uniq_name(prefix=kwargs.get('prefix', ''))

        kwargs.pop('prefix', None)

        team = SynapseProxy.client().store(Team(**kwargs))

        # Wait for the team to be available in Synapse.
        tries = 0
        while True:
            tries += 1
            try:
                SynapseProxy.client().getTeam(team.name)
                break
            except ValueError:
                if tries >= 10:
                    raise Exception('Timed out waiting for Team to be available in Synapse.')
                else:
                    time.sleep(3)

        self.dispose_of(team)
        return team
Beispiel #11
0
def test_with_cache_get_user_or_team(syn_test_helper):
    user_id = SynapseProxy.client().getUserProfile().get('ownerId')
    team_id = syn_test_helper.create_team().get('id')

    user = SynapseProxy.WithCache.get_user_or_team(user_id)
    assert isinstance(user, syn.UserProfile)
    assert user['ownerId'] == user_id

    team = SynapseProxy.WithCache.get_user_or_team(team_id)
    assert isinstance(team, syn.Team)
    assert team['id'] == team_id

    # Returns None if the user and team do not exist
    assert SynapseProxy.WithCache.get_user_or_team('-9999999') is None
    assert SynapseProxy.WithCache.get_user_or_team('000') is None
    assert SynapseProxy.WithCache.get_user_or_team(
        syn_test_helper.uniq_name(prefix='notarealname')) is None
    assert SynapseProxy.WithCache.get_user_or_team(
        syn_test_helper.uniq_name(prefix='notarealname')) is None
Beispiel #12
0
def test_is_file():
    assert SynapseProxy.is_file(
        'org.sagebionetworks.repo.model.FileEntity') is True
    assert SynapseProxy.is_file(syn.File(parentId='syn0')) is True
    assert SynapseProxy.is_file(
        {'concreteType': 'org.sagebionetworks.repo.model.FileEntity'}) is True
Beispiel #13
0
def test_is_folder():
    assert SynapseProxy.is_folder(
        'org.sagebionetworks.repo.model.Folder') is True
    assert SynapseProxy.is_folder(syn.Folder(parentId='syn0')) is True
    assert SynapseProxy.is_folder(
        {'concreteType': 'org.sagebionetworks.repo.model.Folder'}) is True
Beispiel #14
0
def test_is_project():
    assert SynapseProxy.is_project(
        'org.sagebionetworks.repo.model.Project') is True
    assert SynapseProxy.is_project(syn.Project()) is True
    assert SynapseProxy.is_project(
        {'concreteType': 'org.sagebionetworks.repo.model.Project'}) is True
Beispiel #15
0
def test_entity_type_display_name():
    assert SynapseProxy.entity_type_display_name(
        'org.sagebionetworks.repo.model.Project'
    ) == SynapseProxy.PROJECT_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name(
        syn.Project()) == SynapseProxy.PROJECT_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name({
        'concreteType':
        'org.sagebionetworks.repo.model.Project'
    }) == SynapseProxy.PROJECT_TYPE_DISPLAY_NAME

    assert SynapseProxy.entity_type_display_name(
        'org.sagebionetworks.repo.model.Folder'
    ) == SynapseProxy.FOLDER_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name(
        syn.Folder(parentId='syn0')) == SynapseProxy.FOLDER_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name({
        'concreteType':
        'org.sagebionetworks.repo.model.Folder'
    }) == SynapseProxy.FOLDER_TYPE_DISPLAY_NAME

    assert SynapseProxy.entity_type_display_name(
        'org.sagebionetworks.repo.model.FileEntity'
    ) == SynapseProxy.FILE_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name(
        syn.File(parentId='syn0')) == SynapseProxy.FILE_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name({
        'concreteType':
        'org.sagebionetworks.repo.model.FileEntity'
    }) == SynapseProxy.FILE_TYPE_DISPLAY_NAME

    assert SynapseProxy.entity_type_display_name(
        'org.sagebionetworks.repo.model.Link'
    ) == SynapseProxy.LINK_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name(
        syn.Link(parentId='syn0',
                 targetId='syn0')) == SynapseProxy.LINK_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name({
        'concreteType':
        'org.sagebionetworks.repo.model.Link'
    }) == SynapseProxy.LINK_TYPE_DISPLAY_NAME

    assert SynapseProxy.entity_type_display_name(
        'org.sagebionetworks.repo.model.table.TableEntity'
    ) == SynapseProxy.TABLE_TYPE_DISPLAY_NAME
    assert SynapseProxy.entity_type_display_name({
        'concreteType':
        'org.sagebionetworks.repo.model.table.TableEntity'
    }) == SynapseProxy.TABLE_TYPE_DISPLAY_NAME
Beispiel #16
0
    def dispose(self):
        """Cleans up any Synapse objects that were created during testing.

        This method needs to be manually called after each or all tests are done.
        """
        projects = []
        folders = []
        files = []
        teams = []
        wikis = []
        others = []

        for obj in self._trash:
            if isinstance(obj, Project):
                projects.append(obj)
            elif isinstance(obj, Folder):
                folders.append(obj)
            elif isinstance(obj, File):
                files.append(obj)
            elif isinstance(obj, Team):
                teams.append(obj)
            elif isinstance(obj, Wiki):
                wikis.append(obj)
            else:
                others.append(obj)

        for syn_obj in wikis:
            try:
                SynapseProxy.client().delete(syn_obj)
            except:
                pass
            self._trash.remove(syn_obj)

        for syn_obj in files:
            try:
                SynapseProxy.client().delete(syn_obj)
            except:
                pass
            self._trash.remove(syn_obj)

        for syn_obj in folders:
            try:
                SynapseProxy.client().delete(syn_obj)
            except:
                pass
            self._trash.remove(syn_obj)

        for syn_obj in projects:
            try:
                SynapseProxy.client().delete(syn_obj)
            except:
                pass
            self._trash.remove(syn_obj)

        for syn_obj in teams:
            try:
                SynapseProxy.client().delete(syn_obj)
            except:
                pass
            self._trash.remove(syn_obj)

        for obj in others:
            print('WARNING: Non-Supported object found: {0}'.format(obj))
            self._trash.remove(obj)
Beispiel #17
0
def syn_client():
    return SynapseProxy.client()