Back to index

plone3  3.1.7
test_exportimport.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights
00004 # Reserved.
00005 #
00006 # This software is subject to the provisions of the Zope Public License,
00007 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this
00008 # distribution.
00009 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00010 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00011 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00012 # FOR A PARTICULAR PURPOSE.
00013 #
00014 ##############################################################################
00015 """ Unit tests for plugin.exportimport
00016 
00017 $Id: test_exportimport.py 75977 2007-05-27 18:05:47Z jens $
00018 """
00019 
00020 import unittest
00021 
00022 try:
00023     import Products.GenericSetup
00024 except ImportError:  # No GenericSetup, so no tests
00025 
00026     print 'XXXX:  No GenericSetup!'
00027     def test_suite():
00028         return unittest.TestSuite()
00029 
00030 else:
00031 
00032     from Products.GenericSetup.tests.conformance \
00033             import ConformsToIFilesystemExporter
00034     from Products.GenericSetup.tests.conformance \
00035             import ConformsToIFilesystemImporter
00036 
00037     from Products.GenericSetup.tests.common import BaseRegistryTests
00038     from Products.GenericSetup.tests.common import DummyExportContext
00039     from Products.GenericSetup.tests.common import DummyImportContext
00040 
00041     class _TestBase(BaseRegistryTests,
00042                     ConformsToIFilesystemExporter,
00043                     ConformsToIFilesystemImporter,
00044                     ):
00045 
00046         def _makeOne(self, context, *args, **kw):
00047             return self._getTargetClass()(context, *args, **kw)
00048 
00049     class ZODBUserManagerExportImportTests(_TestBase):
00050 
00051         def _getTargetClass(self):
00052             from Products.PluggableAuthService.plugins.exportimport \
00053                 import ZODBUserManagerExportImport
00054             return ZODBUserManagerExportImport
00055 
00056         def _makePlugin(self, id='zodbusers', *args, **kw):
00057             from Products.PluggableAuthService.plugins.ZODBUserManager \
00058                 import ZODBUserManager
00059             return ZODBUserManager(id, *args, **kw)
00060 
00061         def test_listExportableItems(self):
00062             plugin = self._makePlugin('lEI').__of__(self.root)
00063             adapter = self._makeOne(plugin)
00064             self.assertEqual(len(adapter.listExportableItems()), 0)
00065             plugin.addUser('foo', 'bar', 'baz')
00066             self.assertEqual(len(adapter.listExportableItems()), 0)
00067 
00068         def test__getExportInfo_empty(self):
00069             plugin = self._makePlugin('empty').__of__(self.root)
00070             adapter = self._makeOne(plugin)
00071 
00072             info = adapter._getExportInfo()
00073             self.assertEqual(info['title'], None)
00074             self.assertEqual(len(info['users']), 0)
00075 
00076         def test_export_empty(self):
00077             plugin = self._makePlugin('empty').__of__(self.root)
00078             adapter = self._makeOne(plugin)
00079 
00080             context = DummyExportContext(plugin)
00081             adapter.export(context, 'plugins', False)
00082 
00083             self.assertEqual( len( context._wrote ), 1 )
00084             filename, text, content_type = context._wrote[ 0 ]
00085             self.assertEqual( filename, 'plugins/empty.xml' )
00086             self._compareDOM( text, _EMPTY_ZODB_USERS )
00087             self.assertEqual( content_type, 'text/xml' )
00088 
00089         def test__getExportInfo_with_users(self):
00090 
00091             plugin = self._makePlugin('with_users').__of__(self.root)
00092             plugin.title = 'Plugin Title'
00093             source_info = []
00094 
00095             for info in _ZODB_USER_INFO:
00096                 info = info.copy()
00097                 plugin.addUser(**info)
00098                 hash = plugin._user_passwords[info['user_id']]
00099                 info['password_hash'] = hash
00100                 source_info.append(info)
00101 
00102             adapter = self._makeOne(plugin)
00103 
00104             info = adapter._getExportInfo()
00105             self.assertEqual(info['title'], 'Plugin Title')
00106             self.assertEqual(len(info['users']), len(source_info))
00107 
00108             for x, y in zip(info['users'], source_info):
00109                 self.assertEqual(x['user_id'], y['user_id'])
00110                 self.assertEqual(x['login_name'], y['login_name'])
00111                 self.assertEqual(x['password_hash'], y['password_hash'])
00112 
00113         def test_export_with_users(self):
00114 
00115             plugin = self._makePlugin('with_users').__of__(self.root)
00116             plugin.title = 'Plugin Title'
00117 
00118             hashes = []
00119             for info in _ZODB_USER_INFO:
00120                 plugin.addUser(**info)
00121                 hash = plugin._user_passwords[info['user_id']]
00122                 hashes.append(hash)
00123 
00124             adapter = self._makeOne(plugin)
00125             context = DummyExportContext(plugin)
00126             adapter.export(context, 'plugins', False)
00127 
00128             self.assertEqual( len(context._wrote), 1)
00129             filename, text, content_type = context._wrote[ 0 ]
00130             self.assertEqual(filename, 'plugins/with_users.xml')
00131             self._compareDOM(text, _FILLED_ZODB_USERS % tuple(hashes))
00132             self.assertEqual(content_type, 'text/xml')
00133 
00134         def test_import_empty(self):
00135             HASHES = ('abcde', 'wxyz')
00136             plugin = self._makePlugin('empty').__of__(self.root)
00137             adapter = self._makeOne(plugin)
00138 
00139             context = DummyImportContext(plugin)
00140             context._files['plugins/empty.xml'] = _FILLED_ZODB_USERS % HASHES
00141             self.assertEqual(plugin.title, None)
00142 
00143             adapter.import_(context, 'plugins', False)
00144 
00145             self.assertEqual(len(plugin._user_passwords), len(_ZODB_USER_INFO))
00146             self.assertEqual(plugin.title, 'Plugin Title')
00147 
00148             for info, hash in zip(_ZODB_USER_INFO, HASHES):
00149                 user_id = info['user_id']
00150                 self.assertEqual(plugin.getLoginForUserId(user_id),
00151                                 info['login_name'])
00152                 self.assertEqual(plugin._user_passwords[user_id], hash)
00153 
00154         def test_import_without_purge_leaves_existing_users(self):
00155 
00156             plugin = self._makePlugin('with_users').__of__(self.root)
00157             plugin.title = 'Plugin Title'
00158 
00159             for info in _ZODB_USER_INFO:
00160                 plugin.addUser(**info)
00161 
00162             adapter = self._makeOne(plugin)
00163 
00164             context = DummyImportContext(plugin, purge=False)
00165             context._files['plugins/with_users.xml'] = _EMPTY_ZODB_USERS
00166 
00167             self.assertEqual(len(plugin._user_passwords), len(_ZODB_USER_INFO))
00168             adapter.import_(context, 'plugins', False)
00169             self.assertEqual(len(plugin._user_passwords), len(_ZODB_USER_INFO))
00170             self.assertEqual(plugin.title, None)
00171 
00172         def test_import_with_purge_wipes_existing_users(self):
00173 
00174             plugin = self._makePlugin('with_users').__of__(self.root)
00175             plugin.title = 'Plugin Title'
00176 
00177             for info in _ZODB_USER_INFO:
00178                 plugin.addUser(**info)
00179 
00180             adapter = self._makeOne(plugin)
00181 
00182             context = DummyImportContext(plugin, purge=True)
00183             context._files['plugins/with_users.xml'] = _EMPTY_ZODB_USERS
00184 
00185             self.assertEqual(len(plugin._user_passwords), len(_ZODB_USER_INFO))
00186             adapter.import_(context, 'plugins', False)
00187             self.assertEqual(len(plugin._user_passwords), 0)
00188             self.assertEqual(plugin.title, None)
00189 
00190     class ZODBGroupManagerExportImportTests(_TestBase):
00191 
00192         def _getTargetClass(self):
00193             from Products.PluggableAuthService.plugins.exportimport \
00194                 import ZODBGroupManagerExportImport
00195             return ZODBGroupManagerExportImport
00196 
00197         def _makePlugin(self, id, *args, **kw):
00198             from Products.PluggableAuthService.plugins.ZODBGroupManager \
00199                 import ZODBGroupManager
00200             return ZODBGroupManager(id, *args, **kw)
00201 
00202         def test_listExportableItems(self):
00203             plugin = self._makePlugin('lEI').__of__(self.root)
00204             adapter = self._makeOne(plugin)
00205             self.assertEqual(len(adapter.listExportableItems()), 0)
00206             plugin.addGroup('group_id', 'title', 'description')
00207             self.assertEqual(len(adapter.listExportableItems()), 0)
00208 
00209         def test__getExportInfo_empty(self):
00210             plugin = self._makePlugin('empty').__of__(self.root)
00211             adapter = self._makeOne(plugin)
00212 
00213             info = adapter._getExportInfo()
00214             self.assertEqual(info['title'], None)
00215             self.assertEqual(len(info['groups']), 0)
00216 
00217         def test_export_empty(self):
00218             plugin = self._makePlugin('empty').__of__(self.root)
00219             adapter = self._makeOne(plugin)
00220 
00221             context = DummyExportContext(plugin)
00222             adapter.export(context, 'plugins', False)
00223 
00224             self.assertEqual( len( context._wrote ), 1 )
00225             filename, text, content_type = context._wrote[ 0 ]
00226             self.assertEqual( filename, 'plugins/empty.xml' )
00227             self._compareDOM( text, _EMPTY_ZODB_GROUPS )
00228             self.assertEqual( content_type, 'text/xml' )
00229 
00230         def test__getExportInfo_with_groups(self):
00231 
00232             plugin = self._makePlugin('with_groups').__of__(self.root)
00233             plugin.title = 'Plugin Title'
00234 
00235             for g in _ZODB_GROUP_INFO:
00236                 plugin.addGroup(g['group_id'], g['title'], g['description'])
00237                 for principal in g['principals']:
00238                     plugin.addPrincipalToGroup(principal, g['group_id'])
00239 
00240             adapter = self._makeOne(plugin)
00241 
00242             info = adapter._getExportInfo()
00243             self.assertEqual(info['title'], 'Plugin Title')
00244             self.assertEqual(len(info['groups']), len(_ZODB_GROUP_INFO))
00245 
00246             for x, y in zip(info['groups'], _ZODB_GROUP_INFO):
00247                 self.assertEqual(x, y)
00248 
00249         def test_export_with_groups(self):
00250 
00251             plugin = self._makePlugin('with_groups').__of__(self.root)
00252             plugin.title = 'Plugin Title'
00253 
00254             for g in _ZODB_GROUP_INFO:
00255                 plugin.addGroup(g['group_id'], g['title'], g['description'])
00256                 for principal in g['principals']:
00257                     plugin.addPrincipalToGroup(principal, g['group_id'])
00258 
00259             adapter = self._makeOne(plugin)
00260             context = DummyExportContext(plugin)
00261             adapter.export(context, 'plugins', False)
00262 
00263             self.assertEqual( len(context._wrote), 1)
00264             filename, text, content_type = context._wrote[ 0 ]
00265             self.assertEqual(filename, 'plugins/with_groups.xml')
00266             self._compareDOM(text, _FILLED_ZODB_GROUPS)
00267             self.assertEqual(content_type, 'text/xml')
00268 
00269         def test_import_empty(self):
00270             plugin = self._makePlugin('empty').__of__(self.root)
00271             adapter = self._makeOne(plugin)
00272 
00273             context = DummyImportContext(plugin)
00274             context._files['plugins/empty.xml'] = _FILLED_ZODB_GROUPS
00275             self.assertEqual(plugin.title, None)
00276 
00277             adapter.import_(context, 'plugins', False)
00278 
00279             found = plugin.listGroupInfo()
00280             self.assertEqual(len(found), len(_ZODB_GROUP_INFO))
00281             self.assertEqual(plugin.title, 'Plugin Title')
00282 
00283             for finfo, ginfo in zip(found, _ZODB_GROUP_INFO):
00284                 self.assertEqual(finfo['id'], ginfo['group_id'])
00285                 self.assertEqual(finfo['title'], ginfo['title'])
00286                 self.assertEqual(finfo['description'], ginfo['description'])
00287                 for principal_id in ginfo['principals']:
00288                     groups = plugin._principal_groups[principal_id]
00289                     self.failUnless(ginfo['group_id'] in groups)
00290 
00291         def test_import_without_purge_leaves_existing_users(self):
00292 
00293             plugin = self._makePlugin('with_groups').__of__(self.root)
00294             plugin.title = 'Plugin Title'
00295 
00296             for g in _ZODB_GROUP_INFO:
00297                 plugin.addGroup(g['group_id'], g['title'], g['description'])
00298                 for principal in g['principals']:
00299                     plugin.addPrincipalToGroup(principal, g['group_id'])
00300 
00301             adapter = self._makeOne(plugin)
00302 
00303             context = DummyImportContext(plugin, purge=False)
00304             context._files['plugins/with_groups.xml'] = _EMPTY_ZODB_GROUPS
00305 
00306             self.assertEqual(len(plugin._groups), len(_ZODB_GROUP_INFO))
00307             adapter.import_(context, 'plugins', False)
00308             self.assertEqual(len(plugin._groups), len(_ZODB_GROUP_INFO))
00309             self.assertEqual(plugin.title, None)
00310 
00311         def test_import_with_purge_wipes_existing_users(self):
00312 
00313             plugin = self._makePlugin('with_groups').__of__(self.root)
00314             plugin.title = 'Plugin Title'
00315 
00316             for g in _ZODB_GROUP_INFO:
00317                 plugin.addGroup(g['group_id'], g['title'], g['description'])
00318                 for principal in g['principals']:
00319                     plugin.addPrincipalToGroup(principal, g['group_id'])
00320 
00321             adapter = self._makeOne(plugin)
00322 
00323             context = DummyImportContext(plugin, purge=True)
00324             context._files['plugins/with_groups.xml'] = _EMPTY_ZODB_GROUPS
00325 
00326             self.assertEqual(len(plugin._groups), len(_ZODB_GROUP_INFO))
00327             adapter.import_(context, 'plugins', False)
00328             self.assertEqual(len(plugin._groups), 0)
00329             self.assertEqual(plugin.title, None)
00330 
00331     class ZODBRoleManagerExportImportTests(_TestBase):
00332 
00333         def _getTargetClass(self):
00334             from Products.PluggableAuthService.plugins.exportimport \
00335                 import ZODBRoleManagerExportImport
00336             return ZODBRoleManagerExportImport
00337 
00338         def _makePlugin(self, id, *args, **kw):
00339             from Products.PluggableAuthService.plugins.ZODBRoleManager \
00340                 import ZODBRoleManager
00341             return ZODBRoleManager(id, *args, **kw)
00342 
00343         def test_listExportableItems(self):
00344             plugin = self._makePlugin('lEI').__of__(self.root)
00345             adapter = self._makeOne(plugin)
00346 
00347             self.assertEqual(len(adapter.listExportableItems()), 0)
00348             plugin.addRole('role_id', 'title', 'description')
00349             self.assertEqual(len(adapter.listExportableItems()), 0)
00350 
00351         def test__getExportInfo_empty(self):
00352             plugin = self._makePlugin('empty').__of__(self.root)
00353             adapter = self._makeOne(plugin)
00354 
00355             info = adapter._getExportInfo()
00356             self.assertEqual(info['title'], None)
00357             self.assertEqual(len(info['roles']), 0)
00358 
00359         def test_export_empty(self):
00360             plugin = self._makePlugin('empty').__of__(self.root)
00361             adapter = self._makeOne(plugin)
00362 
00363             context = DummyExportContext(plugin)
00364             adapter.export(context, 'plugins', False)
00365 
00366             self.assertEqual( len( context._wrote ), 1 )
00367             filename, text, content_type = context._wrote[ 0 ]
00368             self.assertEqual( filename, 'plugins/empty.xml' )
00369             self._compareDOM( text, _EMPTY_ZODB_ROLES )
00370             self.assertEqual( content_type, 'text/xml' )
00371 
00372         def test__getExportInfo_with_roles(self):
00373 
00374             plugin = self._makePlugin('with_roles').__of__(self.root)
00375             plugin.title = 'Plugin Title'
00376 
00377             for r in _ZODB_ROLE_INFO:
00378                 plugin.addRole(r['role_id'], r['title'], r['description'])
00379                 for principal in r['principals']:
00380                     plugin.assignRoleToPrincipal(r['role_id'], principal)
00381 
00382             adapter = self._makeOne(plugin)
00383 
00384             info = adapter._getExportInfo()
00385             self.assertEqual(info['title'], 'Plugin Title')
00386             self.assertEqual(len(info['roles']), len(_ZODB_ROLE_INFO))
00387 
00388             for x, y in zip(info['roles'], _ZODB_ROLE_INFO):
00389                 self.assertEqual(x, y)
00390 
00391         def test_export_with_roles(self):
00392 
00393             plugin = self._makePlugin('with_roles').__of__(self.root)
00394             plugin.title = 'Plugin Title'
00395 
00396             for r in _ZODB_ROLE_INFO:
00397                 plugin.addRole(r['role_id'], r['title'], r['description'])
00398                 for principal in r['principals']:
00399                     plugin.assignRoleToPrincipal(r['role_id'], principal)
00400 
00401             adapter = self._makeOne(plugin)
00402             context = DummyExportContext(plugin)
00403             adapter.export(context, 'plugins', False)
00404 
00405             self.assertEqual( len(context._wrote), 1)
00406             filename, text, content_type = context._wrote[ 0 ]
00407             self.assertEqual(filename, 'plugins/with_roles.xml')
00408             self._compareDOM(text, _FILLED_ZODB_ROLES)
00409             self.assertEqual(content_type, 'text/xml')
00410 
00411         def test_import_empty(self):
00412             plugin = self._makePlugin('empty').__of__(self.root)
00413             adapter = self._makeOne(plugin)
00414 
00415             context = DummyImportContext(plugin)
00416             context._files['plugins/empty.xml'] = _FILLED_ZODB_ROLES
00417             self.assertEqual(plugin.title, None)
00418 
00419             adapter.import_(context, 'plugins', False)
00420 
00421             found = plugin.listRoleInfo()
00422             self.assertEqual(len(found), len(_ZODB_ROLE_INFO))
00423             self.assertEqual(plugin.title, 'Plugin Title')
00424 
00425             for finfo, rinfo in zip(found, _ZODB_ROLE_INFO):
00426                 self.assertEqual(finfo['id'], rinfo['role_id'])
00427                 self.assertEqual(finfo['title'], rinfo['title'])
00428                 self.assertEqual(finfo['description'], rinfo['description'])
00429                 for principal_id in rinfo['principals']:
00430                     roles = plugin._principal_roles[principal_id]
00431                     self.failUnless(rinfo['role_id'] in roles)
00432 
00433         def test_import_without_purge_leaves_existing_users(self):
00434 
00435             plugin = self._makePlugin('with_roles').__of__(self.root)
00436             plugin.title = 'Plugin Title'
00437 
00438             for r in _ZODB_ROLE_INFO:
00439                 plugin.addRole(r['role_id'], r['title'], r['description'])
00440                 for principal in r['principals']:
00441                     plugin.assignRoleToPrincipal(r['role_id'], principal)
00442 
00443             adapter = self._makeOne(plugin)
00444 
00445             context = DummyImportContext(plugin, purge=False)
00446             context._files['plugins/with_roles.xml'] = _EMPTY_ZODB_ROLES
00447 
00448             self.assertEqual(len(plugin._roles), len(_ZODB_ROLE_INFO))
00449             adapter.import_(context, 'plugins', False)
00450             self.assertEqual(len(plugin._roles), len(_ZODB_ROLE_INFO))
00451             self.assertEqual(plugin.title, None)
00452 
00453         def test_import_with_purge_wipes_existing_users(self):
00454 
00455             plugin = self._makePlugin('with_roles').__of__(self.root)
00456             plugin.title = 'Plugin Title'
00457 
00458             for r in _ZODB_ROLE_INFO:
00459                 plugin.addRole(r['role_id'], r['title'], r['description'])
00460                 for principal in r['principals']:
00461                     plugin.assignRoleToPrincipal(r['role_id'], principal)
00462 
00463             adapter = self._makeOne(plugin)
00464 
00465             context = DummyImportContext(plugin, purge=True)
00466             context._files['plugins/with_roles.xml'] = _EMPTY_ZODB_ROLES
00467 
00468             self.assertEqual(len(plugin._roles), len(_ZODB_ROLE_INFO))
00469             adapter.import_(context, 'plugins', False)
00470             self.assertEqual(len(plugin._roles), 0)
00471             self.assertEqual(plugin.title, None)
00472 
00473     class CookieAuthHelperExportImportTests(_TestBase):
00474 
00475         def _getTargetClass(self):
00476             from Products.PluggableAuthService.plugins.exportimport \
00477                 import CookieAuthHelperExportImport
00478             return CookieAuthHelperExportImport
00479 
00480         def _makePlugin(self, id, *args, **kw):
00481             from Products.PluggableAuthService.plugins.CookieAuthHelper \
00482                 import CookieAuthHelper
00483             return CookieAuthHelper(id, *args, **kw)
00484 
00485         def test_listExportableItems(self):
00486             plugin = self._makePlugin('lEI').__of__(self.root)
00487             adapter = self._makeOne(plugin)
00488 
00489             self.assertEqual(len(adapter.listExportableItems()), 0)
00490             plugin.cookie_name = 'COOKIE_NAME'
00491             plugin.login_path = 'LOGIN_PATH'
00492             self.assertEqual(len(adapter.listExportableItems()), 0)
00493 
00494         def test__getExportInfo_default(self):
00495             from Products.PluggableAuthService.plugins.CookieAuthHelper \
00496                 import CookieAuthHelper
00497             plugin = self._makePlugin('default').__of__(self.root)
00498             adapter = self._makeOne(plugin)
00499 
00500             info = adapter._getExportInfo()
00501             self.assertEqual(info['title'], None)
00502             self.assertEqual(info['cookie_name'], CookieAuthHelper.cookie_name)
00503             self.assertEqual(info['login_path'], CookieAuthHelper.login_path)
00504 
00505         def test_export_default(self):
00506             from Products.PluggableAuthService.plugins.CookieAuthHelper \
00507                 import CookieAuthHelper as CAH
00508             plugin = self._makePlugin('default').__of__(self.root)
00509             adapter = self._makeOne(plugin)
00510 
00511             context = DummyExportContext(plugin)
00512             adapter.export(context, 'plugins', False)
00513 
00514             self.assertEqual(len(context._wrote), 1)
00515             filename, text, content_type = context._wrote[0]
00516             self.assertEqual(filename, 'plugins/default.xml' )
00517             self._compareDOM(text,
00518                              _COOKIE_AUTH_TEMPLATE_NO_TITLE % (CAH.cookie_name,
00519                                                                CAH.login_path,
00520                                                               ))
00521             self.assertEqual( content_type, 'text/xml' )
00522 
00523         def test__getExportInfo_explicitly_set(self):
00524             TITLE = 'Plugin Title'
00525             COOKIE_NAME = 'COOKIE_NAME'
00526             LOGIN_PATH = 'LOGIN_PATH'
00527             plugin = self._makePlugin('explicit').__of__(self.root)
00528             plugin.title = TITLE
00529             plugin.cookie_name = COOKIE_NAME
00530             plugin.login_path = LOGIN_PATH
00531             adapter = self._makeOne(plugin)
00532 
00533             info = adapter._getExportInfo()
00534             self.assertEqual(info['title'], TITLE)
00535             self.assertEqual(info['cookie_name'], COOKIE_NAME)
00536             self.assertEqual(info['login_path'], LOGIN_PATH)
00537 
00538         def test_export_explicitly_set(self):
00539             TITLE = 'Plugin Title'
00540             COOKIE_NAME = 'COOKIE_NAME'
00541             LOGIN_PATH = 'LOGIN_PATH'
00542             plugin = self._makePlugin('explicit').__of__(self.root)
00543             plugin.title = TITLE
00544             plugin.cookie_name = COOKIE_NAME
00545             plugin.login_path = LOGIN_PATH
00546             adapter = self._makeOne(plugin)
00547 
00548             context = DummyExportContext(plugin)
00549             adapter.export(context, 'plugins', False)
00550 
00551             self.assertEqual(len(context._wrote), 1)
00552             filename, text, content_type = context._wrote[0]
00553             self.assertEqual(filename, 'plugins/explicit.xml' )
00554             self._compareDOM(text,
00555                              _COOKIE_AUTH_TEMPLATE % (TITLE,
00556                                                       COOKIE_NAME,
00557                                                       LOGIN_PATH,
00558                                                      ))
00559             self.assertEqual( content_type, 'text/xml' )
00560 
00561         def test_import_with_title(self):
00562             TITLE = 'Plugin Title'
00563             COOKIE_NAME = 'COOKIE_NAME'
00564             LOGIN_PATH = 'LOGIN_PATH'
00565             plugin = self._makePlugin('with_title').__of__(self.root)
00566             adapter = self._makeOne(plugin)
00567 
00568             context = DummyImportContext(plugin)
00569             context._files['plugins/with_title.xml'
00570                           ] = _COOKIE_AUTH_TEMPLATE % (TITLE,
00571                                                        COOKIE_NAME,
00572                                                        LOGIN_PATH,
00573                                                       )
00574             adapter.import_(context, 'plugins', False)
00575 
00576             self.assertEqual( plugin.title, TITLE )
00577             self.assertEqual( plugin.cookie_name, COOKIE_NAME )
00578             self.assertEqual( plugin.login_path, LOGIN_PATH )
00579 
00580         def test_import_no_title(self):
00581             TITLE = 'Plugin Title'
00582             COOKIE_NAME = 'COOKIE_NAME'
00583             LOGIN_PATH = 'LOGIN_PATH'
00584             plugin = self._makePlugin('no_title').__of__(self.root)
00585             plugin.title = TITLE
00586             plugin.cookie_name = COOKIE_NAME
00587             plugin.login_path = LOGIN_PATH
00588             adapter = self._makeOne(plugin)
00589 
00590             context = DummyImportContext(plugin)
00591             context._files['plugins/no_title.xml'
00592                           ] = _COOKIE_AUTH_TEMPLATE_NO_TITLE % (COOKIE_NAME,
00593                                                                 LOGIN_PATH,
00594                                                                )
00595             adapter.import_(context, 'plugins', False)
00596 
00597             self.assertEqual( plugin.title, None )
00598             self.assertEqual( plugin.cookie_name, COOKIE_NAME )
00599             self.assertEqual( plugin.login_path, LOGIN_PATH )
00600 
00601     class DomainAuthHelperExportImportTests(_TestBase):
00602 
00603         def _getTargetClass(self):
00604             from Products.PluggableAuthService.plugins.exportimport \
00605                 import DomainAuthHelperExportImport
00606             return DomainAuthHelperExportImport
00607 
00608         def _makePlugin(self, id, *args, **kw):
00609             from Products.PluggableAuthService.plugins.DomainAuthHelper \
00610                 import DomainAuthHelper
00611             return DomainAuthHelper(id, *args, **kw)
00612 
00613         def test_listExportableItems(self):
00614             plugin = self._makePlugin('lEI').__of__(self.root)
00615             adapter = self._makeOne(plugin)
00616 
00617             self.assertEqual(len(adapter.listExportableItems()), 0)
00618             plugin.cookie_name = 'COOKIE_NAME'
00619             plugin.login_path = 'LOGIN_PATH'
00620             plugin.manage_addMapping(user_id='user_id',
00621                                      match_type='equals',
00622                                      match_string='host.example.com',
00623                                      roles=['foo', 'bar'],
00624                                     )
00625             self.assertEqual(len(adapter.listExportableItems()), 0)
00626 
00627         def test__getExportInfo_empty(self):
00628             plugin = self._makePlugin('empty', None).__of__(self.root)
00629             adapter = self._makeOne(plugin)
00630 
00631             info = adapter._getExportInfo()
00632             self.assertEqual(info['title'], None)
00633             self.assertEqual(len(info['map']), 0)
00634 
00635         def test_export_empty(self):
00636             plugin = self._makePlugin('empty', None).__of__(self.root)
00637             adapter = self._makeOne(plugin)
00638 
00639             context = DummyExportContext(plugin)
00640             adapter.export(context, 'plugins', False)
00641 
00642             self.assertEqual( len( context._wrote ), 1 )
00643             filename, text, content_type = context._wrote[ 0 ]
00644             self.assertEqual( filename, 'plugins/empty.xml' )
00645             self._compareDOM( text, _EMPTY_DOMAIN_AUTH )
00646             self.assertEqual( content_type, 'text/xml' )
00647 
00648         def test__getExportInfo_with_map(self):
00649             TITLE = 'With Map'
00650             USER_ID = 'some_user_id'
00651             DOMAIN = 'host.example.com'
00652             ROLES = ['foo', 'bar']
00653             plugin = self._makePlugin('with_map', TITLE).__of__(self.root)
00654             adapter = self._makeOne(plugin)
00655 
00656             plugin.manage_addMapping(user_id=USER_ID,
00657                                      match_type='equals',
00658                                      match_string=DOMAIN,
00659                                      roles=ROLES,
00660                                     )
00661 
00662             info = adapter._getExportInfo()
00663             self.assertEqual(info['title'], TITLE)
00664             user_map = info['map']
00665             self.assertEqual(len(user_map), 1)
00666             self.failUnless(USER_ID in user_map)
00667             match_list = user_map[USER_ID]
00668             self.assertEqual(len(match_list), 1)
00669             match = match_list[0]
00670             self.assertEqual(match['username'], USER_ID)
00671             self.assertEqual(match['match_type'], 'equals')
00672             self.assertEqual(match['match_string'], DOMAIN)
00673             self.assertEqual(match['roles'], ','.join(ROLES))
00674 
00675         def test_export_with_map(self):
00676             TITLE = 'With Map'
00677             USER_ID = 'some_user_id'
00678             DOMAIN = 'host.example.com'
00679             ROLES = ['foo', 'bar']
00680             plugin = self._makePlugin('with_map', TITLE).__of__(self.root)
00681             adapter = self._makeOne(plugin)
00682 
00683             plugin.manage_addMapping(user_id=USER_ID,
00684                                      match_type='equals',
00685                                      match_string=DOMAIN,
00686                                      roles=ROLES,
00687                                     )
00688 
00689             context = DummyExportContext(plugin)
00690             adapter.export(context, 'plugins', False)
00691 
00692             self.assertEqual(len(context._wrote), 1)
00693             filename, text, content_type = context._wrote[0]
00694             self.assertEqual(filename, 'plugins/with_map.xml' )
00695             self._compareDOM(text,
00696                              _FILLED_DOMAIN_AUTH %
00697                               (TITLE,
00698                                USER_ID,
00699                                DOMAIN,
00700                                'equals',
00701                                ','.join(ROLES),
00702                                USER_ID,
00703                               ))
00704             self.assertEqual( content_type, 'text/xml' )
00705 
00706         def test_import_empty(self):
00707             TITLE = 'With Map'
00708             USER_ID = 'some_user_id'
00709             DOMAIN = 'host.example.com'
00710             ROLES = ['foo', 'bar']
00711             plugin = self._makePlugin('empty').__of__(self.root)
00712             adapter = self._makeOne(plugin)
00713 
00714             context = DummyImportContext(plugin)
00715             context._files['plugins/empty.xml'
00716                           ] = _FILLED_DOMAIN_AUTH % (TITLE,
00717                                                      USER_ID,
00718                                                      DOMAIN,
00719                                                      'equals',
00720                                                      ','.join(ROLES),
00721                                                      USER_ID,
00722                                                     )
00723             self.assertEqual(plugin.title, '')
00724 
00725             adapter.import_(context, 'plugins', False)
00726 
00727             self.assertEqual(len(plugin._domain_map), 1)
00728             self.assertEqual(plugin.title, TITLE)
00729 
00730             username, match_list = plugin._domain_map.items()[0]
00731             self.assertEqual(username, USER_ID)
00732             self.assertEqual(len(match_list), 1)
00733             match = match_list[0]
00734             self.assertEqual(match['username'], USER_ID)
00735             self.assertEqual(match['match_string'], DOMAIN)
00736             self.assertEqual(match['match_real'], DOMAIN)
00737             self.assertEqual(match['match_type'], 'equals')
00738             self.assertEqual(len(match['roles']), len(ROLES))
00739             for role in ROLES:
00740                 self.failUnless(role in match['roles'])
00741 
00742         def test_import_without_purge_leaves_existing_users(self):
00743             TITLE = 'With Map'
00744             USER_ID = 'some_user_id'
00745             DOMAIN = 'host.example.com'
00746             ROLES = ['foo', 'bar']
00747             plugin = self._makePlugin('with_map', TITLE).__of__(self.root)
00748             adapter = self._makeOne(plugin)
00749 
00750             plugin.manage_addMapping(user_id=USER_ID,
00751                                      match_type='equals',
00752                                      match_string=DOMAIN,
00753                                      roles=ROLES,
00754                                     )
00755 
00756             adapter = self._makeOne(plugin)
00757 
00758             context = DummyImportContext(plugin, purge=False)
00759             context._files['plugins/with_map.xml'] = _EMPTY_DOMAIN_AUTH
00760 
00761             self.assertEqual(len(plugin._domain_map), 1)
00762             adapter.import_(context, 'plugins', False)
00763             self.assertEqual(len(plugin._domain_map), 1)
00764             self.assertEqual(plugin.title, None)
00765 
00766         def test_import_with_purge_wipes_existing_users(self):
00767             TITLE = 'With Map'
00768             USER_ID = 'some_user_id'
00769             DOMAIN = 'host.example.com'
00770             ROLES = ['foo', 'bar']
00771             plugin = self._makePlugin('with_map', TITLE).__of__(self.root)
00772 
00773             adapter = self._makeOne(plugin)
00774 
00775             plugin.manage_addMapping(user_id=USER_ID,
00776                                      match_type='equals',
00777                                      match_string=DOMAIN,
00778                                      roles=ROLES,
00779                                     )
00780             adapter = self._makeOne(plugin)
00781 
00782             context = DummyImportContext(plugin, purge=True)
00783             context._files['plugins/with_map.xml'] = _EMPTY_DOMAIN_AUTH
00784 
00785             self.assertEqual(len(plugin._domain_map), 1)
00786             adapter.import_(context, 'plugins', False)
00787             self.assertEqual(len(plugin._domain_map), 0)
00788             self.assertEqual(plugin.title, None)
00789 
00790     class TitleOnlyExportImportTests(_TestBase):
00791 
00792         def _getTargetClass(self):
00793             from Products.PluggableAuthService.plugins.exportimport \
00794                 import TitleOnlyExportImport
00795             return TitleOnlyExportImport
00796 
00797         def _makePlugin(self, id, *args, **kw):
00798             from OFS.SimpleItem import SimpleItem
00799 
00800             class _Plugin(SimpleItem):
00801                 title = None
00802 
00803                 def __init__(self, id, title=None):
00804                     self._setId(id)
00805                     if title is not None:
00806                         self.title = title
00807 
00808             return _Plugin(id, *args, **kw)
00809 
00810         def test_listExportableItems(self):
00811             plugin = self._makePlugin('lEI').__of__(self.root)
00812             adapter = self._makeOne(plugin)
00813 
00814             self.assertEqual(len(adapter.listExportableItems()), 0)
00815 
00816         def test__getExportInfo_no_title(self):
00817             plugin = self._makePlugin('simple', None).__of__(self.root)
00818             adapter = self._makeOne(plugin)
00819 
00820             info = adapter._getExportInfo()
00821             self.assertEqual(info['title'], None)
00822 
00823         def test__getExportInfo_with_title(self):
00824             plugin = self._makePlugin('simple', None).__of__(self.root)
00825             plugin.title = 'Plugin Title'
00826             adapter = self._makeOne(plugin)
00827 
00828             info = adapter._getExportInfo()
00829             self.assertEqual(info['title'], 'Plugin Title')
00830 
00831         def test_export_no_title(self):
00832             plugin = self._makePlugin('no_title', None).__of__(self.root)
00833             adapter = self._makeOne(plugin)
00834 
00835             context = DummyExportContext(plugin)
00836             adapter.export(context, 'plugins', False)
00837 
00838             self.assertEqual( len( context._wrote ), 1 )
00839             filename, text, content_type = context._wrote[ 0 ]
00840             self.assertEqual( filename, 'plugins/no_title.xml' )
00841             self._compareDOM( text, _TITLE_ONLY_TEMPLATE_NO_TITLE )
00842             self.assertEqual( content_type, 'text/xml' )
00843 
00844         def test_export_with_title(self):
00845             TITLE = 'Plugin Title'
00846             plugin = self._makePlugin('with_title', None).__of__(self.root)
00847             plugin.title = TITLE
00848             adapter = self._makeOne(plugin)
00849 
00850             context = DummyExportContext(plugin)
00851             adapter.export(context, 'plugins', False)
00852 
00853             self.assertEqual( len( context._wrote ), 1 )
00854             filename, text, content_type = context._wrote[ 0 ]
00855             self.assertEqual( filename, 'plugins/with_title.xml' )
00856             self._compareDOM( text, _TITLE_ONLY_TEMPLATE % TITLE )
00857             self.assertEqual( content_type, 'text/xml' )
00858 
00859         def test_import_with_title(self):
00860             TITLE = 'Plugin Title'
00861             plugin = self._makePlugin('with_title').__of__(self.root)
00862             adapter = self._makeOne(plugin)
00863 
00864             context = DummyImportContext(plugin)
00865             context._files['plugins/with_title.xml'
00866                           ] = _TITLE_ONLY_TEMPLATE % TITLE
00867             adapter.import_(context, 'plugins', False)
00868 
00869             self.assertEqual( plugin.title, TITLE )
00870 
00871         def test_import_no_title(self):
00872             TITLE = 'Plugin Title'
00873             plugin = self._makePlugin('no_title').__of__(self.root)
00874             plugin.title = TITLE
00875             adapter = self._makeOne(plugin)
00876 
00877             context = DummyImportContext(plugin)
00878             context._files['plugins/no_title.xml'
00879                           ] = _TITLE_ONLY_TEMPLATE_NO_TITLE
00880 
00881             adapter.import_(context, 'plugins', False)
00882 
00883             self.assertEqual( plugin.title, None )
00884 
00885     class DelegatePathExportImportTests(_TestBase):
00886 
00887         def _getTargetClass(self):
00888             from Products.PluggableAuthService.plugins.exportimport \
00889                 import DelegatePathExportImport
00890             return DelegatePathExportImport
00891 
00892         def _makePlugin(self, id, *args, **kw):
00893             from OFS.SimpleItem import SimpleItem
00894 
00895             class _Plugin(SimpleItem):
00896                 title = None
00897                 delegate = ''
00898 
00899                 def __init__(self, id, title=None):
00900                     self._setId(id)
00901                     if title is not None:
00902                         self.title = title
00903 
00904             return _Plugin(id, *args, **kw)
00905 
00906         def test_listExportableItems(self):
00907             plugin = self._makePlugin('lEI').__of__(self.root)
00908             adapter = self._makeOne(plugin)
00909 
00910             self.assertEqual(len(adapter.listExportableItems()), 0)
00911             plugin.delegate = 'path/to/delegate'
00912             self.assertEqual(len(adapter.listExportableItems()), 0)
00913 
00914         def test__getExportInfo_default(self):
00915             plugin = self._makePlugin('default').__of__(self.root)
00916             adapter = self._makeOne(plugin)
00917 
00918             info = adapter._getExportInfo()
00919             self.assertEqual(info['title'], None)
00920             self.assertEqual(info['delegate'], '')
00921 
00922         def test_export_default(self):
00923             plugin = self._makePlugin('default').__of__(self.root)
00924             adapter = self._makeOne(plugin)
00925 
00926             context = DummyExportContext(plugin)
00927             adapter.export(context, 'plugins', False)
00928 
00929             self.assertEqual(len(context._wrote), 1)
00930             filename, text, content_type = context._wrote[0]
00931             self.assertEqual(filename, 'plugins/default.xml' )
00932             self._compareDOM(text, _DELEGATE_PATH_TEMPLATE_NO_TITLE % "")
00933             self.assertEqual( content_type, 'text/xml' )
00934 
00935         def test__getExportInfo_explicitly_set(self):
00936             TITLE = 'Plugin Title'
00937             DELEGATE_PATH = 'path/to/delegate'
00938             plugin = self._makePlugin('explicit').__of__(self.root)
00939             plugin.title = TITLE
00940             plugin.delegate = DELEGATE_PATH
00941             adapter = self._makeOne(plugin)
00942 
00943             info = adapter._getExportInfo()
00944             self.assertEqual(info['title'], TITLE)
00945             self.assertEqual(info['delegate'], DELEGATE_PATH)
00946 
00947         def test_export_explicitly_set(self):
00948             TITLE = 'Plugin Title'
00949             DELEGATE_PATH = 'path/to/delegate'
00950             plugin = self._makePlugin('explicit').__of__(self.root)
00951             plugin.title = TITLE
00952             plugin.delegate = DELEGATE_PATH
00953             adapter = self._makeOne(plugin)
00954 
00955             context = DummyExportContext(plugin)
00956             adapter.export(context, 'plugins', False)
00957 
00958             self.assertEqual(len(context._wrote), 1)
00959             filename, text, content_type = context._wrote[0]
00960             self.assertEqual(filename, 'plugins/explicit.xml' )
00961             self._compareDOM(text,
00962                              _DELEGATE_PATH_TEMPLATE % (TITLE,
00963                                                         DELEGATE_PATH,
00964                                                        ))
00965             self.assertEqual( content_type, 'text/xml' )
00966 
00967         def test_import_with_title(self):
00968             TITLE = 'Plugin Title'
00969             DELEGATE_PATH = 'path/to/delegate'
00970             plugin = self._makePlugin('with_title').__of__(self.root)
00971             adapter = self._makeOne(plugin)
00972 
00973             context = DummyImportContext(plugin)
00974             context._files['plugins/with_title.xml'
00975                           ] = _DELEGATE_PATH_TEMPLATE % (TITLE,
00976                                                          DELEGATE_PATH,
00977                                                         )
00978             adapter.import_(context, 'plugins', False)
00979 
00980             self.assertEqual( plugin.title, TITLE )
00981             self.assertEqual( plugin.delegate, DELEGATE_PATH )
00982 
00983         def test_import_no_title(self):
00984             TITLE = 'Plugin Title'
00985             DELEGATE_PATH = 'path/to/delegate'
00986             plugin = self._makePlugin('no_title').__of__(self.root)
00987             plugin.title = TITLE
00988             plugin.delegate = DELEGATE_PATH
00989             adapter = self._makeOne(plugin)
00990 
00991             context = DummyImportContext(plugin)
00992             context._files['plugins/no_title.xml'
00993                           ] = _DELEGATE_PATH_TEMPLATE_NO_TITLE % DELEGATE_PATH
00994             adapter.import_(context, 'plugins', False)
00995 
00996             self.assertEqual( plugin.title, None )
00997             self.assertEqual( plugin.delegate, DELEGATE_PATH )
00998 
00999     class DynamicGroupsPluginExportImportTests(_TestBase):
01000 
01001         def _getTargetClass(self):
01002             from Products.PluggableAuthService.plugins.exportimport \
01003                 import DynamicGroupsPluginExportImport
01004             return DynamicGroupsPluginExportImport
01005 
01006         def _makePlugin(self, id, *args, **kw):
01007             from Products.PluggableAuthService.plugins.DynamicGroupsPlugin \
01008                 import DynamicGroupsPlugin
01009 
01010             return DynamicGroupsPlugin(id, *args, **kw)
01011 
01012         def test_listExportableItems(self):
01013             plugin = self._makePlugin('lEI').__of__(self.root)
01014             adapter = self._makeOne(plugin)
01015 
01016             self.assertEqual(len(adapter.listExportableItems()), 0)
01017             plugin.addGroup('group_id', 'python:1', 'Group Title' )
01018             self.assertEqual(len(adapter.listExportableItems()), 0)
01019 
01020         def test__getExportInfo_empty(self):
01021             plugin = self._makePlugin('empty', None).__of__(self.root)
01022             adapter = self._makeOne(plugin)
01023 
01024             info = adapter._getExportInfo()
01025             self.assertEqual(info['title'], None)
01026             self.assertEqual(len(info['groups']), 0)
01027 
01028         def test_export_empty(self):
01029             plugin = self._makePlugin('empty', None).__of__(self.root)
01030             adapter = self._makeOne(plugin)
01031 
01032             context = DummyExportContext(plugin)
01033             adapter.export(context, 'plugins', False)
01034 
01035             self.assertEqual( len( context._wrote ), 1 )
01036             filename, text, content_type = context._wrote[ 0 ]
01037             self.assertEqual( filename, 'plugins/empty.xml' )
01038             self._compareDOM( text, _EMPTY_DYNAMIC_GROUPS )
01039             self.assertEqual( content_type, 'text/xml' )
01040 
01041         def test__getExportInfo_with_groups(self):
01042 
01043             plugin = self._makePlugin('with_groups').__of__(self.root)
01044             plugin.title = 'Plugin Title'
01045 
01046             for g in _DYNAMIC_GROUP_INFO:
01047                 plugin.addGroup(g['group_id'],
01048                                 g['predicate'],
01049                                 g['title'],
01050                                 g['description'],
01051                                 g['active'],
01052                                )
01053 
01054             adapter = self._makeOne(plugin)
01055 
01056             info = adapter._getExportInfo()
01057             self.assertEqual(info['title'], 'Plugin Title')
01058             self.assertEqual(len(info['groups']), len(_DYNAMIC_GROUP_INFO))
01059 
01060             for x, y in zip(info['groups'], _DYNAMIC_GROUP_INFO):
01061                 self.assertEqual(x, y)
01062 
01063         def test_export_with_groups(self):
01064 
01065             plugin = self._makePlugin('with_groups').__of__(self.root)
01066             plugin.title = 'Plugin Title'
01067 
01068             for g in _DYNAMIC_GROUP_INFO:
01069                 plugin.addGroup(g['group_id'],
01070                                 g['predicate'],
01071                                 g['title'],
01072                                 g['description'],
01073                                 g['active'],
01074                                )
01075 
01076             adapter = self._makeOne(plugin)
01077             context = DummyExportContext(plugin)
01078             adapter.export(context, 'plugins', False)
01079 
01080             self.assertEqual( len(context._wrote), 1)
01081             filename, text, content_type = context._wrote[ 0 ]
01082             self.assertEqual(filename, 'plugins/with_groups.xml')
01083             self._compareDOM(text, _FILLED_DYNAMIC_GROUPS)
01084             self.assertEqual(content_type, 'text/xml')
01085 
01086         def test_import_empty(self):
01087             plugin = self._makePlugin('empty', None).__of__(self.root)
01088             adapter = self._makeOne(plugin)
01089 
01090             context = DummyImportContext(plugin, encoding='ascii')
01091             context._files['plugins/empty.xml'] = _FILLED_DYNAMIC_GROUPS
01092             self.assertEqual(plugin.title, None)
01093 
01094             adapter.import_(context, 'plugins', False)
01095 
01096             found = plugin.listGroupInfo()
01097             self.assertEqual(len(found), len(_DYNAMIC_GROUP_INFO))
01098             self.assertEqual(plugin.title, 'Plugin Title')
01099 
01100             for finfo, ginfo in zip(found, _DYNAMIC_GROUP_INFO):
01101                 self.assertEqual(finfo['id'], ginfo['group_id'])
01102                 self.assertEqual(finfo['predicate'], ginfo['predicate'])
01103                 self.assertEqual(finfo['title'], ginfo['title'])
01104                 self.assertEqual(finfo['description'], ginfo['description'])
01105                 self.assertEqual(finfo['active'], ginfo['active'])
01106 
01107         def test_import_without_purge_leaves_existing_users(self):
01108 
01109             plugin = self._makePlugin('with_groups').__of__(self.root)
01110             plugin.title = 'Plugin Title'
01111 
01112             for g in _DYNAMIC_GROUP_INFO:
01113                 plugin.addGroup(g['group_id'],
01114                                 g['predicate'],
01115                                 g['title'],
01116                                 g['description'],
01117                                 g['active'],
01118                                )
01119 
01120             adapter = self._makeOne(plugin)
01121 
01122             context = DummyImportContext(plugin, purge=False)
01123             context._files['plugins/with_groups.xml'] = _EMPTY_DYNAMIC_GROUPS
01124 
01125             self.assertEqual(len(plugin.listGroupIds()),
01126                              len(_DYNAMIC_GROUP_INFO))
01127             adapter.import_(context, 'plugins', False)
01128             self.assertEqual(len(plugin.listGroupIds()),
01129                              len(_DYNAMIC_GROUP_INFO))
01130             self.assertEqual(plugin.title, None)
01131 
01132         def test_import_with_purge_wipes_existing_users(self):
01133 
01134             plugin = self._makePlugin('with_groups').__of__(self.root)
01135             plugin.title = 'Plugin Title'
01136 
01137             for g in _DYNAMIC_GROUP_INFO:
01138                 plugin.addGroup(g['group_id'],
01139                                 g['predicate'],
01140                                 g['title'],
01141                                 g['description'],
01142                                 g['active'],
01143                                )
01144 
01145             adapter = self._makeOne(plugin)
01146 
01147             context = DummyImportContext(plugin, purge=True)
01148             context._files['plugins/with_groups.xml'] = _EMPTY_DYNAMIC_GROUPS
01149 
01150             self.assertEqual(len(plugin.listGroupIds()),
01151                              len(_DYNAMIC_GROUP_INFO))
01152             adapter.import_(context, 'plugins', False)
01153             self.assertEqual(len(plugin.listGroupIds()), 0)
01154             self.assertEqual(plugin.title, None)
01155 
01156     def test_suite():
01157         suite = unittest.TestSuite((
01158             unittest.makeSuite(ZODBUserManagerExportImportTests),
01159             unittest.makeSuite(ZODBGroupManagerExportImportTests),
01160             unittest.makeSuite(ZODBRoleManagerExportImportTests),
01161             unittest.makeSuite(CookieAuthHelperExportImportTests),
01162             unittest.makeSuite(DomainAuthHelperExportImportTests),
01163             unittest.makeSuite(TitleOnlyExportImportTests),
01164             unittest.makeSuite(DelegatePathExportImportTests),
01165             unittest.makeSuite(DynamicGroupsPluginExportImportTests),
01166                         ))
01167         return suite
01168 
01169 _EMPTY_ZODB_USERS = """\
01170 <?xml version="1.0" ?>
01171 <zodb-users>
01172 </zodb-users>
01173 """
01174 
01175 _ZODB_USER_INFO = ({'user_id': 'user_1',
01176                     'login_name': 'user1@example.com',
01177                     'password': 'password1',
01178                    },
01179                    {'user_id': 'user_2',
01180                     'login_name': 'user2@example.com',
01181                     'password': 'password2',
01182                    },
01183                   )
01184 
01185 _FILLED_ZODB_USERS = """\
01186 <?xml version="1.0" ?>
01187 <zodb-users title="Plugin Title">
01188 <user user_id="user_1"
01189 login_name="user1@example.com"
01190 password_hash="%s" />
01191 <user user_id="user_2"
01192 login_name="user2@example.com"
01193 password_hash="%s" />
01194 </zodb-users>
01195 """
01196 
01197 _EMPTY_ZODB_GROUPS = """\
01198 <?xml version="1.0" ?>
01199 <zodb-groups>
01200 </zodb-groups>
01201 """
01202 
01203 _ZODB_GROUP_INFO = ({'group_id': 'group_1',
01204                      'title': 'Group 1',
01205                      'description': 'First Group',
01206                      'principals': ('principal1', 'principal2'),
01207                     },
01208                     {'group_id': 'group_2',
01209                      'title': 'Group 2',
01210                      'description': 'Second Group',
01211                      'principals': ('principal1', 'principal3'),
01212                     },
01213                    )
01214 
01215 _FILLED_ZODB_GROUPS = """\
01216 <?xml version="1.0" ?>
01217 <zodb-groups title="Plugin Title">
01218 <group group_id="group_1" title="Group 1" description="First Group">
01219 <principal principal_id="principal1" />
01220 <principal principal_id="principal2" />
01221 </group>
01222 <group group_id="group_2" title="Group 2" description="Second Group">
01223 <principal principal_id="principal1" />
01224 <principal principal_id="principal3" />
01225 </group>
01226 </zodb-groups>
01227 """
01228 
01229 _EMPTY_ZODB_ROLES = """\
01230 <?xml version="1.0" ?>
01231 <zodb-roles>
01232 </zodb-roles>
01233 """
01234 
01235 _ZODB_ROLE_INFO = ({'role_id': 'role_1',
01236                     'title': 'Role 1',
01237                     'description': 'First Role',
01238                     'principals': ('principal1', 'principal2'),
01239                    },
01240                    {'role_id': 'role_2',
01241                     'title': 'Role 2',
01242                     'description': 'Second Role',
01243                     'principals': ('principal1', 'principal3'),
01244                    },
01245                   )
01246 
01247 _FILLED_ZODB_ROLES = """\
01248 <?xml version="1.0" ?>
01249 <zodb-roles title="Plugin Title">
01250 <role role_id="role_1" title="Role 1" description="First Role">
01251 <principal principal_id="principal1" />
01252 <principal principal_id="principal2" />
01253 </role>
01254 <role role_id="role_2" title="Role 2" description="Second Role">
01255 <principal principal_id="principal1" />
01256 <principal principal_id="principal3" />
01257 </role>
01258 </zodb-roles>
01259 """
01260 
01261 _COOKIE_AUTH_TEMPLATE_NO_TITLE = """\
01262 <?xml version="1.0" ?>
01263 <cookie-auth cookie_name="%s" login_path="%s" />
01264 """
01265 
01266 _COOKIE_AUTH_TEMPLATE = """\
01267 <?xml version="1.0" ?>
01268 <cookie-auth title="%s" cookie_name="%s" login_path="%s" />
01269 """
01270 
01271 _EMPTY_DOMAIN_AUTH = """\
01272 <?xml version="1.0" ?>
01273 <domain-auth>
01274 </domain-auth>
01275 """
01276 
01277 _FILLED_DOMAIN_AUTH = """\
01278 <?xml version="1.0" ?>
01279 <domain-auth title="%s">
01280  <user user_id="%s">
01281   <match match_string="%s" match_type="%s" roles="%s" username="%s"/>
01282  </user>
01283 </domain-auth>
01284 """
01285 
01286 _TITLE_ONLY_TEMPLATE_NO_TITLE = """\
01287 <?xml version="1.0" ?>
01288 <plug-in />
01289 """
01290 
01291 _TITLE_ONLY_TEMPLATE = """\
01292 <?xml version="1.0" ?>
01293 <plug-in title="%s" />
01294 """
01295 
01296 _DELEGATE_PATH_TEMPLATE_NO_TITLE = """\
01297 <?xml version="1.0" ?>
01298 <delegating-plugin delegate="%s" />
01299 """
01300 
01301 _DELEGATE_PATH_TEMPLATE = """\
01302 <?xml version="1.0" ?>
01303 <delegating-plugin title="%s" delegate="%s" />
01304 """
01305 
01306 _DYNAMIC_GROUP_INFO = ({'group_id': 'group_1',
01307                         'title': 'Group 1',
01308                         'predicate': 'python:1',
01309                         'description': 'First Group',
01310                         'active': True,
01311                        },
01312                        {'group_id': 'group_2',
01313                         'title': 'Group 2',
01314                         'predicate': 'python:0',
01315                         'description': 'Second Group',
01316                         'active': False,
01317                        },
01318                       )
01319 
01320 _EMPTY_DYNAMIC_GROUPS = """\
01321 <?xml version="1.0" ?>
01322 <dynamic-groups>
01323 </dynamic-groups>
01324 """
01325 
01326 _FILLED_DYNAMIC_GROUPS = """\
01327 <?xml version="1.0" ?>
01328 <dynamic-groups title="Plugin Title">
01329 <group
01330     group_id="group_1"
01331     predicate="python:1"
01332     title="Group 1"
01333     description="First Group"
01334     active="True"
01335     />
01336 <group
01337     group_id="group_2"
01338     predicate="python:0"
01339     title="Group 2"
01340     description="Second Group"
01341     active="False"
01342     />
01343 </dynamic-groups>
01344 """
01345 
01346 if __name__ == '__main__':
01347     unittest.main(defaultTest='test_suite')