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

Tres Seaver cvs-admin at zope.org
Fri May 25 19:10:46 UTC 2012


Log message for revision 126500:
  Add GenericSetup export / import support for the NotCompetent_byRoles plugin.

Changed:
  _U  Products.PluggableAuthService/trunk/
  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/notcompetent.xml

-=-
Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/exportimport.zcml
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/exportimport.zcml	2012-05-25 19:10:39 UTC (rev 126499)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/exportimport.zcml	2012-05-25 19:10:43 UTC (rev 126500)
@@ -112,6 +112,18 @@
       />
 
   <adapter
+      factory=".plugins.exportimport.NotCompetent_byRolesExportImport"
+      provides="Products.GenericSetup.interfaces.IFilesystemExporter"
+      for=".plugins.NotCompetentHelper.NotCompetent_byRoles"
+      />
+
+  <adapter
+      factory=".plugins.exportimport.NotCompetent_byRolesExportImport"
+      provides="Products.GenericSetup.interfaces.IFilesystemImporter"
+      for=".plugins.NotCompetentHelper.NotCompetent_byRoles"
+      />
+
+  <adapter
       factory=".plugins.exportimport.TitleOnlyExportImport"
       provides="Products.GenericSetup.interfaces.IFilesystemExporter"
       for=".plugins.RecursiveGroupsPlugin.IRecursiveGroupsPlugin"

Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/exportimport.py
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/exportimport.py	2012-05-25 19:10:39 UTC (rev 126499)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/exportimport.py	2012-05-25 19:10:43 UTC (rev 126500)
@@ -33,7 +33,7 @@
 
    - [X] LocalRolePlugin (TitleOnlyExportImport)
 
-   - [_] NotCompetent_byRoles
+   - [X] NotCompetent_byRoles (NotCompetent_byRolesExportImport)
 
    - [X] RecursiveGroupsPlugin (TitleOnlyExportImport)
 
@@ -490,3 +490,24 @@
         """ Return the name under which our file data is stored.
         """
         return '%s.py' % self.context.getId()
+
+class NotCompetent_byRolesExportImport(SimpleXMLExportImport):
+    """ Adapter for dumping / loading NCbR plugin.
+    """
+    _FILENAME = 'notcompetent.xml'
+    _ROOT_TAGNAME = 'not-competent-by-roles'
+
+    def _purgeContext(self):
+        pass
+
+    def _updateFromDOM(self, root):
+        roles = []
+        for node in root.getElementsByTagName('role'):
+            role = node.firstChild.wholeText
+            roles.append(role.strip())
+        self.context.roles = tuple(roles)
+
+    def _getExportInfo(self):
+        return {'title': self.context.title,
+                'roles': self.context.roles,
+               }

Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_exportimport.py
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_exportimport.py	2012-05-25 19:10:39 UTC (rev 126499)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_exportimport.py	2012-05-25 19:10:43 UTC (rev 126500)
@@ -1322,6 +1322,104 @@
                     self.assertEqual(protocols, ['digest', 'http'])
 
 
