def test_basics(self, class_entity_repo): agg = class_entity_repo.get_aggregate(IMyEntity) child_agg = class_entity_repo.get_aggregate(IMyEntityChild) new_child0 = self._make_child(child_agg) new_parent1 = MyEntityParent() new_ent1 = MyEntity() new_ent1.parent = new_parent1 new_child1 = MyEntityChild() child_rel_agg = self._make_rel_agg(class_entity_repo, new_ent1) assert len(list(child_agg.iterator())) == 1 assert len(list(agg.iterator())) == 1 assert len(list(child_rel_agg.iterator())) == 0 # Adding to a relationship aggregate ..... child_rel_agg.add(new_child1) # ....... adds to root aggregates: assert len(list(child_agg.iterator())) == 2 # ....... adds (along the cascade) to parent root aggregate: assert len(list(agg.iterator())) == 2 # ....... appends to children: assert new_ent1.children == [new_child1] # get by ID and slug, filtering. assert child_rel_agg.get_by_id(new_child1.id).id == new_child1.id assert \ child_rel_agg.get_by_slug(new_child1.slug).slug == new_child1.slug child_rel_agg.filter = eq(id=2) assert child_rel_agg.get_by_id(new_child1.id) is None assert child_rel_agg.get_by_slug(new_child1.slug) is None # update. upd_child0 = MyEntityChild(id=0) txt = 'FROBNIC' upd_child0.text = txt child_rel_agg.update(upd_child0) assert new_child0.text == txt
def test_update_cascade(self, class_entity_repo, monkeypatch): csc = DEFAULT_CASCADE & ~RELATION_OPERATIONS.UPDATE child_agg = class_entity_repo.get_aggregate(IMyEntityChild) new_child = self._make_child(child_agg) child_rel_agg = self._make_rel_agg(class_entity_repo, new_child.parent) children_attr = get_domain_class_attribute(MyEntity, 'children') monkeypatch.setattr(children_attr, 'cascade', csc) upd_child = MyEntityChild(id=0) txt = 'FROBNIC' upd_child.text = txt child_rel_agg.update(upd_child) assert new_child.text != txt assert not new_child.parent is None