Mailing List Archive

SVN: PluggableAuthService/trunk/plugins/ Add GenericSetup export / import support for CookieAuthHelper plugin.
Log message for revision 40147:
Add GenericSetup export / import support for CookieAuthHelper plugin.

Changed:
U PluggableAuthService/trunk/plugins/exportimport.py
U PluggableAuthService/trunk/plugins/tests/test_exportimport.py
A PluggableAuthService/trunk/plugins/xml/cookieauth.xml

-=-
Modified: PluggableAuthService/trunk/plugins/exportimport.py
===================================================================
--- PluggableAuthService/trunk/plugins/exportimport.py 2005-11-16 03:30:21 UTC (rev 40146)
+++ PluggableAuthService/trunk/plugins/exportimport.py 2005-11-16 03:52:08 UTC (rev 40147)
@@ -223,3 +223,36 @@
result.append(k)
return tuple(result)

+class CookieAuthHelperExportImport(SimpleXMLExportImport):
+ """ Adapter for dumping / loading CookieAuthHelper to an XML file.
+ """
+ _FILENAME = 'cookieauth.xml'
+ _ROOT_TAGNAME = 'cookie-auth'
+
+ def _purgeContext(self):
+ pass
+
+ def _updateFromDOM(self, root):
+ cookie_name = root.attributes.get('cookie_name')
+ if cookie_name is not None:
+ self.context.cookie_name = cookie_name.value
+ else:
+ try:
+ del self.context.cookie_name
+ except AttributeError:
+ pass
+
+ login_path = root.attributes.get('login_path')
+ if login_path is not None:
+ self.context.login_path = login_path.value
+ else:
+ try:
+ del self.context.login_path
+ except AttributeError:
+ pass
+
+ def _getExportInfo(self):
+ return {'title': self.context.title,
+ 'cookie_name': self.context.cookie_name,
+ 'login_path': self.context.login_path,
+ }

Modified: PluggableAuthService/trunk/plugins/tests/test_exportimport.py
===================================================================
--- PluggableAuthService/trunk/plugins/tests/test_exportimport.py 2005-11-16 03:30:21 UTC (rev 40146)
+++ PluggableAuthService/trunk/plugins/tests/test_exportimport.py 2005-11-16 03:52:08 UTC (rev 40147)
@@ -468,11 +468,100 @@
self.assertEqual(len(plugin._roles), 0)
self.assertEqual(plugin.title, None)

+ class CookieAuthHelperExportImportTests(_TestBase):
+
+ def _getTargetClass(self):
+ from Products.PluggableAuthService.plugins.exportimport \
+ import CookieAuthHelperExportImport
+ return CookieAuthHelperExportImport
+
+ def _makePlugin(self, id, *args, **kw):
+ from Products.PluggableAuthService.plugins.CookieAuthHelper \
+ import CookieAuthHelper
+ return CookieAuthHelper(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.cookie_name = 'COOKIE_NAME'
+ plugin.login_path = 'LOGIN_PATH'
+ self.assertEqual(len(adapter.listExportableItems()), 0)
+
+ def test__getExportInfo_default(self):
+ from Products.PluggableAuthService.plugins.CookieAuthHelper \
+ import CookieAuthHelper
+ plugin = self._makePlugin('default').__of__(self.root)
+ adapter = self._makeOne(plugin)
+
+ info = adapter._getExportInfo()
+ self.assertEqual(info['title'], None)
+ self.assertEqual(info['cookie_name'], CookieAuthHelper.cookie_name)
+ self.assertEqual(info['login_path'], CookieAuthHelper.login_path)
+
+ def test_export_default(self):
+ from Products.PluggableAuthService.plugins.CookieAuthHelper \
+ import CookieAuthHelper as CAH
+ 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,
+ _COOKIE_AUTH_TEMPLATE_NO_TITLE % (CAH.cookie_name,
+ CAH.login_path,
+ ))
+ self.assertEqual( content_type, 'text/xml' )
+
+ def test__getExportInfo_explicitly_set(self):
+ TITLE = 'Plugin Title'
+ COOKIE_NAME = 'COOKIE_NAME'
+ LOGIN_PATH = 'LOGIN_PATH'
+ plugin = self._makePlugin('explicit').__of__(self.root)
+ plugin.title = TITLE
+ plugin.cookie_name = COOKIE_NAME
+ plugin.login_path = LOGIN_PATH
+ adapter = self._makeOne(plugin)
+
+ info = adapter._getExportInfo()
+ self.assertEqual(info['title'], TITLE)
+ self.assertEqual(info['cookie_name'], COOKIE_NAME)
+ self.assertEqual(info['login_path'], LOGIN_PATH)
+
+ def test_export_explicitly_set(self):
+ TITLE = 'Plugin Title'
+ COOKIE_NAME = 'COOKIE_NAME'
+ LOGIN_PATH = 'LOGIN_PATH'
+ plugin = self._makePlugin('explicit').__of__(self.root)
+ plugin.title = TITLE
+ plugin.cookie_name = COOKIE_NAME
+ plugin.login_path = LOGIN_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,
+ _COOKIE_AUTH_TEMPLATE % (TITLE,
+ COOKIE_NAME,
+ LOGIN_PATH,
+ ))
+ self.assertEqual( content_type, 'text/xml' )
+
def test_suite():
suite = unittest.TestSuite((
unittest.makeSuite(ZODBUserManagerExportImportTests),
unittest.makeSuite(ZODBGroupManagerExportImportTests),
unittest.makeSuite(ZODBRoleManagerExportImportTests),
+ unittest.makeSuite(CookieAuthHelperExportImportTests),
))
return suite

@@ -568,5 +657,15 @@
</zodb-roles>
"""

+_COOKIE_AUTH_TEMPLATE_NO_TITLE = """\
+<?xml version="1.0" ?>
+<cookie-auth cookie_name="%s" login_path="%s" />
+"""
+
+_COOKIE_AUTH_TEMPLATE = """\
+<?xml version="1.0" ?>
+<cookie-auth title="%s" cookie_name="%s" login_path="%s" />
+"""
+
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')

Added: PluggableAuthService/trunk/plugins/xml/cookieauth.xml
===================================================================
--- PluggableAuthService/trunk/plugins/xml/cookieauth.xml 2005-11-16 03:30:21 UTC (rev 40146)
+++ PluggableAuthService/trunk/plugins/xml/cookieauth.xml 2005-11-16 03:52:08 UTC (rev 40147)
@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<cookie-auth xmlns:tal="http://xml.zope.org/namespaces/tal"
+ title="%s" cookie_name="%s" login_path="%s"
+ tal:define="info options/info"
+ tal:attributes="title info/title;
+ cookie_name info/cookie_name;
+ login_path info/login_path;
+ "/>


Property changes on: PluggableAuthService/trunk/plugins/xml/cookieauth.xml
___________________________________________________________________
Name: svn:eol-style
+ native

_______________________________________________
Zope-CVS maillist - Zope-CVS@zope.org
http://mail.zope.org/mailman/listinfo/zope-cvs

Zope CVS instructions: http://dev.zope.org/CVS