+    class NotCompetent_byRolesExportImportTests(_TestBase):
+
+        def _getTargetClass(self):
+            from Products.PluggableAuthService.plugins.exportimport \
+                import NotCompetent_byRolesExportImport
+            return NotCompetent_byRolesExportImport
+
+        def _makePlugin(self, id, *args, **kw):
+            from \
+              Products.PluggableAuthService.plugins.NotCompetentHelper \
+                import NotCompetent_byRoles
+
+            return NotCompetent_byRoles(id, *args, **kw)
+
+        def test_listExportableItems(self):
+            plugin = self._makePlugin('ncwr').__of__(self.root)
+            adapter = self._makeOne(plugin)
+            self.assertEqual(len(adapter.listExportableItems()), 0)
+            plugin.roles = ('Manager',)
+            self.assertEqual(len(adapter.listExportableItems()), 0)
+
+        def test__getExportInfo_empty(self):
+            plugin = self._makePlugin('empty').__of__(self.root)
+            adapter = self._makeOne(plugin)
+
+            info = adapter._getExportInfo()
+            self.assertEqual(info['title'], '')
+            self.assertEqual(len(info['roles']), 0)
+
+        def test_export_empty(self):
+            _setUpDefaultTraversable()
+
+            plugin = self._makePlugin('empty', 'Plugin Title'
+                                     ).__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_NONCOMPETENT )
+            self.assertEqual( content_type, 'text/xml' )
+
+        def test__getExportInfo_non_empty(self):
+            plugin = self._makePlugin('non_empty', 'TITLE').__of__(self.root)
+            plugin.roles = ('Manager',)
+            adapter = self._makeOne(plugin)
+
+            info = adapter._getExportInfo()
+            self.assertEqual(info['title'], 'TITLE')
+            self.assertEqual(len(info['roles']), 1)
+            self.assertEqual(info['roles'][0], 'Manager')
+
+        def test_export_non_empty(self):
+            _setUpDefaultTraversable()
+
+            plugin = self._makePlugin('non_empty', 'Plugin Title'
+                                     ).__of__(self.root)
+            plugin.roles = ('Manager',)
+            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/non_empty.xml')
+            self._compareDOM(text, _FILLED_NONCOMPETENT)
+            self.assertEqual(content_type, 'text/xml')
+
+        def test_import_empty(self):
+            plugin = self._makePlugin('empty', 'BEFORE').__of__(self.root)
+            plugin.roles = ('Manager',)
+            adapter = self._makeOne(plugin)
+
+            context = DummyImportContext(plugin, encoding='ascii')
+            context._files['plugins/empty.xml'] = _EMPTY_NONCOMPETENT
+
+            adapter.import_(context, 'plugins', False)
+
+            self.assertEqual(plugin.title, 'Plugin Title')
+            self.assertEqual(plugin.roles, ())
+
+        def test_import_non_empty(self):
+            plugin = self._makePlugin('non_empty', 'BEFORE').__of__(self.root)
+            adapter = self._makeOne(plugin)
+
+            context = DummyImportContext(plugin, encoding='ascii')
+            context._files['plugins/non_empty.xml'] = _FILLED_NONCOMPETENT
+
+            adapter.import_(context, 'plugins', False)
+
+            self.assertEqual(plugin.title, 'Plugin Title')
+            self.assertEqual(plugin.roles, ('Manager',))
+
+
     def test_suite():
         return unittest.TestSuite((
             unittest.makeSuite(ZODBUserManagerExportImportTests),
@@ -1333,6 +1431,7 @@
             unittest.makeSuite(DelegatePathExportImportTests),
             unittest.makeSuite(DynamicGroupsPluginExportImportTests),
             unittest.makeSuite(ChallengeProtocolChooserExportImportTests),
+            unittest.makeSuite(NotCompetent_byRolesExportImportTests),
         ))
 
 _EMPTY_ZODB_USERS = """\
@@ -1544,5 +1643,15 @@
 </challenge-protocol-chooser>
 """
 
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')
+_EMPTY_NONCOMPETENT = """\
+<?xml version="1.0" ?>
+<not-competent-by-roles title="Plugin Title">
+</not-competent-by-roles>
+"""
+
+_FILLED_NONCOMPETENT = """\
+<?xml version="1.0" ?>
+<not-competent-by-roles title="Plugin Title">
+<role>Manager</role>
+</not-competent-by-roles>
+"""

Added: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/xml/notcompetent.xml
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/xml/notcompetent.xml	                        (rev 0)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/xml/notcompetent.xml	2012-05-25 19:10:43 UTC (rev 126500)
@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<not-competent-by-roles xmlns:tal="http://xml.zope.org/namespaces/tal"
+    title="TITLE"
+    tal:define="info options/info"
+    tal:attributes="title info/title;">
+ <role tal:repeat="role info/roles"
+       tal:content="role">ROLE</role>
+</not-competent-by-roles>



More information about the checkins mailing list