def test_old_xml(self): from Products.CMFCore.exportimport.typeinfo import exportTypesTool from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite() tool = site.portal_types self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files['types.xml'] = self._NORMAL_TOOL_EXPORT context._files['types/foo.xml'] = _FOO_OLD_EXPORT % 'foo' context._files['types/bar.xml'] = _BAR_OLD_EXPORT % 'bar' importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.failUnless('foo' in tool.objectIds()) self.failUnless('bar' in tool.objectIds()) context = DummyExportContext(site) exportTypesTool(context) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'types/bar.xml') self._compareDOM(text, _BAR_EXPORT % 'bar') self.assertEqual(content_type, 'text/xml')
def test_normal_update(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite() tool = site.portal_types context = DummyImportContext(site) context._files['types.xml'] = self._NORMAL_TOOL_EXPORT context._files['types/foo.xml'] = _FOO_EXPORT % 'foo' context._files['types/bar.xml'] = _BAR_EXPORT % 'bar' importTypesTool(context) self.assertEqual(tool.foo.title, 'Foo') self.assertEqual(tool.foo.content_meta_type, 'Foo Thing') self.assertEqual(tool.foo.content_icon, 'foo.png') self.assertEqual(tool.foo.immediate_view, 'foo_view') self.assertEqual(tool.foo._aliases, { '(Default)': 'foo_view', 'view': 'foo_view' }) context = DummyImportContext(site, False) context._files['types.xml'] = _UPDATE_TOOL_IMPORT context._files['types/foo.xml'] = _UPDATE_FOO_IMPORT importTypesTool(context) self.assertEqual(tool.foo.title, 'Foo') self.assertEqual(tool.foo.content_meta_type, 'Foo Thing') self.assertEqual(tool.foo.content_icon, 'foo.png') self.assertEqual(tool.foo.immediate_view, 'foo_view') self.assertEqual(tool.foo._aliases, { '(Default)': 'foo_view', 'view': 'foo_view', 'spam': 'eggs' })
def test_old_xml(self): from Products.CMFCore.exportimport.typeinfo import exportTypesTool from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite() tool = site.portal_types self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files['types.xml'] = self._NORMAL_TOOL_EXPORT context._files['types/foo.xml'] = _FOO_OLD_EXPORT % 'foo' context._files['types/bar.xml'] = _BAR_OLD_EXPORT % 'bar' importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.failUnless('foo' in tool.objectIds()) self.failUnless('bar' in tool.objectIds()) context = DummyExportContext(site) exportTypesTool(context) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'types/bar.xml') self._compareDOM(text, _BAR_EXPORT % 'bar') self.assertEqual(content_type, 'text/xml')
def test_normal_update(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite() tool = site.portal_types context = DummyImportContext(site) context._files["types.xml"] = self._NORMAL_TOOL_EXPORT context._files["types/foo.xml"] = _FOO_EXPORT % "foo" context._files["types/bar.xml"] = _BAR_EXPORT % "bar" importTypesTool(context) self.assertEqual(tool.foo.title, "Foo") self.assertEqual(tool.foo.content_meta_type, "Foo Thing") self.assertEqual(tool.foo.icon_expr, "string:${portal_url}/foo.png") self.assertEqual(tool.foo.immediate_view, "foo_view") self.assertEqual(tool.foo._aliases, {"(Default)": "foo_view", "view": "foo_view"}) context = DummyImportContext(site, False) context._files["types.xml"] = _UPDATE_TOOL_IMPORT context._files["types/foo.xml"] = _UPDATE_FOO_IMPORT importTypesTool(context) self.assertEqual(tool.foo.title, "Foo") self.assertEqual(tool.foo.content_meta_type, "Foo Thing") self.assertEqual(tool.foo.icon_expr, "string:${portal_url}/foo.png") self.assertEqual(tool.foo.immediate_view, "foo_view") self.assertEqual(tool.foo._aliases, {"(Default)": "foo_view", "view": "foo_view", "spam": "eggs"})
def test_normal_update(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite() tool = site.portal_types context = DummyImportContext(site) context._files['types.xml'] = self._NORMAL_TOOL_EXPORT context._files['types/foo.xml'] = _FOO_EXPORT % 'foo' context._files['types/bar.xml'] = _BAR_EXPORT % 'bar' importTypesTool(context) self.assertEqual(tool.foo.title, 'Foo') self.assertEqual(tool.foo.content_meta_type, 'Foo Thing') self.assertEqual(tool.foo.content_icon, 'foo.png') self.assertEqual(tool.foo.immediate_view, 'foo_view') self.assertEqual(tool.foo._aliases, {'(Default)': 'foo_view', 'view': 'foo_view'}) context = DummyImportContext(site, False) context._files['types.xml'] = _UPDATE_TOOL_IMPORT context._files['types/foo.xml'] = _UPDATE_FOO_IMPORT importTypesTool(context) self.assertEqual(tool.foo.title, 'Foo') self.assertEqual(tool.foo.content_meta_type, 'Foo Thing') self.assertEqual(tool.foo.content_icon, 'foo.png') self.assertEqual(tool.foo.immediate_view, 'foo_view') self.assertEqual(tool.foo._aliases, {'(Default)': 'foo_view', 'view': 'foo_view', 'spam': 'eggs'})
def test_action_remove(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite() tool = site.portal_types self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site, False) # Make sure removing a non-existant action doesn't fail _TOOL = """\ <?xml version="1.0"?> <object name="portal_types" meta_type="CMF Types Tool"> <object name="%s" meta_type="Factory-based Type Information"/> </object> """ context._files['types.xml'] = (_TOOL % 'baz').strip() _BAZ_SETUP = """\ <?xml version="1.0"?> <object name="%s" meta_type="Factory-based Type Information"> <property name="title">Baz</property> <action title="View" action_id="view" category="object" condition_expr="" url_expr="string:${object_url}/baz_view" icon_expr="" visible="True"> <permission value="View"/> </action> <action action_id="edit" category="object" remove="True" /> </object> """ context._files['types/baz.xml'] = (_BAZ_SETUP % 'baz').strip() importTypesTool(context) self.assertEqual(len(tool.objectIds()), 1) self.failUnless('baz' in tool.objectIds()) baz = tool['baz'] actions = baz.listActions() self.assertEqual(len(actions), 1) self.assertEqual(actions[0].title, 'View') # Remove an already existing action _BAZ_REMOVE = """\ <?xml version="1.0"?> <object name="%s" meta_type="Factory-based Type Information"> <property name="title">Baz</property> <action action_id="view" category="object" remove="True" /> </object> """ context._files['types/baz.xml'] = (_BAZ_REMOVE % 'baz').strip() importTypesTool(context) self.assertEqual(len(tool.objectIds()), 1) self.failUnless('baz' in tool.objectIds()) baz = tool['baz'] actions = baz.listActions() self.assertEqual(len(actions), 0)
def test_action_remove(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite() tool = site.portal_types self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site, False) # Make sure removing a non-existant action doesn't fail _TOOL = """\ <?xml version="1.0"?> <object name="portal_types" meta_type="CMF Types Tool"> <object name="%s" meta_type="Factory-based Type Information"/> </object> """ context._files['types.xml'] = (_TOOL % 'baz').strip() _BAZ_SETUP = """\ <?xml version="1.0"?> <object name="%s" meta_type="Factory-based Type Information"> <property name="title">Baz</property> <action title="View" action_id="view" category="object" condition_expr="" url_expr="string:${object_url}/baz_view" icon_expr="" visible="True"> <permission value="View"/> </action> <action action_id="edit" category="object" remove="True" /> </object> """ context._files['types/baz.xml'] = (_BAZ_SETUP % 'baz').strip() importTypesTool(context) self.assertEqual(len(tool.objectIds()), 1) self.failUnless('baz' in tool.objectIds()) baz = tool['baz'] actions = baz.listActions() self.assertEqual(len(actions), 1) self.assertEqual(actions[0].title, 'View') # Remove an already existing action _BAZ_REMOVE = """\ <?xml version="1.0"?> <object name="%s" meta_type="Factory-based Type Information"> <property name="title">Baz</property> <action action_id="view" category="object" remove="True" /> </object> """ context._files['types/baz.xml'] = (_BAZ_REMOVE % 'baz').strip() importTypesTool(context) self.assertEqual(len(tool.objectIds()), 1) self.failUnless('baz' in tool.objectIds()) baz = tool['baz'] actions = baz.listActions() self.assertEqual(len(actions), 0)
def test_empty_skip_purge(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site, tool = self._initSite(1) self.assertEqual(len(tool.objectIds()), 2) context = DummyImportContext(site, False) context._files['types.xml'] = self._EMPTY_TOOL_EXPORT importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2)
def test_empty_skip_purge(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site, tool = self._initSite(1) self.assertEqual(len(tool.objectIds()), 2) context = DummyImportContext(site, False) context._files['types.xml'] = self._EMPTY_TOOL_EXPORT importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2)
def test_empty_explicit_purge(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite(1) tool = site.portal_types self.assertEqual(len(tool.objectIds()), 2) context = DummyImportContext(site, True) context._files["types.xml"] = self._EMPTY_TOOL_EXPORT importTypesTool(context) self.assertEqual(len(tool.objectIds()), 0)
def test_with_filenames(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site, tool = self._initSite() self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files['types.xml'] = self._FILENAME_EXPORT context._files['types/foo_object.xml'] = _FOO_EXPORT % 'foo object' context._files['types/bar_object.xml'] = _BAR_EXPORT % 'bar object' importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.assertTrue('foo object' in tool.objectIds()) self.assertTrue('bar object' in tool.objectIds())
def test_normal(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site, tool = self._initSite() self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files['types.xml'] = self._NORMAL_TOOL_EXPORT context._files['types/foo.xml'] = _FOO_EXPORT % 'foo' context._files['types/bar.xml'] = _BAR_EXPORT % 'bar' importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.assertTrue('foo' in tool.objectIds()) self.assertTrue('bar' in tool.objectIds())
def test_normal(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site, tool = self._initSite() self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files['types.xml'] = self._NORMAL_TOOL_EXPORT context._files['types/foo.xml'] = _FOO_EXPORT % 'foo' context._files['types/bar.xml'] = _BAR_EXPORT % 'bar' importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.failUnless('foo' in tool.objectIds()) self.failUnless('bar' in tool.objectIds())
def test_with_filenames(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site, tool = self._initSite() self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files['types.xml'] = self._FILENAME_EXPORT context._files['types/foo_object.xml'] = _FOO_EXPORT % 'foo object' context._files['types/bar_object.xml'] = _BAR_EXPORT % 'bar object' importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.failUnless('foo object' in tool.objectIds()) self.failUnless('bar object' in tool.objectIds())
def test_migration(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site, tool = self._initSite() self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files['types.xml'] = self._NORMAL_TOOL_EXPORT context._files['types/foo.xml'] = _FOO_EXPORT % 'foo' context._files['types/bar.xml'] = _BAR_CMF21_IMPORT % 'bar' importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.assertTrue('foo' in tool.objectIds()) self.assertTrue('bar' in tool.objectIds()) self.assertEqual(tool.bar.icon_expr, 'string:${portal_url}/bar.png')
def test_normal(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site = self._initSite() tool = site.portal_types self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files["types.xml"] = self._NORMAL_TOOL_EXPORT context._files["types/foo.xml"] = _FOO_EXPORT % "foo" context._files["types/bar.xml"] = _BAR_EXPORT % "bar" importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.failUnless("foo" in tool.objectIds()) self.failUnless("bar" in tool.objectIds())
def test_migration(self): from Products.CMFCore.exportimport.typeinfo import importTypesTool site, tool = self._initSite() self.assertEqual(len(tool.objectIds()), 0) context = DummyImportContext(site) context._files['types.xml'] = self._NORMAL_TOOL_EXPORT context._files['types/foo.xml'] = _FOO_EXPORT % 'foo' context._files['types/bar.xml'] = _BAR_CMF21_IMPORT % 'bar' importTypesTool(context) self.assertEqual(len(tool.objectIds()), 2) self.failUnless('foo' in tool.objectIds()) self.failUnless('bar' in tool.objectIds()) self.assertEqual(tool.bar.icon_expr, 'string:${portal_url}/bar.png')