def test_annotations(): # Get the annotations of an Entity entity = syn.store(Folder(parent=project['id'])) anno = syn.getAnnotations(entity) assert hasattr(anno, 'id') assert hasattr(anno, 'etag') assert anno.id == entity.id assert anno.etag == entity.etag # Set the annotations, with keywords too anno['bogosity'] = 'total' syn.setAnnotations(entity, anno, wazoo='Frank', label='Barking Pumpkin', shark=16776960) # Check the update annote = syn.getAnnotations(entity) assert annote['bogosity'] == ['total'] assert annote['wazoo'] == ['Frank'] assert annote['label'] == ['Barking Pumpkin'] assert annote['shark'] == [16776960] # More annotation setting annote['primes'] = [2,3,5,7,11,13,17,19,23,29] annote['phat_numbers'] = [1234.5678, 8888.3333, 1212.3434, 6677.8899] annote['goobers'] = ['chris', 'jen', 'jane'] annote['present_time'] = datetime.now() syn.setAnnotations(entity, annote) # Check it again annotation = syn.getAnnotations(entity) assert annotation['primes'] == [2,3,5,7,11,13,17,19,23,29] assert annotation['phat_numbers'] == [1234.5678, 8888.3333, 1212.3434, 6677.8899] assert annotation['goobers'] == ['chris', 'jen', 'jane'] assert annotation['present_time'][0].strftime('%Y-%m-%d %H:%M:%S') == annote['present_time'].strftime('%Y-%m-%d %H:%M:%S')
def test_chunked_query(): oldLimit = synapseclient.client.QUERY_LIMIT try: synapseclient.client.QUERY_LIMIT = 3 time.sleep(3) # Remove all the Entities that are in the project iter = syn.chunkedQuery("select id from entity where entity.parentId=='%s'" % project['id']) for res in iter: syn.delete(res['entity.id']) # Dump a bunch of Entities into the project for i in range(synapseclient.client.QUERY_LIMIT * 5): syn.store(Folder(parent=project['id'])) time.sleep(3) # Give a bunch of limits/offsets to be ignored (except for the first ones) queryString = "select * from entity where entity.parentId=='%s' offset 1 limit 9999999999999 offset 2345 limit 6789 offset 3456 limit 5689" % project['id'] count = 0 start_time = time.time() while count != (synapseclient.client.QUERY_LIMIT * 5): assert_less(time.time() - start_time, QUERY_TIMEOUT_SEC) time.sleep(2) iter = syn.chunkedQuery(queryString) count = 0 for res in iter: count += 1 assert count == (synapseclient.client.QUERY_LIMIT * 5) finally: synapseclient.client.QUERY_LIMIT = oldLimit
def test_getChildren(): # setup a hierarchy for folders # PROJECT # | \ # File Folder # | # File project_name = str(uuid.uuid1()) test_project = syn.store(Project(name=project_name)) folder = syn.store(Folder(name="firstFolder", parent=test_project)) syn.store( File(path="~/doesntMatter.txt", name="file inside folders", parent=folder, synapseStore=False)) project_file = syn.store( File(path="~/doesntMatterAgain.txt", name="file inside project", parent=test_project, synapseStore=False)) schedule_for_cleanup(test_project) expected_id_set = {project_file.id, folder.id} children_id_set = {x['id'] for x in syn.getChildren(test_project.id)} assert_equals(expected_id_set, children_id_set)
def test_chunked_query_giant_row(): import synapseclient.utils as utils absurdly_long_desription = 'This is an absurdly long description!' + '~'*512000 normal = syn.store(Folder('normal', description='A file with a normal length description', parentId=project['id'])) absurd = syn.store(Folder('absurd', description=absurdly_long_desription, parentId=project['id'])) ## the expected behavior is that the absurdly long row will be skipped ## but the normal row will be returned start_time = time.time() ids = [] while normal.id not in ids: assert_less(time.time() - start_time, QUERY_TIMEOUT_SEC) time.sleep(2) resultgen = syn.chunkedQuery('select * from entity where parentId=="%s"' % project['id']) ids = [result['entity.id'] for result in resultgen]
def test_entity_constructors(): project = Project(name=str(uuid.uuid4()), description='Testing 123') folder = Folder(name='Musicians', parent=project, genre='Jazz', datatype='personnel') personnel_file = File(fname, parentId=folder.id, group='Miles Davis Quintet', album='Stockholm 1960 Complete')
def test_query(): ## TODO: replace this test with the one below when query() is replaced # Remove all the Entities that are in the project qry = syn.query("select id from entity where entity.parentId=='%s'" % project['id']) for res in qry['results']: syn.delete(res['entity.id']) # Add entities and verify that I can find them with a query for i in range(2): syn.store(Folder(parent=project['id'])) qry = syn.query( "select id, name from entity where entity.parentId=='%s'" % project['id']) assert qry['totalNumberOfResults'] == i + 1
def test_entity_constructors(): project = Project('TestProject', id='syn1001', foo='bar') assert project.name == 'TestProject' assert project['foo'] == 'bar' folder = Folder('MyFolder', parent=project, foo='bat', id='syn1002') assert folder.name == 'MyFolder' assert folder.foo == 'bat' assert folder.parentId == 'syn1001' a_file = File('/path/to/fabulous_things.zzz', parent=folder, foo='biz') #assert a_file.name == 'fabulous_things.zzz' assert a_file.entityType == 'org.sagebionetworks.repo.model.FileEntity' assert a_file.path == '/path/to/fabulous_things.zzz' assert a_file.foo == 'biz' assert a_file.parentId == 'syn1002'
def test_entity_constructors(): project = Project('TestProject', id='syn1001', foo='bar') assert project.name == 'TestProject' assert project['foo'] == 'bar' folder = Folder('MyFolder', parent=project, foo='bat', id='syn1002') assert folder.name == 'MyFolder' assert folder.foo == 'bat' assert folder.parentId == 'syn1001' a_file = File('/path/to/fabulous_things.zzz', parent=folder, foo='biz', contentType='application/cattywampus') #assert a_file.name == 'fabulous_things.zzz' assert a_file.concreteType == 'org.sagebionetworks.repo.model.FileEntity' assert a_file.path == '/path/to/fabulous_things.zzz' assert a_file.foo == 'biz' assert a_file.parentId == 'syn1002' assert a_file.contentType == 'application/cattywampus' assert 'contentType' in a_file.__dict__
def test_entity_constructors(): project = Project('TestProject', id='syn1001', foo='bar') assert_equals(project.name, 'TestProject') assert_equals(project['foo'], 'bar') folder = Folder('MyFolder', parent=project, foo='bat', id='syn1002') assert_equals(folder.name, 'MyFolder') assert_equals(folder.foo, 'bat') assert_equals(folder.parentId, 'syn1001') a_file = File('/path/to/fabulous_things.zzz', parent=folder, foo='biz', contentType='application/cattywampus') assert_equals(a_file.concreteType, 'org.sagebionetworks.repo.model.FileEntity') assert_equals(a_file.path, '/path/to/fabulous_things.zzz') assert_equals(a_file.foo, 'biz') assert_equals(a_file.parentId, 'syn1002') assert_equals(a_file.contentType, 'application/cattywampus') assert_in('contentType', a_file._file_handle)
def test_query(): ## TODO: replace this test with the one below when query() is replaced query_str = "select id from entity where entity.parentId=='%s'" % project['id'] # Remove all the Entities that are in the project qry = syn.query(query_str) while len(qry['results']) > 0: for res in qry['results']: syn.delete(res['entity.id']) qry = syn.query(query_str) # Add entities and verify that I can find them with a query for i in range(2): syn.store(Folder(parent=project['id'])) start_time = time.time() qry = syn.query(query_str) while len(qry['results']) != i + 1: assert_less(time.time() - start_time, QUERY_TIMEOUT_SEC) time.sleep(2) qry = syn.query(query_str) assert len(qry['results']) == i + 1
def test_is_container(): ## result from a Synapse entity annotation query ## Note: prefix may be capitalized or not, depending on the from clause of the query result = { 'entity.versionNumber': 1, 'entity.nodeType': 'project', 'entity.concreteType': ['org.sagebionetworks.repo.model.Project'], 'entity.createdOn': 1451512703905, 'entity.id': 'syn5570912', 'entity.name': 'blah' } assert is_container(result) result = { 'Entity.nodeType': 'project', 'Entity.id': 'syn5570912', 'Entity.name': 'blah' } assert is_container(result) result = { 'entity.concreteType': ['org.sagebionetworks.repo.model.Folder'], 'entity.id': 'syn5570914', 'entity.name': 'flapdoodle' } assert is_container(result) result = { 'File.concreteType': ['org.sagebionetworks.repo.model.FileEntity'], 'File.id': 'syn5570914', 'File.name': 'flapdoodle' } assert not is_container(result) assert is_container(Folder("Stuff", parentId="syn12345")) assert is_container(Project("My Project", parentId="syn12345")) assert not is_container(File("asdf.png", parentId="syn12345"))