[Zope-CVS] SVN: PluggableAuthService/trunk/plugins/ Add adapter for
plugins who delegate to another, found via 'delegate_path'.
Tres Seaver
tseaver at palladion.com
Wed Nov 16 13:01:37 EST 2005
Log message for revision 40166:
Add adapter for plugins who delegate to another, found via 'delegate_path'.
Changed:
U PluggableAuthService/trunk/plugins/exportimport.py
U PluggableAuthService/trunk/plugins/tests/test_exportimport.py
A PluggableAuthService/trunk/plugins/xml/delegatepath.xml
-=-
Modified: PluggableAuthService/trunk/plugins/exportimport.py
===================================================================
--- PluggableAuthService/trunk/plugins/exportimport.py 2005-11-16 18:00:56 UTC (rev 40165)
+++ PluggableAuthService/trunk/plugins/exportimport.py 2005-11-16 18:01:36 UTC (rev 40166)
@@ -44,9 +44,9 @@
- [/] ScriptablePlugin (stock GenericSetup folderish support?)
- - [_] DelegatingMultiPlugin (DelegatePathExportImport)
+ - [X] DelegatingMultiPlugin (DelegatePathExportImport)
- - [_] SearchPrincipalsPlugin (DelegatePathExportImport)
+ - [X] SearchPrincipalsPlugin (DelegatePathExportImport)
- [_] DynamicGroupsPlugin (use folderish support, w/ handler for
DynamicGroupDefinition? or use a single XML file?)
@@ -351,3 +351,27 @@
def _getExportInfo(self):
return {'title': self.context.title,
}
+
+class DelegatePathExportImport(SimpleXMLExportImport):
+ """ Adapter for dumping / loading plugins with 'delegate_path' via XML.
+ """
+ _FILENAME = 'delegatepath.xml'
+ _ROOT_TAGNAME = 'delegating-plugin'
+
+ def _purgeContext(self):
+ pass
+
+ def _updateFromDOM(self, root):
+ delegate_path = root.attributes.get('delegate_path')
+ if delegate_path is not None:
+ self.context.delegate_path = delegate_path.value
+ else:
+ try:
+ del self.context.delegate_path
+ except AttributeError:
+ pass
+
+ def _getExportInfo(self):
+ return {'title': self.context.title,
+ 'delegate_path': self.context.delegate_path,
+ }
Modified: PluggableAuthService/trunk/plugins/tests/test_exportimport.py
===================================================================
--- PluggableAuthService/trunk/plugins/tests/test_exportimport.py 2005-11-16 18:00:56 UTC (rev 40165)
+++ PluggableAuthService/trunk/plugins/tests/test_exportimport.py 2005-11-16 18:01:36 UTC (rev 40166)
@@ -884,6 +884,120 @@
self.assertEqual( plugin.title, None )
+ class DelegatePathExportImportTests(_TestBase):
+
+ def _getTargetClass(self):
+ from Products.PluggableAuthService.plugins.exportimport \
+ import DelegatePathExportImport
+ return DelegatePathExportImport
+
+ def _makePlugin(self, id, *args, **kw):
+ from OFS.SimpleItem import SimpleItem
+
+ class _Plugin(SimpleItem):
+ title = None
+ delegate_path = ''
+
+ def __init__(self, id, title=None):
+ self._setId(id)
+ if title is not None:
+ self.title = title
+
+ return _Plugin(id, *args, **kw)
+
+ def test_listExportableItems(self):
+ plugin = self._makePlugin('lEI').__of__(self.root)
+ adapter = self._makeOne(plugin)
+
+ self.assertEqual(len(adapter.listExportableItems()), 0)
+ plugin.delegate_path = 'path/to/delegate'
+ self.assertEqual(len(adapter.listExportableItems()), 0)
+
+ def test__getExportInfo_default(self):
+ plugin = self._makePlugin('default').__of__(self.root)
+ adapter = self._makeOne(plugin)
+
+ info = adapter._getExportInfo()
+ self.assertEqual(info['title'], None)
+ self.assertEqual(info['delegate_path'], '')
+
+ def test_export_default(self):
+ plugin = self._makePlugin('default').__of__(self.root)
+ adapter = self._makeOne(plugin)
+
+ context = DummyExportContext(plugin)
+ adapter.export(context, 'plugins', False)
+
+ self.assertEqual(len(context._wrote), 1)
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'plugins/default.xml' )
+ self._compareDOM(text, _DELEGATE_PATH_TEMPLATE_NO_TITLE % "")
+ self.assertEqual( content_type, 'text/xml' )
+
+ def test__getExportInfo_explicitly_set(self):
+ TITLE = 'Plugin Title'
+ DELEGATE_PATH = 'path/to/delegate'
+ plugin = self._makePlugin('explicit').__of__(self.root)
+ plugin.title = TITLE
+ plugin.delegate_path = DELEGATE_PATH
+ adapter = self._makeOne(plugin)
+
+ info = adapter._getExportInfo()
+ self.assertEqual(info['title'], TITLE)
+ self.assertEqual(info['delegate_path'], DELEGATE_PATH)
+
+ def test_export_explicitly_set(self):
+ TITLE = 'Plugin Title'
+ DELEGATE_PATH = 'path/to/delegate'
+ plugin = self._makePlugin('explicit').__of__(self.root)
+ plugin.title = TITLE
+ plugin.delegate_path = DELEGATE_PATH
+ adapter = self._makeOne(plugin)
+
+ context = DummyExportContext(plugin)
+ adapter.export(context, 'plugins', False)
+
+ self.assertEqual(len(context._wrote), 1)
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'plugins/explicit.xml' )
+ self._compareDOM(text,
+ _DELEGATE_PATH_TEMPLATE % (TITLE,
+ DELEGATE_PATH,
+ ))
+ self.assertEqual( content_type, 'text/xml' )
+
+ def test_import_with_title(self):
+ TITLE = 'Plugin Title'
+ DELEGATE_PATH = 'path/to/delegate'
+ plugin = self._makePlugin('with_title').__of__(self.root)
+ adapter = self._makeOne(plugin)
+
+ context = DummyImportContext(plugin)
+ context._files['plugins/with_title.xml'
+ ] = _DELEGATE_PATH_TEMPLATE % (TITLE,
+ DELEGATE_PATH,
+ )
+ adapter.import_(context, 'plugins', False)
+
+ self.assertEqual( plugin.title, TITLE )
+ self.assertEqual( plugin.delegate_path, DELEGATE_PATH )
+
+ def test_import_no_title(self):
+ TITLE = 'Plugin Title'
+ DELEGATE_PATH = 'path/to/delegate'
+ plugin = self._makePlugin('no_title').__of__(self.root)
+ plugin.title = TITLE
+ plugin.delegate_path = DELEGATE_PATH
+ adapter = self._makeOne(plugin)
+
+ context = DummyImportContext(plugin)
+ context._files['plugins/no_title.xml'
+ ] = _DELEGATE_PATH_TEMPLATE_NO_TITLE % DELEGATE_PATH
+ adapter.import_(context, 'plugins', False)
+
+ self.assertEqual( plugin.title, None )
+ self.assertEqual( plugin.delegate_path, DELEGATE_PATH )
+
def test_suite():
suite = unittest.TestSuite((
unittest.makeSuite(ZODBUserManagerExportImportTests),
@@ -892,6 +1006,7 @@
unittest.makeSuite(CookieAuthHelperExportImportTests),
unittest.makeSuite(DomainAuthHelperExportImportTests),
unittest.makeSuite(TitleOnlyExportImportTests),
+ unittest.makeSuite(DelegatePathExportImportTests),
))
return suite
@@ -1022,5 +1137,15 @@
<plug-in title="%s" />
"""
+_DELEGATE_PATH_TEMPLATE_NO_TITLE = """\
+<?xml version="1.0" ?>
+<delegating-plugin delegate_path="%s" />
+"""
+
+_DELEGATE_PATH_TEMPLATE = """\
+<?xml version="1.0" ?>
+<delegating-plugin title="%s" delegate_path="%s" />
+"""
+
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Added: PluggableAuthService/trunk/plugins/xml/delegatepath.xml
===================================================================
--- PluggableAuthService/trunk/plugins/xml/delegatepath.xml 2005-11-16 18:00:56 UTC (rev 40165)
+++ PluggableAuthService/trunk/plugins/xml/delegatepath.xml 2005-11-16 18:01:36 UTC (rev 40166)
@@ -0,0 +1,7 @@
+<?xml version="1.0" ?>
+<delegating-plugin xmlns:tal="http://xml.zope.org/namespaces/tal"
+ title="%s" delegate_path="%s"
+ tal:define="info options/info"
+ tal:attributes="title info/title;
+ delegate_path info/delegate_path;
+ "/>
Property changes on: PluggableAuthService/trunk/plugins/xml/delegatepath.xml
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Zope-CVS
mailing list