Example #1
0
 def __init__(self, entity_class, cache=None):
     Aggregate.__init__(self)
     self.entity_class = entity_class
     if cache is None:
         cache = EntityCacheMap()
     self.__cache_map = cache
     self.__visitor = AruVisitor(entity_class, self.__add,
                                 self.__remove, self.__update)
Example #2
0
 def __collect(self, resource):
     ent_cls = get_entity_class(resource)
     coll_cls = get_collection_class(resource)
     cache = EntityCacheMap()
     agg = StagingAggregate(ent_cls, cache)
     coll = coll_cls.create_from_aggregate(agg)
     coll.add(resource)
     return dict([(get_member_class(ent_cls),
                   coll.get_root_collection(ent_cls))
                  for ent_cls in cache.keys()])
Example #3
0
 def test_basics(self):
     ecm = EntityCacheMap()
     ent = MyEntity(id=0)
     ecm.add(MyEntity, ent)
     assert ecm.has_key(MyEntity)
     assert ecm[MyEntity].get_by_id(ent.id) == ent
     assert ent in ecm
     assert list(ecm.keys()) == [MyEntity]
     ecm.remove(MyEntity, ent)
     assert not ent in ecm
Example #4
0
 def test_traverse_with_remove_sequence(self):
     ent0 = create_entity(entity_id=0)
     ent1 = create_entity(entity_id=None)
     cache = EntityCacheMap()
     agg = StagingAggregate(MyEntity, cache=cache)
     agg.add(ent0)
     agg.add(ent1)
     trv = SourceTargetDataTreeTraverser.make_traverser(
         None, [ent0, ent1], RELATION_OPERATIONS.REMOVE)
     vst = AruVisitor(MyEntity, remove_callback=agg.remove)
     trv.run(vst)
     self.assert_equal(len(list(iter(agg))), 0)