def test_update_nested_collection_from_data(self):
     # Set up member that has one child.
     root_coll = get_root_collection(IMyEntity)
     ent = MyEntity(id=1)
     child0 = MyEntityChild(id=0)
     ent.children.append(child0)
     mb = root_coll.create_member(ent)
     # Set up another member with two children with different IDs.
     stg_coll = create_staging_collection(IMyEntity)
     upd_ent = MyEntity(id=1)
     child1 = MyEntityChild(id=1)
     child1.parent = upd_ent
     child2 = MyEntityChild(id=2)
     child2.parent = upd_ent
     upd_ent.children.append(child1)
     upd_ent.children.append(child2)
     upd_mb = stg_coll.create_member(upd_ent)
     rpr = as_representer(mb, CsvMime)
     attribute_options = {('children',):{IGNORE_OPTION:False,
                                         WRITE_AS_LINK_OPTION:False}, }
     rpr.configure(attribute_options=attribute_options)
     de = rpr.data_from_resource(upd_mb)
     #
     mb.update(de)
     self.assert_equal(set([mb.id for mb in mb.children]), set([1, 2]))
예제 #2
0
 def test_update_nested_collection_from_data(self, resource_repo):
     # Set up member that has one child.
     coll = resource_repo.get_collection(IMyEntity)
     ent = MyEntity(id=1)
     child0 = MyEntityChild(id=0)
     ent.children.append(child0)
     mb = coll.create_member(ent)
     # Set up another member with two children with different IDs.
     tmp_coll = create_staging_collection(IMyEntity)
     upd_ent = MyEntity(id=1)
     child1 = MyEntityChild(id=1)
     child1.parent = upd_ent
     child2 = MyEntityChild(id=2)
     child2.parent = upd_ent
     upd_ent.children.append(child1)
     upd_ent.children.append(child2)
     upd_mb = tmp_coll.create_member(upd_ent)
     rpr = as_representer(mb, CsvMime)
     attribute_options = {('children',):{IGNORE_OPTION:False,
                                         WRITE_AS_LINK_OPTION:False}, }
     with rpr.with_updated_configuration(attribute_options=
                                                 attribute_options):
         de = rpr.resource_to_data(upd_mb)
         mb.update(de)
         assert set([mb.id for mb in mb.children]) == set([1, 2])
예제 #3
0
 def test_update_nested_collection_from_data(self, resource_repo):
     # Set up member that has one child.
     coll = resource_repo.get_collection(IMyEntity)
     ent = MyEntity(id=1)
     child0 = MyEntityChild(id=0)
     ent.children.append(child0)
     mb = coll.create_member(ent)
     # Set up another member with two children with different IDs.
     tmp_coll = create_staging_collection(IMyEntity)
     upd_ent = MyEntity(id=1)
     child1 = MyEntityChild(id=1)
     child1.parent = upd_ent
     child2 = MyEntityChild(id=2)
     child2.parent = upd_ent
     upd_ent.children.append(child1)
     upd_ent.children.append(child2)
     upd_mb = tmp_coll.create_member(upd_ent)
     rpr = as_representer(mb, CsvMime)
     attribute_options = {
         ('children', ): {
             IGNORE_OPTION: False,
             WRITE_AS_LINK_OPTION: False
         },
     }
     with rpr.with_updated_configuration(
             attribute_options=attribute_options):
         de = rpr.resource_to_data(upd_mb)
         mb.update(de)
         assert set([mb.id for mb in mb.children]) == set([1, 2])
예제 #4
0
 def test_delete_cascade(self, class_entity_repo, monkeypatch):
     new_parent1 = MyEntityParent()
     new_ent1 = MyEntity()
     new_ent1.parent = new_parent1
     new_child1 = MyEntityChild()
     new_child1.parent = new_ent1
     child_rel_agg = self._make_rel_agg(class_entity_repo, new_ent1)
     child_rel_agg.add(new_child1)
     new_parent1.id = 1
     new_ent1.id = 1
     new_child1.id = 1
     agg = class_entity_repo.get_aggregate(IMyEntity)
     child_agg = class_entity_repo.get_aggregate(IMyEntityChild)
     assert len(list(child_agg.iterator())) == 1
     assert len(list(agg.iterator())) == 1
     assert new_ent1.children == [new_child1]
     assert new_child1.parent == new_ent1
     csc = DEFAULT_CASCADE | RELATION_OPERATIONS.REMOVE
     children_attr = get_domain_class_attribute(MyEntity, 'children')
     parent_attr = get_domain_class_attribute(MyEntityChild, 'parent')
     monkeypatch.setattr(children_attr, 'cascade', csc)
     monkeypatch.setattr(parent_attr, 'cascade', csc)
     child_rel_agg.remove(new_child1)
     assert new_ent1.children == []
     assert new_child1.parent is None
     assert len(list(child_agg.iterator())) == 0
     if self.__class__.__name__.startswith('TestMemory'):
         # FIXME: Transparent modification of RDB mapper cascades
         #        does not work yet.
         assert len(list(agg.iterator())) == 0
     assert len(list(child_rel_agg.iterator())) == 0
