[Checkins] SVN: Products.PluggableAuthService/trunk/ Add export/import support for the ChallengeProtocolChooser plugin.

Tres Seaver cvs-admin at zope.org
Tue May 8 18:34:50 UTC 2012


Log message for revision 125733:
  Add export/import support for the ChallengeProtocolChooser plugin.
  
  Bump next version to 1.8.0.
  

Changed:
  U   Products.PluggableAuthService/trunk/CHANGES.txt
  U   Products.PluggableAuthService/trunk/Products/PluggableAuthService/exportimport.zcml
  U   Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/exportimport.py
  U   Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_exportimport.py
  A   Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/xml/chooser.xml
  U   Products.PluggableAuthService/trunk/Products/PluggableAuthService/version.txt

-=-
Modified: Products.PluggableAuthService/trunk/CHANGES.txt
===================================================================
--- Products.PluggableAuthService/trunk/CHANGES.txt	2012-05-08 16:41:01 UTC (rev 125732)
+++ Products.PluggableAuthService/trunk/CHANGES.txt	2012-05-08 18:34:46 UTC (rev 125733)
@@ -1,11 +1,13 @@
 Change Log
 ==========
 
-1.7.9 (unreleased)
+1.8.0 (unreleased)
 ------------------
 
-- TBD
+- Added export / import support for the ChallengeProtocolChooser plugin's
+  label - protocols mapping.
 
+
 1.7.8 (2012-05-08)
 ------------------
 

Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/exportimport.zcml
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/exportimport.zcml	2012-05-08 16:41:01 UTC (rev 125732)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/exportimport.zcml	2012-05-08 18:34:46 UTC (rev 125733)
@@ -22,13 +22,13 @@
       />
 
   <adapter
-      factory=".plugins.exportimport.TitleOnlyExportImport"
+      factory=".plugins.exportimport.ChallengeProtocolChooserExportImport"
       provides="Products.GenericSetup.interfaces.IFilesystemExporter"
       for=".plugins.ChallengeProtocolChooser.IChallengeProtocolChooserPlugin"
       />
 
   <adapter
-      factory=".plugins.exportimport.TitleOnlyExportImport"
+      factory=".plugins.exportimport.ChallengeProtocolChooserExportImport"
       provides="Products.GenericSetup.interfaces.IFilesystemImporter"
       for=".plugins.ChallengeProtocolChooser.IChallengeProtocolChooserPlugin"
       />

Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/exportimport.py
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/exportimport.py	2012-05-08 16:41:01 UTC (rev 125732)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/exportimport.py	2012-05-08 18:34:46 UTC (rev 125733)
@@ -437,6 +437,37 @@
                 'groups': group_info,
                }
 
+class ChallengeProtocolChooserExportImport(SimpleXMLExportImport):
+    """ Adapter for dumping / loading ChallengeProtocolChooser to an XML file.
+    """
+    _FILENAME = 'chooser.xml'
+    _ROOT_TAGNAME = 'challenge-protocol-chooser'
+
+    def _purgeContext(self):
+        self.context._map.clear()
+
+    def _updateFromDOM(self, root):
+        for mapping in root.getElementsByTagName('mapping'):
+            label = self._getNodeAttr(mapping, 'label', None)
+            protocols = self._getNodeAttr(mapping, 'protocols', '').split(',')
+            self.context._map[label] = tuple(filter(None, protocols))
+
+    def _getExportInfo(self):
+        from Products.PluggableAuthService.plugins.ChallengeProtocolChooser \
+            import listRequestTypesLabels
+
+        request_type_info = []
+
+        for label in sorted(listRequestTypesLabels()):
+            protocols = sorted(self.context._map.get(label, []))
+            request_type_info.append({'label': label,
+                                      'protocols': protocols,
+                                     })
+
+        return {'title': self.context.title,
+                'request_types': request_type_info,
+               }
+
 class ScriptablePluginExportImport(FolderishExporterImporter):
     """ Export / import the Scriptable type plugin.
     """

Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_exportimport.py
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_exportimport.py	2012-05-08 16:41:01 UTC (rev 125732)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_exportimport.py	2012-05-08 18:34:46 UTC (rev 125733)
@@ -1186,8 +1186,144 @@
             self.assertEqual(len(plugin.listGroupIds()), 0)
             self.assertEqual(plugin.title, None)
 
