[CMF-checkins] SVN: CMF/trunk/CMFCore/ - CMFCore.MemberDataTool: Fixed the pruneMemberData functionality in the

Jens Vagelpohl jens at dataflake.org
Mon Sep 19 08:01:56 EDT 2005


Log message for revision 38514:
  - CMFCore.MemberDataTool: Fixed the pruneMemberData functionality in the 
    ZMI: Now it is enough to press the button once.
  

Changed:
  U   CMF/trunk/CMFCore/MemberDataTool.py
  U   CMF/trunk/CMFCore/tests/test_MemberDataTool.py

-=-
Modified: CMF/trunk/CMFCore/MemberDataTool.py
===================================================================
--- CMF/trunk/CMFCore/MemberDataTool.py	2005-09-19 12:01:33 UTC (rev 38513)
+++ CMF/trunk/CMFCore/MemberDataTool.py	2005-09-19 12:01:56 UTC (rev 38514)
@@ -175,14 +175,12 @@
         """ Delete data contents of all members not listet in acl_users.
         """
         membertool= getToolByName(self, 'portal_membership')
-        members   = self._members
+        members = self._members
         user_list = membertool.listMemberIds()
 
-        for tuple in members.items():
-            member_name = tuple[0]
-            member_obj  = tuple[1]
-            if member_name not in user_list:
-                del members[member_name]
+        for member_id in list(members.keys()):
+            if member_id not in user_list:
+                del members[member_id]
 
     security.declarePrivate('wrapUser')
     def wrapUser(self, u):

Modified: CMF/trunk/CMFCore/tests/test_MemberDataTool.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_MemberDataTool.py	2005-09-19 12:01:33 UTC (rev 38513)
+++ CMF/trunk/CMFCore/tests/test_MemberDataTool.py	2005-09-19 12:01:56 UTC (rev 38514)
@@ -22,7 +22,6 @@
 
 import Acquisition
 
-
 class DummyUserFolder(Acquisition.Implicit):
 
     def __init__(self):
@@ -39,7 +38,10 @@
         user.roles = tuple(roles)
         user.domains = tuple(domains)
 
+    def getUsers(self):
+        return self._users.values()
 
+
 class DummyUser(Acquisition.Implicit):
 
     def __init__(self, name, password, roles, domains):
@@ -97,7 +99,38 @@
         self.failIf( tool._members.has_key('user_foo') )
         self.failIf( tool.deleteMemberData('user_foo') )
 
+    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', self._makeOne())
+        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)
+
+
 class MemberDataTests(TestCase):
 
     def _makeOne(self, *args, **kw):



More information about the CMF-checkins mailing list