Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_Entity():
# Update the project
project_name = str(uuid.uuid4())
project = Project(name=project_name)
project = syn.store(project)
schedule_for_cleanup(project)
project = syn.getEntity(project)
assert_equals(project.name, project_name)
# Create and get a Folder
folder = Folder('Test Folder', parent=project, description='A place to put my junk', foo=1000)
folder = syn.createEntity(folder)
folder = syn.getEntity(folder)
assert_equals(folder.name, 'Test Folder')
assert_equals(folder.parentId, project.id)
assert_equals(folder.description, 'A place to put my junk')
assert_equals(folder.foo[0], 1000)
# Update and get the Folder
folder.pi = 3.14159265359
folder.description = 'The rejects from the other folder'
folder = syn.store(folder)
folder = syn.get(folder)
assert_equals(folder.name, 'Test Folder')
assert_equals(folder.parentId, project.id)
assert_equals(folder.description, 'The rejects from the other folder')
assert_equals(folder.pi[0], 3.14159265359)
def test_special_characters():
folder = syn.store(Folder(u'Special Characters Here',
parent=project,
description=u'A test for special characters such as Déjà vu, ประเทศไทย, and 中国',
hindi_annotation=u'बंदर बट',
russian_annotation=u'Обезьяна прикладом',
weird_german_thing=u'Völlerei lässt grüßen'))
assert_equals(folder.name, u'Special Characters Here')
assert_equals(folder.parentId, project.id)
assert_equals(folder.description, u'A test for special characters such as Déjà vu, ประเทศไทย, and 中国',
u'description= %s' % folder.description)
assert_equals(folder.weird_german_thing[0], u'Völlerei lässt grüßen')
assert_equals(folder.hindi_annotation[0], u'बंदर बट')
assert_equals(folder.russian_annotation[0], u'Обезьяна прикладом')
def test_syncFromSynapse__empty_folder():
folder = Folder(name="the folder", parent="whatever", id="syn123")
with patch.object(syn, "getChildren", return_value=[]),\
patch.object(syn, "get", return_value=Folder(name="asssdfa", parent="whatever")):
assert_equals(list(), synapseutils.syncFromSynapse(syn, folder))
def test_syncFromSynapse__empty_folder():
folder = Folder(name="the folder", parent="whatever", id="syn123")
with patch.object(syn, "getChildren", return_value=[]),\
patch.object(syn, "get", return_value=Folder(name="asssdfa", parent="whatever")):
assert_equals(list(), synapseutils.syncFromSynapse(syn, folder))
def test_Entity():
# Update the project
project_name = str(uuid.uuid4())
project = Project(name=project_name)
project = syn.store(project)
schedule_for_cleanup(project)
project = syn.getEntity(project)
assert_equals(project.name, project_name)
# Create and get a Folder
folder = Folder('Test Folder', parent=project, description='A place to put my junk', foo=1000)
folder = syn.createEntity(folder)
folder = syn.getEntity(folder)
assert_equals(folder.name, 'Test Folder')
assert_equals(folder.parentId, project.id)
assert_equals(folder.description, 'A place to put my junk')
assert_equals(folder.foo[0], 1000)
# Update and get the Folder
folder.pi = 3.14159265359
folder.description = 'The rejects from the other folder'
folder = syn.store(folder)
folder = syn.get(folder)
assert_equals(folder.name, 'Test Folder')
assert_equals(folder.parentId, project.id)
assert_equals(folder.description, 'The rejects from the other folder')
assert_equals(folder.pi[0], 3.14159265359)
def test_copy():
"""Tests the copy function"""
# Create a Project
project_entity = syn.store(Project(name=str(uuid.uuid4())))
schedule_for_cleanup(project_entity.id)
# Create two Folders in Project
folder_entity = syn.store(Folder(name=str(uuid.uuid4()), parent=project_entity))
second_folder = syn.store(Folder(name=str(uuid.uuid4()), parent=project_entity))
third_folder = syn.store(Folder(name=str(uuid.uuid4()), parent=project_entity))
schedule_for_cleanup(folder_entity.id)
schedule_for_cleanup(second_folder.id)
schedule_for_cleanup(third_folder.id)
# Annotations and provenance
repo_url = 'https://github.com/Sage-Bionetworks/synapsePythonClient'
annos = {'test': ['hello_world']}
prov = Activity(name="test", used=repo_url)
# Create, upload, and set annotations/provenance on a file in Folder
filename = utils.make_bogus_data_file()
schedule_for_cleanup(filename)
file_entity = syn.store(File(filename, parent=folder_entity))
externalURL_entity = syn.store(File(repo_url, name='rand', parent=folder_entity, synapseStore=False))
syn.setAnnotations(file_entity, annos)
setProvenance = kwargs.get('setProvenance', "traceback")
excludeTypes = kwargs.get('excludeTypes', [])
updateExisting = kwargs.get('updateExisting', False)
if mapping is None:
mapping = dict()
# Check that passed in excludeTypes is file, table, and link
if not isinstance(excludeTypes, list):
raise ValueError("Excluded types must be a list")
elif not all([i in ["file", "link", "table"] for i in excludeTypes]):
raise ValueError("Excluded types can only be a list of these values: file, table, and link")
ent = syn.get(entity, downloadFile=False)
if ent.id == destinationId:
raise ValueError("destinationId cannot be the same as entity id")
if (isinstance(ent, Project) or isinstance(ent, Folder)) and version is not None:
raise ValueError("Cannot specify version when copying a project of folder")
if not isinstance(ent, (Project, Folder, File, Link, Schema, Entity)):
raise ValueError("Not able to copy this type of file")
profile_username = syn.username
permissions = syn.getPermissions(ent, profile_username)
# Don't copy entities without DOWNLOAD permissions
if "DOWNLOAD" not in permissions:
print("%s not copied - this file lacks download permission" % ent.id)
return mapping
access_requirements = syn.restGET('/entity/{}/accessRequirement'.format(ent.id))
# If there are any access requirements, don't copy files
if access_requirements['results']:
print("{} not copied - this file has access restrictions".format(ent.id))
def synapseStoreFolder(dir_path,parent_syn):
data_folder = synapseclient.Folder(dir_path, parent=parent_syn)
data_folder = syn.store(data_folder)
sub_parent = data_folder.id
return sub_parent
if mapping is None:
mapping = dict()
# Check that passed in excludeTypes is file, table, and link
if not isinstance(excludeTypes, list):
raise ValueError("Excluded types must be a list")
elif not all([i in ["file", "link", "table"] for i in excludeTypes]):
raise ValueError("Excluded types can only be a list of these values: file, table, and link")
ent = syn.get(entity, downloadFile=False)
if ent.id == destinationId:
raise ValueError("destinationId cannot be the same as entity id")
if (isinstance(ent, Project) or isinstance(ent, Folder)) and version is not None:
raise ValueError("Cannot specify version when copying a project of folder")
if not isinstance(ent, (Project, Folder, File, Link, Schema, Entity)):
raise ValueError("Not able to copy this type of file")
profile_username = syn.username
permissions = syn.getPermissions(ent, profile_username)
# Don't copy entities without DOWNLOAD permissions
if "DOWNLOAD" not in permissions:
print("%s not copied - this file lacks download permission" % ent.id)
return mapping
access_requirements = syn.restGET('/entity/{}/accessRequirement'.format(ent.id))
# If there are any access requirements, don't copy files
if access_requirements['results']:
print("{} not copied - this file has access restrictions".format(ent.id))
return mapping
copiedId = None