def __dump_entities(self, entity_class): cache = self._get_cache(entity_class) coll_cls = get_collection_class(entity_class) mb_cls = get_member_class(entity_class) fn = get_write_collection_path(coll_cls, self._config['content_type'], directory=self._config['directory']) # Wrap the entities in a temporary collection. coll = create_staging_collection(coll_cls) for ent in cache.iterator(): coll.add(mb_cls.create_from_entity(ent)) # Open stream for writing and dump the collection. stream = file(fn, 'w') with stream: dump_resource(coll, stream, content_type=self._config['content_type'])
def test_dump_no_content_type(self): member = _make_test_entity_member() strm = StringIO() dump_resource(member, strm) self.assert_true(strm.getvalue().startswith('"id",'))
def test_dump(self): prjs = get_root_collection(IProject) prj = prjs.get('pond') stream = StringIO('w') dump_resource(prj, stream) self.assert_true(len(stream.getvalue()) > 0)