+
+    class ChallengeProtocolChooserExportImportTests(_TestBase):
+
+        def _getTargetClass(self):
+            from Products.PluggableAuthService.plugins.exportimport \
+                import ChallengeProtocolChooserExportImport
+            return ChallengeProtocolChooserExportImport
+
+        def _makePlugin(self, id, *args, **kw):
+            from \
+              Products.PluggableAuthService.plugins.ChallengeProtocolChooser \
+                import ChallengeProtocolChooser
+
+            return ChallengeProtocolChooser(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.manage_updateProtocolMapping({'WebDAV': ('http',)})
+            self.assertEqual(len(adapter.listExportableItems()), 0)
+
+        def test__getExportInfo_empty(self):
+            from \
+              Products.PluggableAuthService.plugins.ChallengeProtocolChooser \
+                import listRequestTypesLabels
+            labels = sorted(listRequestTypesLabels())
+            plugin = self._makePlugin('empty', None).__of__(self.root)
+            adapter = self._makeOne(plugin)
+
+            info = adapter._getExportInfo()
+            self.assertEqual(info['title'], None)
+            self.assertEqual(len(info['request_types']), len(labels))
+            for r_type, label in zip(info['request_types'], labels):
+                self.assertEqual(r_type['label'], label)
+                self.assertEqual(r_type['protocols'], [])
+
+        def test_export_empty(self):
+            _setUpDefaultTraversable()
+
+            plugin = self._makePlugin('empty', None).__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/empty.xml' )
+            self._compareDOM( text, _EMPTY_CHOOSER )
+            self.assertEqual( content_type, 'text/xml' )
+
+        def test__getExportInfo_non_empty(self):
+            from \
+              Products.PluggableAuthService.plugins.ChallengeProtocolChooser \
+                import listRequestTypesLabels
+            labels = sorted(listRequestTypesLabels())
+            plugin = self._makePlugin('non_empty', None).__of__(self.root)
+            plugin.title = 'TITLE'
+            plugin.manage_updateProtocolMapping({'WebDAV': ('http',),
+                                                 'FTP': ('http',),
+                                                 'XML-RPC': ('http',),
+                                                })
+            adapter = self._makeOne(plugin)
+
+            info = adapter._getExportInfo()
+            self.assertEqual(info['title'], 'TITLE')
+            self.assertEqual(len(info['request_types']), len(labels))
+            for r_type, label in zip(info['request_types'], labels):
+                self.assertEqual(r_type['label'], label)
+                if label == 'Browser':
+                    self.assertEqual(r_type['protocols'], [])
+                else:
+                    self.assertEqual(r_type['protocols'], ['http'])
+
+        def test_export_with_map(self):
+            _setUpDefaultTraversable()
+
+            plugin = self._makePlugin('with_map').__of__(self.root)
+            plugin.title = 'Plugin Title'
+            plugin.manage_updateProtocolMapping({'WebDAV': ('http', 'digest'),
+                                                 'FTP': ('http',),
+                                                 'XML-RPC': ('http', 'digest'),
+                                                })
+
+
+            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/with_map.xml')
+            self._compareDOM(text, _FILLED_CHOOSER)
+            self.assertEqual(content_type, 'text/xml')
+
+        def test_import_empty(self):
+            from \
+              Products.PluggableAuthService.plugins.ChallengeProtocolChooser \
+                import listRequestTypesLabels
+            plugin = self._makePlugin('empty', None).__of__(self.root)
+            adapter = self._makeOne(plugin)
+
+            context = DummyImportContext(plugin, encoding='ascii')
+            context._files['plugins/empty.xml'] = _EMPTY_CHOOSER
+            self.assertEqual(plugin.title, None)
+
+            adapter.import_(context, 'plugins', False)
+
+            for label in  listRequestTypesLabels():
+                protocols = sorted(plugin._map.get(label, ()))
+                self.assertEqual(protocols, [])
+
+        def test_import_non_empty(self):
+            from \
+              Products.PluggableAuthService.plugins.ChallengeProtocolChooser \
+                import listRequestTypesLabels
+            plugin = self._makePlugin('non_empty', None).__of__(self.root)
+            adapter = self._makeOne(plugin)
+
+            context = DummyImportContext(plugin, encoding='ascii')
+            context._files['plugins/non_empty.xml'] = _FILLED_CHOOSER
+            self.assertEqual(plugin.title, None)
+
+            adapter.import_(context, 'plugins', False)
+
+            for label in  listRequestTypesLabels():
+                protocols = sorted(plugin._map.get(label, ()))
+                if label == 'Browser':
+                    self.assertEqual(protocols, [])
+                elif label == 'FTP':
+                    self.assertEqual(protocols, ['http'])
+                else:
+                    self.assertEqual(protocols, ['digest', 'http'])
+
+
     def test_suite():
-        suite = unittest.TestSuite((
+        return unittest.TestSuite((
             unittest.makeSuite(ZODBUserManagerExportImportTests),
             unittest.makeSuite(ZODBGroupManagerExportImportTests),
             unittest.makeSuite(ZODBRoleManagerExportImportTests),
@@ -1196,8 +1332,8 @@
             unittest.makeSuite(TitleOnlyExportImportTests),
             unittest.makeSuite(DelegatePathExportImportTests),
             unittest.makeSuite(DynamicGroupsPluginExportImportTests),
-                        ))
-        return suite
+            unittest.makeSuite(ChallengeProtocolChooserExportImportTests),
+        ))
 
 _EMPTY_ZODB_USERS = """\
 <?xml version="1.0" ?>
@@ -1376,5 +1512,37 @@
 </dynamic-groups>
 """
 
+_EMPTY_CHOOSER = """\
+<?xml version="1.0" ?>
+<challenge-protocol-chooser>
+<mapping label="Browser" protocols="" />
+<mapping label="FTP" protocols="" />
+<mapping label="WebDAV" protocols="" />
+<mapping label="XML-RPC" protocols="" />
+</challenge-protocol-chooser>
+"""
+
+_FILLED_CHOOSER = """\
+<?xml version="1.0" ?>
+<challenge-protocol-chooser title="Plugin Title">
+<mapping
+    label="Browser"
+    protocols=""
+    />
+<mapping
+    label="FTP"
+    protocols="http"
+    />
+<mapping
+    label="WebDAV"
+    protocols="digest,http"
+    />
+<mapping
+    label="XML-RPC"
+    protocols="digest,http"
+    />
+</challenge-protocol-chooser>
+"""
+
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')

Added: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/xml/chooser.xml
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/xml/chooser.xml	                        (rev 0)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/xml/chooser.xml	2012-05-08 18:34:46 UTC (rev 125733)
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<challenge-protocol-chooser
+    xmlns:tal="http://xml.zope.org/namespaces/tal"
+    title="PLUGIN TITLE"
+    tal:define="info options/info "
+    tal:attributes="title info/title;
+                            "
+>
+ <mapping label="LABEL"
+        protocols="PROTOCOL"
+        tal:repeat="req_type info/request_types"
+        tal:attributes="label req_type/label;
+                        protocols python:','.join(req_type['protocols']);
+                       " />
+</challenge-protocol-chooser>

Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/version.txt
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/version.txt	2012-05-08 16:41:01 UTC (rev 125732)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/version.txt	2012-05-08 18:34:46 UTC (rev 125733)
@@ -1 +1 @@
-1.7.9dev
+1.8.0dev



More information about the checkins mailing list