예제 #5
0
def create_entity_tree(id=0, text=None):  # pylint: disable=W0622
    my_entity_grandchild = MyEntityGrandchild(id=id, text=text)
    my_entity_child = MyEntityChild(id=id, text=text, children=[my_entity_grandchild])
    my_entity_parent = MyEntityParent(id=id, text=text)
    my_entity = MyEntity(id=id, text=text, children=[my_entity_child], parent=my_entity_parent)
    # If we run with the SQLAlchemy backend, the back references are populated
    # automatically.
    if my_entity_child.parent is None:
        my_entity_child.parent = my_entity
    if my_entity_grandchild.parent is None:
        my_entity_grandchild.parent = my_entity_child
    return my_entity
예제 #6
0
 def _make_child(self, child_agg, child_id=0):
     new_parent = MyEntityParent()
     new_ent = MyEntity()
     new_ent.parent = new_parent
     new_child = MyEntityChild()
     new_ent.children.append(new_child)
     if new_child.parent is None:
         new_child.parent = new_ent
     child_agg.add(new_child)
     new_parent.id = child_id
     new_ent.id = child_id
     new_child.id = child_id
     return new_child
예제 #7
0
def create_entity(entity_id=0, entity_text=None):
    my_entity_parent = MyEntityParent(id=entity_id, text=entity_text)
    my_entity_grandchild = MyEntityGrandchild(id=entity_id, text=entity_text)
    my_entity_child = MyEntityChild(id=entity_id,
                                    text=entity_text,
                                    children=[my_entity_grandchild])
    my_entity = MyEntity(id=entity_id,
                         text=entity_text,
                         parent=my_entity_parent,
                         children=[my_entity_child])
    # If we run with the SQLAlchemy backend, the back references are populated
    # automatically.
    if my_entity_child.parent is None:
        my_entity_child.parent = my_entity
    if my_entity_grandchild.parent is None:
        my_entity_grandchild.parent = my_entity_child
    return my_entity
예제 #8
0
파일: testing.py 프로젝트: helixyte/everest
def create_entity(entity_id=0, entity_text=None):
    my_entity_parent = MyEntityParent(id=entity_id, text=entity_text)
    my_entity_grandchild = MyEntityGrandchild(id=entity_id, text=entity_text)
    my_entity_child = MyEntityChild(id=entity_id,
                                    text=entity_text,
                                    children=[my_entity_grandchild])
    my_entity = MyEntity(id=entity_id,
                         text=entity_text,
                         parent=my_entity_parent,
                         children=[my_entity_child])
    # If we run with the SQLAlchemy backend, the back references are populated
    # automatically.
    if my_entity_child.parent is None:
        my_entity_child.parent = my_entity
    if my_entity_grandchild.parent is None:
        my_entity_grandchild.parent = my_entity_child
    return my_entity
예제 #9
0
파일: testing.py 프로젝트: b8va/everest
def create_entity(entity_id=0, entity_text=None):
    my_entity = MyEntity(text=entity_text)
    my_entity.id = entity_id
    my_entity_parent = MyEntityParent()
    my_entity_parent.id = entity_id
    my_entity.parent = my_entity_parent
    my_entity_child = MyEntityChild()
    my_entity_child.id = entity_id
    my_entity.children.append(my_entity_child)
    my_entity_grandchild = MyEntityGrandchild()
    my_entity_grandchild.id = entity_id
    my_entity_child.children.append(my_entity_grandchild)
    # If we run with the SQLAlchemy backend, the back references are populated
    # automatically.
    if my_entity_child.parent is None:
        my_entity_child.parent = my_entity
    if my_entity_grandchild.parent is None:
        my_entity_grandchild.parent = my_entity_child
    return my_entity
예제 #10
0
파일: fixtures.py 프로젝트: papagr/everest
def create_entity_tree(id=0, text=None):  # pylint: disable=W0622
    my_entity_grandchild = MyEntityGrandchild(id=id, text=text)
    my_entity_child = MyEntityChild(id=id,
                                    text=text,
                                    children=[my_entity_grandchild])
    my_entity_parent = MyEntityParent(
        id=id,
        text=text,
    )
    my_entity = MyEntity(id=id,
                         text=text,
                         children=[my_entity_child],
                         parent=my_entity_parent)
    # If we run with the SQLAlchemy backend, the back references are populated
    # automatically.
    if my_entity_child.parent is None:
        my_entity_child.parent = my_entity
    if my_entity_grandchild.parent is None:
        my_entity_grandchild.parent = my_entity_child
    return my_entity
