def test_unchanged(self): from Products.LDAPUserFolder.exportimport import \ exportLDAPUserFolder site = self._initSite(use_changed=False) context = DummyExportContext(site) exportLDAPUserFolder(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'ldapuserfolder.xml') self._compareDOM(text, _LDAPUSERFOLDER_BODY) self.assertEqual(content_type, 'text/xml')
def test_empty(self): from Products.CMFCore.exportimport.properties \ import exportSiteProperties site = self._initSite(0, 0) context = DummyExportContext(site) exportSiteProperties(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'properties.xml') self._compareDOM(text, _EMPTY_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_normal(self): from Products.CMFCore.exportimport.properties \ import exportSiteProperties site = self._initSite() context = DummyExportContext(site) exportSiteProperties(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'properties.xml') self._compareDOM(text.decode('utf8'), _NORMAL_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_unchanged(self): from Products.CMFCore.exportimport.cookieauth \ import exportCookieCrumbler site, _cc = self._initSite(use_changed=False) context = DummyExportContext(site) exportCookieCrumbler(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'cookieauth.xml') self._compareDOM(text.decode('utf8'), _DEFAULT_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_changed(self): from Products.LDAPMultiPlugins.exportimport import \ exportLDAPMultiPlugins site = self._initSite(use_changed=True) context = DummyExportContext(site) exportLDAPMultiPlugins(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'tested.xml') self._compareDOM(text, _CHANGED_LMP_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_empty(self): from Products.CMFCore.exportimport.contenttyperegistry \ import exportContentTypeRegistry site, _ctr = self._initSite(mit_predikat=False) context = DummyExportContext(site) exportContentTypeRegistry(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'contenttyperegistry.xml') self._compareDOM(text.decode('utf8'), self._EMPTY_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_with_policy(self): from Products.CMFCore.exportimport.cachingpolicymgr \ import exportCachingPolicyManager site = self._initSite(with_policy=True) context = DummyExportContext(site) exportCachingPolicyManager(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'cachingpolicymgr.xml') self._compareDOM(text, self._WITH_POLICY_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_unchanged(self): from Products.LDAPMultiPlugins.exportimport import \ exportLDAPMultiPlugins site = self._initSite(use_changed=False) context = DummyExportContext(site) exportLDAPMultiPlugins(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'tested.xml') self._compareDOM(text, _LDAPMULTIPLUGIN_BODY) self.assertEqual(content_type, 'text/xml')
def test_empty(self): from Products.CMFCore.exportimport.cachingpolicymgr \ import exportCachingPolicyManager site, _cpm = self._initSite(with_policy=False) context = DummyExportContext(site) exportCachingPolicyManager(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'cachingpolicymgr.xml') self._compareDOM(text.decode('utf8'), self._EMPTY_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_with_policy(self): from Products.CMFCore.exportimport.contenttyperegistry \ import exportContentTypeRegistry site = self._initSite(mit_predikat=True) context = DummyExportContext(site) exportContentTypeRegistry(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'contenttyperegistry.xml') self._compareDOM(text, self._WITH_POLICY_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_changed(self): from Products.GenericSetup.tests.common import DummyExportContext from ..exportimport import exportLDAPUserFolder site = self._initSite(use_changed=True) context = DummyExportContext(site) exportLDAPUserFolder(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'ldapuserfolder.xml') self._compareDOM(text, _CHANGED_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_changed(self): from Products.CMFCore.exportimport.memberdata \ import exportMemberDataTool site, _mdtool = self._initSite(use_changed=True) context = DummyExportContext(site) exportMemberDataTool(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'memberdata.xml') self._compareDOM(text, _CHANGED_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_unchanged(self): from Products.CMFCore.exportimport.actions \ import exportActionProviders site, _atool = self._initSite(0, 0) context = DummyExportContext(site) exportActionProviders(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'actions.xml') self._compareDOM(text.decode('utf8'), _EMPTY_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_with_icon(self): from Products.CMFActionIcons.exportimport \ import exportActionIconsTool site = self._initSite(with_icon=True) context = DummyExportContext(site) exportActionIconsTool(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'actionicons.xml') self._compareDOM(text, self._WITH_ICON_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_with_info(self): from Products.CMFFormController.exportimport \ import exportCMFFormController site = self._initSite(with_info=True) context = DummyExportContext(site) exportCMFFormController(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'cmfformcontroller.xml') self._compareDOM(text, self._WITH_INFO_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_empty(self): from Products.PluginRegistry.exportimport \ import exportPluginRegistry app, registry = self._initRegistry() context = DummyExportContext(app) exportPluginRegistry(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'pluginregistry.xml') self._compareDOM(text, _EMPTY_PLUGINREGISTRY_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_changed(self): from Products.CMFCore.exportimport.cookieauth \ import exportCookieCrumbler site = self._initSite(use_changed=True) context = DummyExportContext(site) exportCookieCrumbler(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'cookieauth.xml') self._compareDOM(text, _CHANGED_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_normal(self): from Products.CMFCore.exportimport.actions \ import exportActionProviders site = self._initSite() context = DummyExportContext(site) exportActionProviders(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'actions.xml') self._compareDOM(text, _NORMAL_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_export_ini_file(self): from Products.GenericSetup.tests.common import DummyExportContext ini_file = _makeINIAware('ini_file.html') adapter = self._makeOne(ini_file) context = DummyExportContext(None) adapter.export(context, 'subpath/to') self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'subpath/to/ini_file.html.ini') self.assertEqual(content_type, 'text/plain') self.assertEqual(text.strip(), ini_file.as_ini().strip())
def test_normal(self): from marsapp.categories.exportimport.storage import \ exportMarscatsSettingsStorage self._populateSite(fields=COMMON_SETUP) context = DummyExportContext(self.site) exportMarscatsSettingsStorage(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'marscats.xml') self._compareDOM(text, _MARSCATS_XML) self.assertEqual(content_type, 'text/xml')
def test_with_contents(self): from Products.GenericSetup.tests.common import DummyExportContext from Products.GenericSetup.tests.faux_objects \ import TestCSVAware from Products.GenericSetup.utils import _getDottedName from Products.PluggableAuthService.exportimport import exportPAS _setUpDefaultTraversable() self._setUpAdapters() app, pas = self._initPAS() csv_aware = TestCSVAware() csv_aware._setId('csv_plugin') pas._setObject('csv_plugin', csv_aware) context = DummyExportContext(pas) exportPAS(context) self.assertEqual(len(context._wrote), 4) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'PAS/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 2) object_id, type_name = objects[0] self.assertEqual(object_id, 'plugins') self.assertEqual(type_name, 'plugins') # adapter-driven object_id, type_name = objects[1] self.assertEqual(object_id, 'csv_plugin') self.assertEqual(type_name, _getDottedName(csv_aware.__class__)) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'PAS/.properties') self.assertEqual(content_type, 'text/plain') lines = [_f for _f in [x.strip() for x in text.splitlines()] if _f] lines = sorted(lines) self.assertEqual(len(lines), 3) self.assertEqual(lines[0], '[DEFAULT]') self.assertEqual(lines[1], 'login_transform =') self.assertEqual(lines[2], 'title =') filename, text, content_type = context._wrote[2] self.assertEqual(filename, 'PAS/pluginregistry.xml') self.assertEqual(content_type, 'text/xml') filename, text, content_type = context._wrote[3] self.assertEqual(filename, 'PAS/csv_plugin.csv') self.assertEqual(content_type, 'text/comma-separated-values')
def test_normal(self): _ORDER = COMMON_SETUP_ORDER _HIDDEN = COMMON_SETUP_HIDDEN self._populateSite(order=_ORDER, hidden=_HIDDEN) context = DummyExportContext(self.site) exportViewletSettingsStorage(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'viewlets.xml') self._compareDOM(text, _VIEWLETS_XML) self.assertEqual(content_type, 'text/xml')
def test_export_with_known_CSV(self): from faux_objects import KNOWN_CSV sheet = _makeCSVAware('config') adapter = self._makeOne(sheet) context = DummyExportContext(None) adapter.export(context, 'subpath/to/sheet') self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'subpath/to/sheet/config.csv') self.assertEqual(content_type, 'text/comma-separated-values') self.assertEqual(text.strip(), KNOWN_CSV.strip())
def test_normal_no_plugins(self): from Products.PluginRegistry.exportimport \ import exportPluginRegistry app, registry = self._initRegistry( plugin_type_info=_PLUGIN_TYPE_INFO) context = DummyExportContext(app) exportPluginRegistry(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'pluginregistry.xml') self._compareDOM(text, _NO_PLUGINS_PLUGINREGISTRY_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_export_site_with_csvaware(self): from Products.GenericSetup.utils import _getDottedName self._setUpAdapters() site = _makeFolder('site') site.title = 'test_export_site_with_csvaware' site._setProperty('description', 'Testing export of an site with CSV-aware content.') aware = _makeCSVAware('aware') site._setObject('aware', aware) context = DummyExportContext(site) exporter = self._getExporter() exporter(context) self.assertEqual(len(context._wrote), 3) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'structure/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 1) self.assertEqual(objects[0][0], 'aware') self.assertEqual(objects[0][1], _getDottedName(aware.__class__)) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'structure/.properties') self.assertEqual(content_type, 'text/plain') parser = ConfigParser() parser.readfp(StringIO(text)) defaults = parser.defaults() self.assertEqual(len(defaults), 2) self.assertEqual(defaults['title'], site.title) self.assertEqual(defaults['description'], site.description) filename, text, content_type = context._wrote[2] self.assertEqual(filename, 'structure/aware.csv') self.assertEqual(content_type, 'text/comma-separated-values') rows = [x for x in reader(StringIO(text))] self.assertEqual(len(rows), 2) self.assertEqual(rows[0][0], 'one') self.assertEqual(rows[0][1], 'two') self.assertEqual(rows[0][2], 'three') self.assertEqual(rows[1][0], 'four') self.assertEqual(rows[1][1], 'five') self.assertEqual(rows[1][2], 'six')
def test_export(self): context = DummyExportContext(self.portal) export_schema(context) self.assertEqual('userschema.xml', context._wrote[0][0]) self.assertIn('field name="home_page"', context._wrote[0][1]) self.assertIn('field name="description"', context._wrote[0][1]) self.assertIn('field name="location"', context._wrote[0][1]) self.assertIn('field name="portrait"', context._wrote[0][1]) self.assertIn('field name="birthdate"', context._wrote[0][1]) self.assertIn('field name="another_date"', context._wrote[0][1]) self.assertIn('field name="age"', context._wrote[0][1]) self.assertIn('field name="department"', context._wrote[0][1]) self.assertIn('field name="skills"', context._wrote[0][1]) self.assertIn('field name="pi"', context._wrote[0][1]) self.assertIn('field name="vegetarian"', context._wrote[0][1])
def test_export_site_with_exportable_simple_items_unicode_latin1(self): self._setUpAdapters() ITEM_IDS = ('foo', 'bar', 'baz') site = _makeFolder('site', site_folder=True) site._setProperty('default_charset', 'iso-8859-1', 'string') site.title = 'AAA' site.description = 'DESCRIPTION' ITEMS_TITLE = u'Actualit\xe9' ITEMS_DESCRIPTION = u'Actualit\xe9 r\xe9centes' for id in ITEM_IDS: site._setObject(id, _makeINIAware(id)) item = getattr(site, id) item.setTitle(ITEMS_TITLE) item.setDescription(ITEMS_DESCRIPTION) context = DummyExportContext(site) exporter = self._getExporter() exporter(context) self.assertEqual(len(context._wrote), 2 + len(ITEM_IDS)) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'structure/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 3) for index in range(len(ITEM_IDS)): self.assertEqual(objects[index][0], ITEM_IDS[index]) self.assertEqual(objects[index][1], TEST_INI_AWARE) filename, text, content_type = context._wrote[index + 2] self.assertEqual(filename, 'structure/%s.ini' % ITEM_IDS[index]) object = site._getOb(ITEM_IDS[index]) self.assertEqual(text.strip(), object.as_ini().strip()) self.assertEqual(content_type, 'text/plain') filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'structure/.properties') self.assertEqual(content_type, 'text/plain') parser = self._get_config_parser(text) self.assertEqual(safe_bytes(parser.get('DEFAULT', 'title'), 'latin1'), ITEMS_TITLE.encode('latin1')) self.assertEqual(safe_bytes(parser.get('DEFAULT', 'description'), 'latin1'), ITEMS_DESCRIPTION.encode('latin1'))
def test_export_empty(self): topic = self._makeTopic('empty', False).__of__(self.app) adapter = self._makeOne(topic) context = DummyExportContext(topic) adapter.export(context, 'test', False) self.assertEqual(len(context._wrote), 2) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'test/empty/.objects') self.assertEqual(text, '') self.assertEqual(content_type, 'text/comma-separated-values') filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'test/empty/criteria.xml') self._compareDOM(text, _EMPTY_TOPIC_CRITERIA) self.assertEqual(content_type, 'text/xml')
def test_normal(self): from Products.CMFCore.exportimport.actions \ import exportActionProviders from Products.CMFCore.exportimport.actions \ import importActionProviders site = self._initSite(1, 1) atool = site.portal_actions foo = site.portal_foo bar = site.portal_bar self.assertEqual(len(atool.listActionProviders()), 1) self.failIf('portal_foo' in atool.listActionProviders()) self.failIf(foo.listActions()) self.failIf('portal_bar' in atool.listActionProviders()) self.failIf(bar.listActions()) self.failUnless('portal_actions' in atool.listActionProviders()) context = DummyImportContext(site) context._files['actions.xml'] = _OLD_EXPORT importActionProviders(context) self.assertEqual(len(atool.listActionProviders()), 3) self.failUnless('portal_bar' in atool.listActionProviders()) self.failUnless('portal_foo' in atool.listActionProviders()) self.failUnless('portal_actions' in atool.listActionProviders()) self.assertEqual(len(atool.objectIds()), 1) self.failUnless('dummy' in atool.objectIds()) # Only one action appears. The importer only deals with actions # defined by the actions tool. Other tools are responsible for # exporting/importing actions themselves. self.assertEqual(len(atool.dummy.objectIds()), 1) self.failUnless('baz' in atool.dummy.objectIds()) self.failIf(foo.listActions()) self.failIf(bar.listActions()) # complete the roundtrip context = DummyExportContext(site) exportActionProviders(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'actions.xml') self._compareDOM(text, _NEWSYTLE_EXPORT) self.assertEqual(content_type, 'text/xml')
def test_normal_with_plugins(self): from Products.PluginRegistry.exportimport \ import exportPluginRegistry provideAdapter(AttrItemTraverser, (Interface, ), ITraversable) app, registry = self._initRegistry( plugin_type_info=_PLUGIN_TYPE_INFO, plugins={IFoo: ('foo_plugin_1', 'foo_plugin_2')}, ) context = DummyExportContext(app) exportPluginRegistry(context) self.assertEqual(len(context._wrote), 1) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'pluginregistry.xml') self._compareDOM(text, _NORMAL_PLUGINREGISTRY_EXPORT) self.assertEqual(content_type, 'text/xml')