[CalendarServer-changes] [2367] CalendarServer/branches/propfind-cache/twistedcaldav/directory

source_changes at macosforge.org source_changes at macosforge.org
Mon May 5 13:03:40 PDT 2008


Revision: 2367
          http://trac.macosforge.org/projects/calendarserver/changeset/2367
Author:   dreid at apple.com
Date:     2008-05-05 13:03:39 -0700 (Mon, 05 May 2008)

Log Message:
-----------
delete-trailing-whitespace and add a test for setGroupMemberSet

Modified Paths:
--------------
    CalendarServer/branches/propfind-cache/twistedcaldav/directory/calendaruserproxy.py
    CalendarServer/branches/propfind-cache/twistedcaldav/directory/test/test_proxyprincipalmembers.py

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/directory/calendaruserproxy.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/directory/calendaruserproxy.py	2008-05-05 17:35:32 UTC (rev 2366)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/directory/calendaruserproxy.py	2008-05-05 20:03:39 UTC (rev 2367)
@@ -54,7 +54,7 @@
                 davxml.Protected(),
             ),
         )
-        
+
         # Add admins
         aces += tuple([davxml.ACE(
                     davxml.Principal(davxml.HRef(principal)),
@@ -118,10 +118,10 @@
     def _index(self):
         """
         Return the SQL database for this group principal.
-        
+
         @return: the L{CalendarUserProxyDatabase} for the principal collection.
         """
-        
+
         # The db is located in the principal collection root
         if not hasattr(self.pcollection, "calendar_user_proxy_db"):
             setattr(self.pcollection, "calendar_user_proxy_db", CalendarUserProxyDatabase(self.pcollection.fp.path))
@@ -166,7 +166,7 @@
 
         # Break out the list into a set of URIs.
         members = [str(h) for h in new_members.children]
-        
+
         # Map the URIs to principals.
         principals = []
         for uri in members:
@@ -178,7 +178,7 @@
                     "Attempt to use a non-existent principal %s as a group member of %s." % (uri, self.principalURL(),)
                 ))
             principals.append(principal)
-        
+
         # Map the principals to UIDs.
         uids = [p.principalUID() for p in principals]
 
@@ -298,19 +298,19 @@
 
     def hasEditableMembership(self):
         return self.parent.hasEditableProxyMembership()
-        
+
 class CalendarUserProxyDatabase(AbstractSQLDatabase):
     """
     A database to maintain calendar user proxy group memberships.
 
     SCHEMA:
-    
+
     Group Database:
-    
+
     ROW: GROUPNAME, MEMBER
-    
+
     """
-    
+
     dbType = "CALENDARUSERPROXY"
     dbFilename = db_prefix + "calendaruserproxy"
     dbFormatVersion = "4"
@@ -322,11 +322,11 @@
     def setGroupMembers(self, principalUID, members):
         """
         Add a group membership record.
-    
+
         @param principalUID: the UID of the group principal to add.
         @param members: a list UIDs of principals that are members of this group.
         """
-        
+
         # Remove what is there, then add it back.
         self._delete_from_db(principalUID)
         self._add_to_db(principalUID, members)
@@ -335,12 +335,12 @@
     def removeGroup(self, principalUID):
         """
         Remove a group membership record.
-    
+
         @param principalUID: the UID of the group principal to remove.
         """
         self._delete_from_db(principalUID)
         self._db_commit()
-    
+
     def getMembers(self, principalUID):
         """
         Return the list of group member UIDs for the specified principal.
@@ -349,7 +349,7 @@
         for row in self._db_execute("select MEMBER from GROUPS where GROUPNAME = :1", principalUID):
             members.add(row[0])
         return members
-    
+
     def getMemberships(self, principalUID):
         """
         Return the list of group principal UIDs the specified principal is a member of.
@@ -373,7 +373,7 @@
                 values (:1, :2)
                 """, principalUID, member
             )
-       
+
     def _delete_from_db(self, principalUID):
         """
         Deletes the specified entry from the database.
@@ -381,19 +381,19 @@
         @param principalUID: the UID of the group principal to remove.
         """
         self._db_execute("delete from GROUPS where GROUPNAME = :1", principalUID)
-    
+
     def _db_version(self):
         """
         @return: the schema version assigned to this index.
         """
         return CalendarUserProxyDatabase.dbFormatVersion
-        
+
     def _db_type(self):
         """
         @return: the collection type assigned to this index.
         """
         return CalendarUserProxyDatabase.dbType
-        
+
     def _db_init_data_tables(self, q):
         """
         Initialise the underlying database tables.

Modified: CalendarServer/branches/propfind-cache/twistedcaldav/directory/test/test_proxyprincipalmembers.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/directory/test/test_proxyprincipalmembers.py	2008-05-05 17:35:32 UTC (rev 2366)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/directory/test/test_proxyprincipalmembers.py	2008-05-05 20:03:39 UTC (rev 2367)
@@ -17,6 +17,7 @@
 import os
 
 from twisted.web2.dav.fileop import rmdir
+from twisted.web2.dav import davxml
 
 from twistedcaldav.directory.directory import DirectoryService
 from twistedcaldav.directory.xmlfile import XMLDirectoryService
@@ -33,7 +34,7 @@
     """
     def setUp(self):
         super(ProxyPrincipals, self).setUp()
-        
+
         # Set up a principals hierarchy for each service we're testing with
         self.principalRootResources = {}
         name = directoryService.__class__.__name__
@@ -114,7 +115,7 @@
         """
         DirectoryPrincipalResource.groupMembers()
         """
-        
+
         # Setup the fake entry in the DB
         proxy = self._getRecordByShortName(DirectoryService.recordType_users, "cdaboo")
         proxy_group = proxy.getChild("calendar-proxy-write")
@@ -131,7 +132,7 @@
         """
         DirectoryPrincipalResource.groupMembers()
         """
-        
+
         # Setup the fake entry in the DB
         fake_uid = "12345"
         proxy = self._getRecordByShortName(DirectoryService.recordType_users, "cdaboo")
@@ -157,3 +158,35 @@
         """
         provisioningResource = self.principalRootResources[directoryService.__class__.__name__]
         return provisioningResource.principalForShortName(type, name)
+
+
+    def test_setGroupMemberSet(self):
+        class StubMemberDB(object):
+            def __init__(self):
+                self.members = None
+
+            def setGroupMembers(self, uid, members):
+                self.members = members
+
+
+        proxy = self._getRecordByShortName(directoryService.recordType_users,
+                                           "cdaboo")
+
+        proxy_group = proxy.getChild("calendar-proxy-write")
+
+        memberdb = StubMemberDB()
+
+        proxy_group._index = (lambda: memberdb)
+
+        new_members = davxml.GroupMemberSet(
+            davxml.HRef.fromString(
+                "/XMLDirectoryService/__uids__/8B4288F6-CC82-491D-8EF9-642EF4F3E7D0/"),
+            davxml.HRef.fromString(
+                "/XMLDirectoryService/__uids__/5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1/"))
+
+        proxy_group.setGroupMemberSet(new_members, None)
+
+        self.assertEquals(
+            set([str(p) for p in memberdb.members]),
+            set(["5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1",
+                 "8B4288F6-CC82-491D-8EF9-642EF4F3E7D0"]))

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080505/af3d0986/attachment-0001.html


More information about the calendarserver-changes mailing list