def test_entity_creation(): props = { "id": "syn123456", "concreteType": "org.sagebionetworks.repo.model.Folder", "parentId": "syn445566", "name": "Testing123" } annos = {'testing': 123} folder = Entity.create(props, annos) assert folder.concreteType == 'org.sagebionetworks.repo.model.Folder' assert folder.__class__ == Folder assert folder.name == 'Testing123' assert folder.testing == 123 ## In case of unknown concreteType, fall back on generic Entity object props = { "id": "syn123456", "concreteType": "org.sagebionetworks.repo.model.DoesntExist", "parentId": "syn445566", "name": "Whatsits" } whatsits = Entity.create(props) assert whatsits.concreteType == 'org.sagebionetworks.repo.model.DoesntExist' assert whatsits.__class__ == Entity
def test_entity_creation(): props = { "id": "syn123456", "concreteType": "org.sagebionetworks.repo.model.Folder", "parentId": "syn445566", "name": "Testing123" } annos = {'testing':123} folder = Entity.create(props, annos) assert folder.concreteType == 'org.sagebionetworks.repo.model.Folder' assert folder.__class__ == Folder assert folder.name == 'Testing123' assert folder.testing == 123 ## In case of unknown concreteType, fall back on generic Entity object props = { "id": "syn123456", "concreteType": "org.sagebionetworks.repo.model.DoesntExist", "parentId": "syn445566", "name": "Whatsits" } whatsits = Entity.create(props) assert whatsits.concreteType == 'org.sagebionetworks.repo.model.DoesntExist' assert whatsits.__class__ == Entity
def test_entity_creation(): props = { "id": "syn123456", "entityType": "org.sagebionetworks.repo.model.Folder", "parentId": "syn445566", "name": "Testing123" } annos = {'testing':123} folder = Entity.create(props, annos) assert folder.entityType == 'org.sagebionetworks.repo.model.Folder' assert folder.__class__ == Folder assert folder.name == 'Testing123' assert folder.testing == 123 props = { "id": "syn123456", "entityType": "org.sagebionetworks.repo.model.DoesntExist", "name": "Whatsits" } whatsits = Entity.create(props) assert whatsits.entityType == 'org.sagebionetworks.repo.model.DoesntExist' assert whatsits.__class__ == Entity
def test_entity_creation(): props = { "id": "syn123456", "entityType": "org.sagebionetworks.repo.model.Folder", "parentId": "syn445566", "name": "Testing123" } annos = {'testing': 123} folder = Entity.create(props, annos) assert folder.entityType == 'org.sagebionetworks.repo.model.Folder' assert folder.__class__ == Folder assert folder.name == 'Testing123' assert folder.testing == 123 props = { "id": "syn123456", "entityType": "org.sagebionetworks.repo.model.DoesntExist", "name": "Whatsits" } whatsits = Entity.create(props) assert whatsits.entityType == 'org.sagebionetworks.repo.model.DoesntExist' assert whatsits.__class__ == Entity
def test_split_entity_namespaces(): """Test split_entity_namespaces""" e = { 'concreteType': 'org.sagebionetworks.repo.model.Folder', 'name': 'Henry', 'color': 'blue', 'foo': 1234, 'parentId': 'syn1234' } (properties, annotations, local_state) = split_entity_namespaces(e) assert set(properties.keys()) == set(['concreteType', 'name', 'parentId']) assert properties['name'] == 'Henry' assert set(annotations.keys()) == set(['color', 'foo']) assert annotations['foo'] == 1234 assert len(local_state) == 0 e = { 'concreteType': 'org.sagebionetworks.repo.model.FileEntity', 'name': 'Henry', 'color': 'blue', 'foo': 1234, 'parentId': 'syn1234', 'dataFileHandleId': 54321, 'cacheDir': '/foo/bar/bat', 'files': ['foo.xyz'], 'path': '/foo/bar/bat/foo.xyz' } (properties, annotations, local_state) = split_entity_namespaces(e) assert set(properties.keys()) == set( ['concreteType', 'name', 'parentId', 'dataFileHandleId']) assert properties['name'] == 'Henry' assert properties['dataFileHandleId'] == 54321 assert set(annotations.keys()) == set(['color', 'foo']) assert annotations['foo'] == 1234 assert set(local_state.keys()) == set(['cacheDir', 'files', 'path']) assert local_state['cacheDir'] == '/foo/bar/bat' f = Entity.create(properties, annotations, local_state) assert f.properties.dataFileHandleId == 54321 assert f.properties.name == 'Henry' assert f.annotations.foo == 1234 assert f.__dict__['cacheDir'] == '/foo/bar/bat' assert f.__dict__['path'] == '/foo/bar/bat/foo.xyz'
def test_split_entity_namespaces(): """Test split_entity_namespaces""" e = { 'concreteType': 'org.sagebionetworks.repo.model.Folder', 'name': 'Henry', 'color': 'blue', 'foo': 1234, 'parentId': 'syn1234' } (properties, annotations, local_state) = split_entity_namespaces(e) assert_equals(set(properties.keys()), {'concreteType', 'name', 'parentId'}) assert_equals(properties['name'], 'Henry') assert_equals(set(annotations.keys()), {'color', 'foo'}) assert_equals(annotations['foo'], 1234) assert_equals(len(local_state), 0) e = { 'concreteType': 'org.sagebionetworks.repo.model.FileEntity', 'name': 'Henry', 'color': 'blue', 'foo': 1234, 'parentId': 'syn1234', 'dataFileHandleId': 54321, 'cacheDir': '/foo/bar/bat', 'files': ['foo.xyz'], 'path': '/foo/bar/bat/foo.xyz' } (properties, annotations, local_state) = split_entity_namespaces(e) assert_equals(set(properties.keys()), {'concreteType', 'name', 'parentId', 'dataFileHandleId'}) assert_equals(properties['name'], 'Henry') assert_equals(properties['dataFileHandleId'], 54321) assert_equals(set(annotations.keys()), {'color', 'foo'}) assert_equals(annotations['foo'], 1234) assert_equals(set(local_state.keys()), {'cacheDir', 'files', 'path'}) assert_equals(local_state['cacheDir'], '/foo/bar/bat') f = Entity.create(properties, annotations, local_state) assert_equals(f.properties.dataFileHandleId, 54321) assert_equals(f.properties.name, 'Henry') assert_equals(f.annotations.foo, 1234) assert_equals(f.__dict__['cacheDir'], '/foo/bar/bat') assert_equals(f.__dict__['path'], '/foo/bar/bat/foo.xyz')
def test_split_entity_namespaces(): """Test split_entity_namespaces""" e = {'concreteType':'org.sagebionetworks.repo.model.Folder', 'name':'Henry', 'color':'blue', 'foo':1234, 'parentId':'syn1234'} (properties,annotations,local_state) = split_entity_namespaces(e) assert set(properties.keys()) == set(['concreteType', 'name', 'parentId']) assert properties['name'] == 'Henry' assert set(annotations.keys()) == set(['color', 'foo']) assert annotations['foo'] == 1234 assert len(local_state) == 0 e = {'concreteType':'org.sagebionetworks.repo.model.FileEntity', 'name':'Henry', 'color':'blue', 'foo':1234, 'parentId':'syn1234', 'dataFileHandleId':54321, 'cacheDir':'/foo/bar/bat', 'files':['foo.xyz'], 'path':'/foo/bar/bat/foo.xyz'} (properties,annotations,local_state) = split_entity_namespaces(e) assert set(properties.keys()) == set(['concreteType', 'name', 'parentId', 'dataFileHandleId']) assert properties['name'] == 'Henry' assert properties['dataFileHandleId'] == 54321 assert set(annotations.keys()) == set(['color', 'foo']) assert annotations['foo'] == 1234 assert set(local_state.keys()) == set(['cacheDir', 'files', 'path']) assert local_state['cacheDir'] == '/foo/bar/bat' f = Entity.create(properties,annotations,local_state) assert f.properties.dataFileHandleId == 54321 assert f.properties.name == 'Henry' assert f.annotations.foo == 1234 assert f.__dict__['cacheDir'] == '/foo/bar/bat' assert f.__dict__['path'] == '/foo/bar/bat/foo.xyz'
def test_split_entity_namespaces(): """Test split_entity_namespaces""" e = {'concreteType': 'org.sagebionetworks.repo.model.Folder', 'name': 'Henry', 'color': 'blue', 'foo': 1234, 'parentId': 'syn1234'} (properties, annotations, local_state) = split_entity_namespaces(e) assert_equals(set(properties.keys()), {'concreteType', 'name', 'parentId'}) assert_equals(properties['name'], 'Henry') assert_equals(set(annotations.keys()), {'color', 'foo'}) assert_equals(annotations['foo'], 1234) assert_equals(len(local_state), 0) e = {'concreteType': 'org.sagebionetworks.repo.model.FileEntity', 'name': 'Henry', 'color': 'blue', 'foo': 1234, 'parentId': 'syn1234', 'dataFileHandleId': 54321, 'cacheDir': '/foo/bar/bat', 'files': ['foo.xyz'], 'path': '/foo/bar/bat/foo.xyz'} (properties, annotations, local_state) = split_entity_namespaces(e) assert_equals(set(properties.keys()), {'concreteType', 'name', 'parentId', 'dataFileHandleId'}) assert_equals(properties['name'], 'Henry') assert_equals(properties['dataFileHandleId'], 54321) assert_equals(set(annotations.keys()), {'color', 'foo'}) assert_equals(annotations['foo'], 1234) assert_equals(set(local_state.keys()), {'cacheDir', 'files', 'path'}) assert_equals(local_state['cacheDir'], '/foo/bar/bat') f = Entity.create(properties, annotations, local_state) assert_equals(f.properties.dataFileHandleId, 54321) assert_equals(f.properties.name, 'Henry') assert_equals(f.annotations.foo, 1234) assert_equals(f.__dict__['cacheDir'], '/foo/bar/bat') assert_equals(f.__dict__['path'], '/foo/bar/bat/foo.xyz')
def test_Entity(): # Test the basics of creating and accessing properties on an entity for i in range(2): e = Entity(name='Test object', description='I hope this works', annotations = dict(foo=123, nerds=['chris','jen','janey'], annotations='How confusing!'), properties = dict(annotations='/repo/v1/entity/syn1234/annotations', md5='cdef636522577fc8fb2de4d95875b27c', parentId='syn1234'), concreteType='org.sagebionetworks.repo.model.Data') # Should be able to create an Entity from an Entity if i == 1: e = Entity.create(e) assert e.parentId == 'syn1234' assert e['parentId'] == 'syn1234' assert e.properties['parentId'] == 'syn1234' assert e.properties.parentId =='syn1234' assert e.foo == 123 assert e['foo'] == 123 assert e.annotations['foo'] == 123 assert e.annotations.foo == 123 # Annotations is a bit funny, because there is a property call # 'annotations', which will be masked by a member of the object # called 'annotations'. Because annotations are open-ended, we # might even have an annotations called 'annotations', which gets # really confusing. assert isinstance(e.annotations, collections.Mapping) assert isinstance(e['annotations'], collections.Mapping) assert e.properties['annotations'] == '/repo/v1/entity/syn1234/annotations' assert e.properties.annotations == '/repo/v1/entity/syn1234/annotations' assert e.annotations.annotations == 'How confusing!' assert e.annotations['annotations'] == 'How confusing!' assert e.nerds == ['chris','jen','janey'] assert all([ k in e for k in ['name', 'description', 'foo', 'nerds', 'annotations', 'md5', 'parentId']]) # Test modifying properties e.description = 'Working, so far' assert e['description'] == 'Working, so far' e['description'] = 'Wiz-bang flapdoodle' assert e.description == 'Wiz-bang flapdoodle' # Test modifying annotations e.foo = 999 assert e.annotations['foo'] == 999 e['foo'] = 12345 assert e.annotations.foo == 12345 # Test creating a new annotation e['bar'] = 888 assert e.annotations['bar'] == 888 e['bat'] = 7788 assert e.annotations['bat'] == 7788 # Test replacing annotations object e.annotations = {'splat':'a totally new set of annotations', 'foo':456} assert e.foo == 456 assert e['foo'] == 456 assert isinstance(e.annotations, collections.Mapping) assert isinstance(e['annotations'], collections.Mapping) assert e.annotations.foo == 456 assert e.properties['annotations'] == '/repo/v1/entity/syn1234/annotations' assert e.properties.annotations == '/repo/v1/entity/syn1234/annotations'
def test_Entity(): # Test the basics of creating and accessing properties on an entity for i in range(2): e = Entity(name='Test object', description='I hope this works', annotations=dict(foo=123, nerds=['chris', 'jen', 'janey'], annotations='How confusing!'), properties=dict( annotations='/repo/v1/entity/syn1234/annotations', md5='cdef636522577fc8fb2de4d95875b27c', parentId='syn1234'), concreteType='org.sagebionetworks.repo.model.Data') # Should be able to create an Entity from an Entity if i == 1: e = Entity.create(e) assert e.parentId == 'syn1234' assert e['parentId'] == 'syn1234' assert e.properties['parentId'] == 'syn1234' assert e.properties.parentId == 'syn1234' assert e.foo == 123 assert e['foo'] == 123 assert e.annotations['foo'] == 123 assert e.annotations.foo == 123 # Annotations is a bit funny, because there is a property call # 'annotations', which will be masked by a member of the object # called 'annotations'. Because annotations are open-ended, we # might even have an annotations called 'annotations', which gets # really confusing. assert isinstance(e.annotations, collections.Mapping) assert isinstance(e['annotations'], collections.Mapping) assert e.properties[ 'annotations'] == '/repo/v1/entity/syn1234/annotations' assert e.properties.annotations == '/repo/v1/entity/syn1234/annotations' assert e.annotations.annotations == 'How confusing!' assert e.annotations['annotations'] == 'How confusing!' assert e.nerds == ['chris', 'jen', 'janey'] assert all([ k in e for k in [ 'name', 'description', 'foo', 'nerds', 'annotations', 'md5', 'parentId' ] ]) # Test modifying properties e.description = 'Working, so far' assert e['description'] == 'Working, so far' e['description'] = 'Wiz-bang flapdoodle' assert e.description == 'Wiz-bang flapdoodle' # Test modifying annotations e.foo = 999 assert e.annotations['foo'] == 999 e['foo'] = 12345 assert e.annotations.foo == 12345 # Test creating a new annotation e['bar'] = 888 assert e.annotations['bar'] == 888 e['bat'] = 7788 assert e.annotations['bat'] == 7788 # Test replacing annotations object e.annotations = { 'splat': 'a totally new set of annotations', 'foo': 456 } assert e.foo == 456 assert e['foo'] == 456 assert isinstance(e.annotations, collections.Mapping) assert isinstance(e['annotations'], collections.Mapping) assert e.annotations.foo == 456 assert e.properties[ 'annotations'] == '/repo/v1/entity/syn1234/annotations' assert e.properties.annotations == '/repo/v1/entity/syn1234/annotations'
def test_Entity(): # Test the basics of creating and accessing properties on an entity for i in range(2): e = Entity(name='Test object', description='I hope this works', annotations=dict(foo=123, nerds=['chris', 'jen', 'janey'], annotations='How confusing!'), properties=dict(annotations='/repo/v1/entity/syn1234/annotations', md5='cdef636522577fc8fb2de4d95875b27c', parentId='syn1234'), concreteType='org.sagebionetworks.repo.model.Data') # Should be able to create an Entity from an Entity if i == 1: e = Entity.create(e) assert_equals(e.parentId, 'syn1234') assert_equals(e['parentId'], 'syn1234') assert_equals(e.properties['parentId'], 'syn1234') assert_equals(e.properties.parentId, 'syn1234') assert_equals(e.foo, 123) assert_equals(e['foo'], 123) assert_equals(e.annotations['foo'], 123) assert_equals(e.annotations.foo, 123) assert_true(hasattr(e, 'parentId')) assert_true(hasattr(e, 'foo')) assert_false(hasattr(e, 'qwerqwer')) # Annotations is a bit funny, because there is a property call # 'annotations', which will be masked by a member of the object # called 'annotations'. Because annotations are open-ended, we # might even have an annotations called 'annotations', which gets # really confusing. assert_is_instance(e.annotations, collections.Mapping) assert_is_instance(e['annotations'], collections.Mapping) assert_equals(e.properties['annotations'], '/repo/v1/entity/syn1234/annotations') assert_equals(e.properties.annotations, '/repo/v1/entity/syn1234/annotations') assert_equals(e.annotations.annotations, 'How confusing!') assert_equals(e.annotations['annotations'], 'How confusing!') assert_equals(e.nerds, ['chris', 'jen', 'janey']) assert_true(all([k in e for k in ['name', 'description', 'foo', 'nerds', 'annotations', 'md5', 'parentId']])) # Test modifying properties e.description = 'Working, so far' assert_equals(e['description'], 'Working, so far') e['description'] = 'Wiz-bang flapdoodle' assert_equals(e.description, 'Wiz-bang flapdoodle') # Test modifying annotations e.foo = 999 assert_equals(e.annotations['foo'], 999) e['foo'] = 12345 assert_equals(e.annotations.foo, 12345) # Test creating a new annotation e['bar'] = 888 assert_equals(e.annotations['bar'], 888) e['bat'] = 7788 assert_equals(e.annotations['bat'], 7788) # Test replacing annotations object e.annotations = {'splat': 'a totally new set of annotations', 'foo': 456} assert_equals(e.foo, 456) assert_equals(e['foo'], 456) assert_is_instance(e.annotations, collections.Mapping) assert_is_instance(e['annotations'], collections.Mapping) assert_equals(e.annotations.foo, 456) assert_equals(e.properties['annotations'], '/repo/v1/entity/syn1234/annotations') assert_equals(e.properties.annotations, '/repo/v1/entity/syn1234/annotations') # test unicode properties e.train = '時刻表には記載されない 月への列車が来ると聞いて' e.band = "Motörhead" e.lunch = "すし"
def test_Entity(): # Test the basics of creating and accessing properties on an entity for i in range(2): e = Entity(name='Test object', description='I hope this works', annotations=dict(foo=123, nerds=['chris', 'jen', 'janey'], annotations='How confusing!'), properties=dict( annotations='/repo/v1/entity/syn1234/annotations', md5='cdef636522577fc8fb2de4d95875b27c', parentId='syn1234'), concreteType='org.sagebionetworks.repo.model.Data') # Should be able to create an Entity from an Entity if i == 1: e = Entity.create(e) assert_equals(e.parentId, 'syn1234') assert_equals(e['parentId'], 'syn1234') assert_equals(e.properties['parentId'], 'syn1234') assert_equals(e.properties.parentId, 'syn1234') assert_equals(e.foo, 123) assert_equals(e['foo'], 123) assert_equals(e.annotations['foo'], 123) assert_equals(e.annotations.foo, 123) assert_true(hasattr(e, 'parentId')) assert_true(hasattr(e, 'foo')) assert_false(hasattr(e, 'qwerqwer')) # Annotations is a bit funny, because there is a property call # 'annotations', which will be masked by a member of the object # called 'annotations'. Because annotations are open-ended, we # might even have an annotations called 'annotations', which gets # really confusing. assert_is_instance(e.annotations, collections.Mapping) assert_is_instance(e['annotations'], collections.Mapping) assert_equals(e.properties['annotations'], '/repo/v1/entity/syn1234/annotations') assert_equals(e.properties.annotations, '/repo/v1/entity/syn1234/annotations') assert_equals(e.annotations.annotations, 'How confusing!') assert_equals(e.annotations['annotations'], 'How confusing!') assert_equals(e.nerds, ['chris', 'jen', 'janey']) assert_true( all([ k in e for k in [ 'name', 'description', 'foo', 'nerds', 'annotations', 'md5', 'parentId' ] ])) # Test modifying properties e.description = 'Working, so far' assert_equals(e['description'], 'Working, so far') e['description'] = 'Wiz-bang flapdoodle' assert_equals(e.description, 'Wiz-bang flapdoodle') # Test modifying annotations e.foo = 999 assert_equals(e.annotations['foo'], 999) e['foo'] = 12345 assert_equals(e.annotations.foo, 12345) # Test creating a new annotation e['bar'] = 888 assert_equals(e.annotations['bar'], 888) e['bat'] = 7788 assert_equals(e.annotations['bat'], 7788) # Test replacing annotations object e.annotations = { 'splat': 'a totally new set of annotations', 'foo': 456 } assert_equals(e.foo, 456) assert_equals(e['foo'], 456) assert_is_instance(e.annotations, collections.Mapping) assert_is_instance(e['annotations'], collections.Mapping) assert_equals(e.annotations.foo, 456) assert_equals(e.properties['annotations'], '/repo/v1/entity/syn1234/annotations') assert_equals(e.properties.annotations, '/repo/v1/entity/syn1234/annotations') # test unicode properties e.train = '時刻表には記載されない 月への列車が来ると聞いて' e.band = "Motörhead" e.lunch = "すし"