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

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


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

Changed:
  U   CMF/branches/1.5/CHANGES.txt
  U   CMF/branches/1.5/CMFCore/MemberDataTool.py
  U   CMF/branches/1.5/CMFCore/tests/test_MemberDataTool.py

-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt	2005-09-19 00:55:53 UTC (rev 38512)
+++ CMF/branches/1.5/CHANGES.txt	2005-09-19 12:01:33 UTC (rev 38513)
@@ -2,6 +2,9 @@
 
   Bug Fixes
 
+    - CMFCore.MemberDataTool: Fixed the pruneMemberData functionality in the
+      ZMI: Now it is enough to press the button once.
+
     - Collector #381:  CMFCore unit tests depended on CMFDefault / workflow.
 
     - CalendarTool: If an event ends at exactly midnight, don't show it

Modified: CMF/branches/1.5/CMFCore/MemberDataTool.py
===================================================================
--- CMF/branches/1.5/CMFCore/MemberDataTool.py	2005-09-19 00:55:53 UTC (rev 38512)
+++ CMF/branches/1.5/CMFCore/MemberDataTool.py	2005-09-19 12:01:33 UTC (rev 38513)
@@ -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/branches/1.5/CMFCore/tests/test_MemberDataTool.py
===================================================================
--- CMF/branches/1.5/CMFCore/tests/test_MemberDataTool.py	2005-09-19 00:55:53 UTC (rev 38512)
+++ CMF/branches/1.5/CMFCore/tests/test_MemberDataTool.py	2005-09-19 12:01:33 UTC (rev 38513)
@@ -25,7 +25,6 @@
 
 import Acquisition
 
-
 class DummyUserFolder(Acquisition.Implicit):
 
     def __init__(self):
@@ -42,7 +41,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):
@@ -104,7 +106,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