def test_deleteMembersUnsupported(self): # Quite a few user folders do not support the deletion API # http://www.zope.org/Collectors/CMF/481 # Make sure we get the right exception site = self._makeSite() sm = getSiteManager() sm.registerUtility(site, ISiteRoot) mtool = site.portal_membership members = site._setObject('Members', PortalFolder('Members')) acl_users = site._setObject('acl_users', DummyUserFolder()) mdtool = MemberDataTool() sm.registerUtility(mdtool, IMemberDataTool) newSecurityManager(None, acl_users.all_powerful_Oz) self.assertEqual(acl_users.getUserById('user_foo'), acl_users.user_foo) mtool.createMemberArea('user_foo') self.assertTrue(hasattr(members.aq_self, 'user_foo')) mdtool.registerMemberData('Dummy', 'user_foo') self.assertTrue('user_foo' in mdtool._members) # Fake an incompatible user folder by deleting the class method deletion_method = DummyUserFolder.userFolderDelUsers del DummyUserFolder.userFolderDelUsers self.assertRaises(NotImplementedError, mtool.deleteMembers, ('user_foo', )) self.assertTrue(acl_users.getUserById('user_foo', None)) self.assertTrue('user_foo' in mdtool._members) self.assertTrue(hasattr(members.aq_self, 'user_foo')) # Cleanup DummyUserFolder.userFolderDelUsers = deletion_method
def test_deleteMembersUnsupported(self): # Quite a few user folders do not support the deletion API # http://www.zope.org/Collectors/CMF/481 # Make sure we get the right exception site = self._makeSite() sm = getSiteManager() sm.registerUtility(site, ISiteRoot) mtool = site.portal_membership members = site._setObject('Members', PortalFolder('Members')) acl_users = site._setObject('acl_users', DummyUserFolder()) mdtool = MemberDataTool() sm.registerUtility(mdtool, IMemberDataTool) newSecurityManager(None, acl_users.all_powerful_Oz) self.assertEqual(acl_users.getUserById('user_foo'), acl_users.user_foo) mtool.createMemberArea('user_foo') self.assertTrue(hasattr(members.aq_self, 'user_foo')) mdtool.registerMemberData('Dummy', 'user_foo') self.assertTrue('user_foo' in mdtool._members) # Fake an incompatible user folder by deleting the class method deletion_method = DummyUserFolder.userFolderDelUsers del DummyUserFolder.userFolderDelUsers self.assertRaises(NotImplementedError, mtool.deleteMembers, ('user_foo',)) self.assertTrue(acl_users.getUserById('user_foo', None)) self.assertTrue('user_foo' in mdtool._members) self.assertTrue(hasattr(members.aq_self, 'user_foo')) # Cleanup DummyUserFolder.userFolderDelUsers = deletion_method cleanUp()
def test_deleteMemberData(self): tool = MemberDataTool() tool.registerMemberData('Dummy', 'user_foo') self.failUnless( tool._members.has_key('user_foo') ) self.failUnless( tool.deleteMemberData('user_foo') ) self.failIf( tool._members.has_key('user_foo') ) self.failIf( tool.deleteMemberData('user_foo') )
def pruneMemberDataContents(self): ''' Compare the user IDs stored in the member data tool with the list in the actual underlying acl_users and delete anything not in acl_users ''' BaseTool.pruneMemberDataContents(self) membertool = getToolByName(self, 'portal_membership') portraits = self.portraits user_list = membertool.listMemberIds() for tuple in portraits.items(): member_id = tuple[0] if member_id not in user_list: self.portraits._delObject(member_id)
def test_pruneMemberData(self): # This needs a tad more setup from OFS.Folder import Folder from Products.CMFCore.MembershipTool import MembershipTool folder = Folder('test') folder._setObject('portal_memberdata', MemberDataTool()) folder._setObject('portal_membership', MembershipTool()) folder._setObject('acl_users', DummyUserFolder()) tool = folder.portal_memberdata # Create some members for i in range(20): tool.registerMemberData( 'Dummy_%i' % i , 'user_foo_%i' % i ) # None of these fake members are in the user folder, which means # there are 20 members and 20 "orphans" contents = tool.getMemberDataContents() info_dict = contents[0] self.assertEqual(info_dict['member_count'], 20) self.assertEqual(info_dict['orphan_count'], 20) # Calling the prune method should delete all orphans, so we end # up with no members in the tool. tool.pruneMemberDataContents() contents = tool.getMemberDataContents() info_dict = contents[0] self.assertEqual(info_dict['member_count'], 0) self.assertEqual(info_dict['orphan_count'], 0)
def test_deleteMembers(self): site = self._makeSite() sm = getSiteManager() mtool = site.portal_membership members = site._setObject('Members', PortalFolder('Members')) acl_users = site._setObject('acl_users', DummyUserFolder()) utool = site._setObject('portal_url', DummyTool()) sm.registerUtility(utool, IURLTool) wtool = site._setObject('portal_workflow', DummyTool()) mdtool = site._setObject('portal_memberdata', MemberDataTool()) sm.registerUtility(mdtool, IMemberDataTool) newSecurityManager(None, acl_users.all_powerful_Oz) self.assertEqual(acl_users.getUserById('user_foo'), acl_users.user_foo) mtool.createMemberArea('user_foo') self.failUnless(hasattr(members.aq_self, 'user_foo')) mdtool.registerMemberData('Dummy', 'user_foo') self.failUnless(mdtool._members.has_key('user_foo')) rval = mtool.deleteMembers(('user_foo', 'user_baz')) self.assertEqual(rval, ('user_foo', )) self.failIf(acl_users.getUserById('user_foo', None)) self.failIf(mdtool._members.has_key('user_foo')) self.failIf(hasattr(members.aq_self, 'user_foo')) cleanUp()
def setUp(self): from OFS.Folder import Folder from Products.CMFCore.MemberDataTool import MemberDataTool from Products.CMFCore.MembershipTool import MembershipTool self.site = Folder('test') self.site._setObject('portal_memberdata', MemberDataTool()) sm = getSiteManager() sm.registerUtility(MembershipTool(), IMembershipTool) self.site._setObject('acl_users', DummyUserFolder())
def test_deleteMemberData(self): tool = MemberDataTool() tool.registerMemberData('Dummy', 'user_foo') self.failUnless(tool._members.has_key('user_foo')) self.failUnless(tool.deleteMemberData('user_foo')) self.failIf(tool._members.has_key('user_foo')) self.failIf(tool.deleteMemberData('user_foo'))
def test_deleteMembers(self): site = self._makeSite() sm = getSiteManager() sm.registerUtility(site, ISiteRoot) mtool = site.portal_membership members = site._setObject('Members', PortalFolder('Members')) acl_users = site._setObject('acl_users', DummyUserFolder()) mdtool = MemberDataTool() sm.registerUtility(mdtool, IMemberDataTool) newSecurityManager(None, acl_users.all_powerful_Oz) self.assertEqual(acl_users.getUserById('user_foo'), acl_users.user_foo) mtool.createMemberArea('user_foo') self.assertTrue(hasattr(members.aq_self, 'user_foo')) mdtool.registerMemberData('Dummy', 'user_foo') self.assertTrue('user_foo' in mdtool._members) rval = mtool.deleteMembers(('user_foo', 'user_baz')) self.assertEqual(rval, ('user_foo', )) self.assertFalse(acl_users.getUserById('user_foo', None)) self.assertFalse('user_foo' in mdtool._members) self.assertFalse(hasattr(members.aq_self, 'user_foo'))
def test_deleteMembers(self): site = self._makeSite() sm = getSiteManager() sm.registerUtility(site, ISiteRoot) mtool = site.portal_membership members = site._setObject('Members', PortalFolder('Members')) acl_users = site._setObject('acl_users', DummyUserFolder()) mdtool = MemberDataTool() sm.registerUtility(mdtool, IMemberDataTool) newSecurityManager(None, acl_users.all_powerful_Oz) self.assertEqual(acl_users.getUserById('user_foo'), acl_users.user_foo) mtool.createMemberArea('user_foo') self.assertTrue(hasattr(members.aq_self, 'user_foo')) mdtool.registerMemberData('Dummy', 'user_foo') self.assertTrue('user_foo' in mdtool._members) rval = mtool.deleteMembers(('user_foo', 'user_baz')) self.assertEqual(rval, ('user_foo',)) self.assertFalse(acl_users.getUserById('user_foo', None)) self.assertFalse('user_foo' in mdtool._members) self.assertFalse(hasattr(members.aq_self, 'user_foo')) cleanUp()
def _makeOne(self, *args, **kw): from Products.CMFCore.MemberDataTool import MemberDataTool return MemberDataTool(*args, **kw)
def setUp(self): self._obj = MemberDataTool() self._BODY = _MEMBERDATATOOL_BODY
def __init__(self): BaseTool.__init__(self) self.portraits = BTreeFolder2(id='portraits')
def __init__(self, id='portal_memberdata'): self.id = id MemberDataTool.__init__(self) self._sorted_attributes = ()
def _initSite(self, use_changed=False): site = Folder(id='site').__of__(self.app) mdtool = MemberDataTool() getSiteManager().registerUtility(mdtool, IMemberDataTool) if use_changed: mdtool._updateProperty('email', 'value1') mdtool._updateProperty('portal_skin', 'value2') mdtool._updateProperty('listed', 'True') mdtool._updateProperty('login_time', '2010/01/01') mdtool._updateProperty('last_login_time', '2010/01/01') mdtool._updateProperty('fullname', 'value3') mdtool.manage_addProperty('home_page', '', 'string') return site, mdtool