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 = "すし"
Exemple #3
0
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 = "すし"