def assertImportFile(self, filename, imported, replace=False, update=False,
                      ignore_top_level=False):
     """Import an XML file.
     """
     clearEvents()
     request = TestRequest()
     importer = Importer(self.root, request, {
             'replace_content': replace,
             'update_content': update,
             'ignore_top_level_content': ignore_top_level})
     with self.layer.open_fixture(filename) as source:
         importer.importStream(source)
     self.assertItemsEqual(
         map(lambda event:  '/'.join(event.object.getPhysicalPath()),
             getEvents(IContentImported)),
         imported)
     return importer
 def assertImportFile(self,
                      filename,
                      imported,
                      replace=False,
                      update=False,
                      ignore_top_level=False):
     """Import an XML file.
     """
     clearEvents()
     request = TestRequest()
     importer = Importer(
         self.root, request, {
             'replace_content': replace,
             'update_content': update,
             'ignore_top_level_content': ignore_top_level
         })
     with self.layer.open_fixture(filename) as source:
         importer.importStream(source)
     self.assertItemsEqual(
         map(lambda event: '/'.join(event.object.getPhysicalPath()),
             getEvents(IContentImported)), imported)
     return importer
 def build(self, origin, adder, items):
     """Helper to build the containers.
     """
     request = self.request
     existing = origin.objectIds()
     # Add items, one by one.
     for item in items:
         identifier = item.get('identifier', '')
         assert len(identifier), 'Invalid json structure'
         if identifier not in existing:
             adder(str(identifier), identifier, no_default_content=True)
         content = origin._getOb(identifier)
         importer = Importer(origin, request, {'update_content': True})
         importer.importStream(io.BytesIO(item['export'].encode('utf-8')))
         # Add index document if needed.
         if 'index' in item and item['index']:
             if content.get_default() is None:
                 factory = content.manage_addProduct['silva.app.document']
                 factory.manage_addDocument(
                     'index', identifier, no_default_version=True)
             importer = Importer(content, request, {'update_content': True})
             importer.importStream(io.BytesIO(item['index'].encode('utf-8')))
         yield content, item