예제 #11
0
def _make_test_entity_member():
    parent = MyEntityParent()
    entity = MyEntity(parent=parent)
    if parent.child is None:
        parent.child = entity
    child = MyEntityChild()
    entity.children.append(child)
    if child.parent is None:
        child.parent = entity
    grandchild = MyEntityGrandchild()
    child.children.append(grandchild)
    if grandchild.parent is None:
        grandchild.parent = child
    coll = create_staging_collection(IMyEntity)
    mb = coll.create_member(entity)
    parent.id = 0
    entity.id = 0
    child.id = 0
    grandchild.id = 0
    return mb
예제 #12
0
파일: test_io.py 프로젝트: b8va/everest
def _make_test_entity_member():
    parent = MyEntityParent()
    entity = MyEntity(parent=parent)
    if parent.child is None:
        parent.child = entity
    child = MyEntityChild()
    entity.children.append(child)
    if child.parent is None:
        child.parent = entity
    grandchild = MyEntityGrandchild()
    child.children.append(grandchild)
    if grandchild.parent is None:
        grandchild.parent = child
    coll = create_staging_collection(IMyEntity)
    mb = coll.create_member(entity)
    parent.id = 0
    entity.id = 0
    child.id = 0
    grandchild.id = 0
    return mb
예제 #13
0
    def test_update_from_data_add_child(self):
        my_entity = create_entity()
        new_child = MyEntityChild()
        my_entity.children.append(new_child)
        if new_child.parent is None:
            new_child.parent = my_entity
        coll = create_staging_collection(IMyEntity)
        member = coll.create_member(my_entity)
        self.assert_equal(len(member.children), 2)
        mp = self._make_mapping()
        data_el = mp.map_to_data_element(member)
        del member
        del my_entity
#        import gc; gc.collect()
        my_entity = create_entity()
        coll = get_root_collection(IMyEntity)
        context = coll.create_member(my_entity)
        self.assert_equal(len(context.children), 1)
        context.update(data_el)
        self.assert_equal(len(context.children), 2)
예제 #14
0
 def test_update_from_data_add_child(self):
     my_entity = create_entity()
     new_child = MyEntityChild()
     my_entity.children.append(new_child)
     if new_child.parent is None:
         new_child.parent = my_entity
     coll = create_staging_collection(IMyEntity)
     member = coll.create_member(my_entity)
     self.assert_equal(len(member.children), 2)
     mp = self._make_mapping()
     data_el = mp.map_to_data_element(member)
     del member
     del my_entity
     #        import gc; gc.collect()
     my_entity = create_entity()
     coll = get_root_collection(IMyEntity)
     context = coll.create_member(my_entity)
     self.assert_equal(len(context.children), 1)
     context.update(data_el)
     self.assert_equal(len(context.children), 2)
예제 #15
0
def create_entity(entity_id=0, entity_text=None):
    my_entity = MyEntity(text=entity_text)
    my_entity.id = entity_id
    my_entity_parent = MyEntityParent()
    my_entity_parent.id = entity_id
    my_entity.parent = my_entity_parent
    my_entity_child = MyEntityChild()
    my_entity_child.id = entity_id
    my_entity_child.parent = my_entity
    if len(my_entity.children) == 0:
        # Tests that use the ORM will not need to go here.
        my_entity.children.append(my_entity_child)
        assert len(my_entity.children) == 1
    my_entity_grandchild = MyEntityGrandchild()
    my_entity_grandchild.id = entity_id
    my_entity_grandchild.parent = my_entity_child
    # Tests that use the ORM will not need this.
    if len(my_entity.children) == 0:
        my_entity.children.append(my_entity_child)
    if len(my_entity_child.children) == 0:
        my_entity_child.children.append(my_entity_grandchild)
    return my_entity
예제 #16
0
def create_entity(entity_id=0, entity_text=None):
    my_entity = MyEntity(text=entity_text)
    my_entity.id = entity_id
    my_entity_parent = MyEntityParent()
    my_entity_parent.id = entity_id
    my_entity.parent = my_entity_parent
    my_entity_child = MyEntityChild()
    my_entity_child.id = entity_id
    my_entity_child.parent = my_entity
    if len(my_entity.children) == 0:
        # Tests that use the ORM will not need to go here.
        my_entity.children.append(my_entity_child)
        assert len(my_entity.children) == 1
    my_entity_grandchild = MyEntityGrandchild()
    my_entity_grandchild.id = entity_id
    my_entity_grandchild.parent = my_entity_child
    # Tests that use the ORM will not need this.
    if len(my_entity.children) == 0:
        my_entity.children.append(my_entity_child)
    if len(my_entity_child.children) == 0:
        my_entity_child.children.append(my_entity_grandchild)
    return my_entity