[CalendarServer-changes] [12986] CalendarServer/branches/users/sagen/move2who-4

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 21 11:47:20 PDT 2014


Revision: 12986
          http://trac.calendarserver.org//changeset/12986
Author:   sagen at apple.com
Date:     2014-03-21 11:47:20 -0700 (Fri, 21 Mar 2014)
Log Message:
-----------
The test for calendarserver_manage_principals works now

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/caldavd.plist
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/resources-locations.xml
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/users-groups.xml
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_principals.py
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py	2014-03-21 02:05:52 UTC (rev 12985)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py	2014-03-21 18:47:20 UTC (rev 12986)
@@ -32,7 +32,9 @@
 from twisted.internet import reactor
 from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 from twistedcaldav.config import config
-from txdav.who.delegates import addDelegate, removeDelegate
+from txdav.who.delegates import (
+    addDelegate, removeDelegate, RecordType as DelegateRecordType
+)
 from txdav.who.idirectory import AutoScheduleMode
 
 
@@ -84,7 +86,7 @@
     print("  --get-auto-schedule-mode: read auto-schedule mode")
     print("  --set-auto-accept-group=principal: set auto-accept-group")
     print("  --get-auto-accept-group: read auto-accept-group")
-    print("  --add {locations|resources|addresses} 'full name' [record name] [GUID]: add a principal")
+    print("  --add {locations|resources|addresses} full-name record-name UID: add a principal")
     print("  --remove: remove a principal")
     print("  --set-geo=url: set the geo: url for an address (e.g. geo:37.331741,-122.030333)")
     print("  --get-geo: get the geo: url for an address")
@@ -358,7 +360,7 @@
 def runListPrincipalTypes(service, store):
     directory = store.directoryService()
     for recordType in directory.recordTypes():
-        print(directory.recordTypeToOldString(recordType))
+        print(directory.recordTypeToOldName(recordType))
     return succeed(None)
 
 
@@ -446,6 +448,20 @@
 def runAddPrincipal(service, store, addType, uid, shortNames, fullNames):
     directory = store.directoryService()
     recordType = directory.oldNameToRecordType(addType)
+
+    # See if that UID is in use
+    record = yield directory.recordWithUID(uid)
+    if record is not None:
+        print("UID already in use: {uid}".format(uid=uid))
+        returnValue(None)
+
+    # See if the shortnames are in use
+    for shortName in shortNames:
+        record = yield directory.recordWithShortName(recordType, shortName)
+        if record is not None:
+            print("Record name already in use: {name}".format(name=shortName))
+            returnValue(None)
+
     fields = {
         directory.fieldName.recordType: recordType,
         directory.fieldName.uid: uid,
@@ -454,6 +470,7 @@
     }
     record = DirectoryRecord(directory, fields)
     yield record.service.updateRecords([record], create=True)
+    print("Added '{name}'".format(name=fullNames[0]))
 
 
 
@@ -531,7 +548,7 @@
 
 
 @inlineCallbacks
-def _addRemoveProxy(fn, store, record, proxyType, *proxyIDs):
+def _addRemoveProxy(msg, fn, store, record, proxyType, *proxyIDs):
     directory = store.directoryService()
     readWrite = (proxyType == "write")
     for proxyID in proxyIDs:
@@ -542,80 +559,83 @@
             txn = store.newTransaction()
             yield fn(txn, record, proxyRecord, readWrite)
             yield txn.commit()
+            print(
+                "{msg} {proxy} as a {proxyType} proxy for {record}".format(
+                    msg=msg, proxy=prettyRecord(proxyRecord),
+                    proxyType=proxyType, record=prettyRecord(record)
+                )
+            )
 
 
+ at inlineCallbacks
 def action_addProxy(store, record, proxyType, *proxyIDs):
-    return _addRemoveProxy(addDelegate, store, record, proxyType, *proxyIDs)
+    yield _addRemoveProxy("Added", addDelegate, store, record, proxyType, *proxyIDs)
 
 
 @inlineCallbacks
 def action_removeProxy(store, record, *proxyIDs):
     # Write
-    yield _addRemoveProxy(removeDelegate, store, record, "write", *proxyIDs)
+    yield _addRemoveProxy("Removed", removeDelegate, store, record, "write", *proxyIDs)
     # Read
-    yield _addRemoveProxy(removeDelegate, store, record, "read", *proxyIDs)
+    yield _addRemoveProxy("Removed", removeDelegate, store, record, "read", *proxyIDs)
 
 
 
-# @inlineCallbacks
-# def setProxies(store, principal, readProxyPrincipals, writeProxyPrincipals, directory=None):
-#     """
-#     Set read/write proxies en masse for a principal
-#     @param principal: DirectoryPrincipalResource
-#     @param readProxyPrincipals: a list of principal IDs (see principalForPrincipalID)
-#     @param writeProxyPrincipals: a list of principal IDs (see principalForPrincipalID)
-#     """
+ at inlineCallbacks
+def setProxies(record, readProxyRecords, writeProxyRecords):
+    """
+    Set read/write proxies en masse for a record
+    @param record: L{IDirectoryRecord}
+    @param readProxyRecords: a list of records
+    @param writeProxyRecords: a list of records
+    """
 
-#     proxyTypes = [
-#         ("read", readProxyPrincipals),
-#         ("write", writeProxyPrincipals),
-#     ]
-#     for proxyType, proxyIDs in proxyTypes:
-#         if proxyIDs is None:
-#             continue
-#         subPrincipal = proxySubprincipal(principal, proxyType)
-#         if subPrincipal is None:
-#             raise ProxyError("Unable to edit %s proxies for %s\n" % (proxyType,
-#                 prettyPrincipal(principal)))
-#         memberURLs = []
-#         for proxyID in proxyIDs:
-#             proxyPrincipal = yield principalForPrincipalID(proxyID, directory=directory)
-#             proxyURL = proxyPrincipal.url()
-#             memberURLs.append(davxml.HRef(proxyURL))
-#         membersProperty = davxml.GroupMemberSet(*memberURLs)
-#         yield subPrincipal.writeProperty(membersProperty, None)
-#         if store is not None:
-#             # Schedule work the PeerConnectionPool will pick up as overdue
-#             yield schedulePolledGroupCachingUpdate(store)
+    proxyTypes = [
+        (DelegateRecordType.readDelegateGroup, readProxyRecords),
+        (DelegateRecordType.writeDelegateGroup, writeProxyRecords),
+    ]
+    for recordType, proxyRecords in proxyTypes:
+        if proxyRecords is None:
+            continue
+        proxyGroup = yield record.service.recordWithShortName(
+            recordType, record.uid
+        )
+        yield proxyGroup.setMembers(proxyRecords)
 
+    # if store is not None:
+    #     # Schedule work the PeerConnectionPool will pick up as overdue
+    #     yield schedulePolledGroupCachingUpdate(store)
 
 
-# @inlineCallbacks
-# def getProxies(principal, directory=None):
-#     """
-#     Returns a tuple containing the GUIDs for read proxies and write proxies
-#     of the given principal
-#     """
 
-#     proxies = {
-#         "read": [],
-#         "write": [],
-#     }
-#     for proxyType in proxies.iterkeys():
-#         subPrincipal = proxySubprincipal(principal, proxyType)
-#         if subPrincipal is not None:
-#             membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
-#             if membersProperty.children:
-#                 for member in membersProperty.children:
-#                     proxyPrincipal = yield principalForPrincipalID(str(member), directory=directory)
-#                     proxies[proxyType].append(proxyPrincipal.record.guid)
+ at inlineCallbacks
+def getProxies(record):
+    """
+    Returns a tuple containing the records for read proxies and write proxies
+    of the given record
+    """
 
-#     returnValue((proxies['read'], proxies['write']))
+    allProxies = {
+        DelegateRecordType.readDelegateGroup: [],
+        DelegateRecordType.writeDelegateGroup: [],
+    }
+    for recordType in allProxies.iterkeys():
+        proxyGroup = yield record.service.recordWithShortName(
+            recordType, record.uid
+        )
+        allProxies[recordType] = yield proxyGroup.members()
 
+    returnValue(
+        (
+            allProxies[DelegateRecordType.readDelegateGroup],
+            allProxies[DelegateRecordType.writeDelegateGroup]
+        )
+    )
 
 
 
 
+
 def action_getAutoScheduleMode(store, record):
     print(
         "Auto-schedule mode for {record} is {mode}".format(
@@ -782,6 +802,13 @@
     this fancier later.
     """
 
+    if len(args) != 3:
+        print(
+            "When adding a principal, you must provide full-name, record-name, "
+            "and UID"
+        )
+        sys.exit(64)
+
     fullName = args[0].decode("utf-8")
     shortName = args[1].decode("utf-8")
     uid = args[2].decode("utf-8")

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/caldavd.plist
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/caldavd.plist	2014-03-21 02:05:52 UTC (rev 12985)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/caldavd.plist	2014-03-21 18:47:20 UTC (rev 12986)
@@ -139,7 +139,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.xmlfile.XMLDirectoryService</string>
-      
+
       <key>params</key>
       <dict>
         <key>xmlFile</key>
@@ -159,7 +159,7 @@
       <true/>
       <key>type</key>
       <string>twistedcaldav.directory.xmlfile.XMLDirectoryService</string>
-      
+
       <key>params</key>
       <dict>
         <key>xmlFile</key>
@@ -168,17 +168,18 @@
         <array>
             <string>resources</string>
             <string>locations</string>
+            <string>addresses</string>
         </array>
       </dict>
     </dict>
-    
+
     <!-- Open Directory Service (Mac OS X) -->
     <!--
     <key>DirectoryService</key>
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.appleopendirectory.OpenDirectoryService</string>
-      
+
       <key>params</key>
       <dict>
         <key>node</key>
@@ -202,7 +203,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.augment.AugmentXMLDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>xmlFiles</key>
@@ -211,14 +212,14 @@
         </array>
       </dict>
     </dict>
-    
+
     <!-- Sqlite Augment Service -->
     <!--
     <key>AugmentService</key>
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.augment.AugmentSqliteDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>dbpath</key>
@@ -233,7 +234,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.augment.AugmentPostgreSQLDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>host</key>
@@ -249,7 +250,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.calendaruserproxy.ProxySqliteDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>dbpath</key>
@@ -263,7 +264,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.calendaruserproxy.ProxyPostgreSQLDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>host</key>
@@ -692,7 +693,7 @@
     <!-- Support for Content-Encoding compression options as specified in RFC2616 Section 3.5 -->
     <key>ResponseCompression</key>
     <false/>
-    
+
     <!-- The retry-after value (in seconds) to return with a 503 error. -->
     <key>HTTPRetryAfter</key>
     <integer>180</integer>

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/resources-locations.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/resources-locations.xml	2014-03-21 02:05:52 UTC (rev 12985)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/resources-locations.xml	2014-03-21 18:47:20 UTC (rev 12986)
@@ -18,7 +18,110 @@
 
 <!DOCTYPE accounts SYSTEM "accounts.dtd">
 
-<accounts realm="Test Realm">
+<directory realm="Test Realm">
+  <record type="location">
+    <short-name>location01</short-name>
+    <uid>location01</uid>
+    <full-name>Room 01</full-name>
+  </record>
+  <record type="location">
+    <short-name>location02</short-name>
+    <uid>location02</uid>
+    <full-name>Room 02</full-name>
+  </record>
+  <record type="location">
+    <short-name>location03</short-name>
+    <uid>location03</uid>
+    <full-name>Room 03</full-name>
+  </record>
+  <record type="location">
+    <short-name>location04</short-name>
+    <uid>location04</uid>
+    <full-name>Room 04</full-name>
+  </record>
+  <record type="location">
+    <short-name>location05</short-name>
+    <uid>location05</uid>
+    <full-name>Room 05</full-name>
+  </record>
+  <record type="location">
+    <short-name>location06</short-name>
+    <uid>location06</uid>
+    <full-name>Room 06</full-name>
+  </record>
+  <record type="location">
+    <short-name>location07</short-name>
+    <uid>location07</uid>
+    <full-name>Room 07</full-name>
+  </record>
+  <record type="location">
+    <short-name>location08</short-name>
+    <uid>location08</uid>
+    <full-name>Room 08</full-name>
+  </record>
+  <record type="location">
+    <short-name>location09</short-name>
+    <uid>location09</uid>
+    <full-name>Room 09</full-name>
+  </record>
+  <record type="location">
+    <short-name>location10</short-name>
+    <uid>location10</uid>
+    <full-name>Room 10</full-name>
+  </record>
+
+  <record type="resource">
+    <short-name>resource01</short-name>
+    <uid>resource01</uid>
+    <full-name>Resource 01</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource02</short-name>
+    <uid>resource02</uid>
+    <full-name>Resource 02</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource03</short-name>
+    <uid>resource03</uid>
+    <full-name>Resource 03</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource04</short-name>
+    <uid>resource04</uid>
+    <full-name>Resource 04</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource05</short-name>
+    <uid>resource05</uid>
+    <full-name>Resource 05</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource06</short-name>
+    <uid>resource06</uid>
+    <full-name>Resource 06</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource07</short-name>
+    <uid>resource07</uid>
+    <full-name>Resource 07</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource08</short-name>
+    <uid>resource08</uid>
+    <full-name>Resource 08</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource09</short-name>
+    <uid>resource09</uid>
+    <full-name>Resource 09</full-name>
+  </record>
+  <record type="resource">
+    <short-name>resource10</short-name>
+    <uid>resource10</uid>
+    <full-name>Resource 10</full-name>
+  </record>
+
+  <!--
   <location repeat="10">
     <uid>location%02d</uid>
     <guid>location%02d</guid>
@@ -31,4 +134,5 @@
     <password>resource%02d</password>
     <name>Resource %02d</name>
   </resource>
-</accounts>
+-->
+</directory>

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/users-groups.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/users-groups.xml	2014-03-21 02:05:52 UTC (rev 12985)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/principals/users-groups.xml	2014-03-21 18:47:20 UTC (rev 12986)
@@ -18,7 +18,95 @@
 
 <!DOCTYPE accounts SYSTEM "accounts.dtd">
 
-<accounts realm="Test Realm">
+<directory realm="Test Realm">
+ <record type="user">
+    <short-name>user01</short-name>
+    <uid>user01</uid>
+    <password>user01</password>
+    <full-name>User 01</full-name>
+    <email>user01 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user02</short-name>
+    <uid>user02</uid>
+    <password>user02</password>
+    <full-name>User 02</full-name>
+    <email>user02 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user03</short-name>
+    <uid>user03</uid>
+    <password>user03</password>
+    <full-name>User 03</full-name>
+    <email>user03 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user04</short-name>
+    <uid>user04</uid>
+    <password>user04</password>
+    <full-name>User 04</full-name>
+    <email>user04 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user05</short-name>
+    <uid>user05</uid>
+    <password>user05</password>
+    <full-name>User 05</full-name>
+    <email>user05 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user06</short-name>
+    <uid>user06</uid>
+    <password>user06</password>
+    <full-name>User 06</full-name>
+    <email>user06 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user07</short-name>
+    <uid>user07</uid>
+    <password>user07</password>
+    <full-name>User 07</full-name>
+    <email>user07 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user08</short-name>
+    <uid>user08</uid>
+    <password>user08</password>
+    <full-name>User 08</full-name>
+    <email>user08 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user09</short-name>
+    <uid>user09</uid>
+    <password>user09</password>
+    <full-name>User 09</full-name>
+    <email>user09 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user10</short-name>
+    <uid>user10</uid>
+    <password>user10</password>
+    <full-name>User 10</full-name>
+    <email>user10 at example.com</email>
+  </record>
+
+  <record type="group">
+    <uid>e5a6142c-4189-4e9e-90b0-9cd0268b314b</uid>
+    <short-name>testgroup1</short-name>
+    <full-name>Group 01</full-name>
+      <member-uid type="users">user01</member-uid>
+      <member-uid type="users">user02</member-uid>
+  </record>
+  <!--
   <user repeat="10">
     <uid>user%02d</uid>
     <guid>user%02d</guid>
@@ -37,4 +125,5 @@
       <member type="users">user02</member>
     </members>
   </group>
-</accounts>
+  -->
+</directory>

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_principals.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_principals.py	2014-03-21 02:05:52 UTC (rev 12985)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_principals.py	2014-03-21 18:47:20 UTC (rev 12986)
@@ -19,18 +19,15 @@
 
 from calendarserver.tools.principals import (
     parseCreationArgs, matchStrings,
-    updateRecord, principalForPrincipalID, getProxies, setProxies
+    recordForPrincipalID, getProxies, setProxies
 )
 from twext.python.filepath import CachingFilePath as FilePath
 from twisted.internet import reactor
 from twisted.internet.defer import inlineCallbacks, Deferred, returnValue
 from twistedcaldav.config import config
-from twistedcaldav.directory import calendaruserproxy
-from twistedcaldav.directory.directory import DirectoryError
 from twistedcaldav.test.util import (
-    TestCase, CapturingProcessProtocol, ErrorOutput
+    TestCase, StoreTestCase, CapturingProcessProtocol, ErrorOutput
 )
-from txdav.who.util import directoryFromConfig
 
 
 
@@ -39,8 +36,8 @@
     def setUp(self):
         super(ManagePrincipalsTestCase, self).setUp()
 
-        # Since this test operates on proxy db, we need to assign the service:
-        calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(os.path.abspath(self.mktemp()))
+        # # Since this test operates on proxy db, we need to assign the service:
+        # calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(os.path.abspath(self.mktemp()))
 
         testRoot = os.path.join(os.path.dirname(__file__), "principals")
         templateName = os.path.join(testRoot, "caldavd.plist")
@@ -50,11 +47,11 @@
 
         databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid()))
         newConfig = template % {
-            "ServerRoot" : os.path.abspath(config.ServerRoot),
-            "DataRoot" : os.path.abspath(config.DataRoot),
-            "DatabaseRoot" : databaseRoot,
-            "DocumentRoot" : os.path.abspath(config.DocumentRoot),
-            "LogRoot" : os.path.abspath(config.LogRoot),
+            "ServerRoot": os.path.abspath(config.ServerRoot),
+            "DataRoot": os.path.abspath(config.DataRoot),
+            "DatabaseRoot": databaseRoot,
+            "DocumentRoot": os.path.abspath(config.DocumentRoot),
+            "LogRoot": os.path.abspath(config.LogRoot),
         }
         configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist"))
         configFilePath.setContent(newConfig)
@@ -62,18 +59,33 @@
         self.configFileName = configFilePath.path
         config.load(self.configFileName)
 
-        origUsersFile = FilePath(os.path.join(os.path.dirname(__file__),
-            "principals", "users-groups.xml"))
+        origUsersFile = FilePath(
+            os.path.join(
+                os.path.dirname(__file__),
+                "principals",
+                "users-groups.xml"
+            )
+        )
         copyUsersFile = FilePath(os.path.join(config.DataRoot, "accounts.xml"))
         origUsersFile.copyTo(copyUsersFile)
 
-        origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__),
-            "principals", "resources-locations.xml"))
+        origResourcesFile = FilePath(
+            os.path.join(
+                os.path.dirname(__file__),
+                "principals",
+                "resources-locations.xml"
+            )
+        )
         copyResourcesFile = FilePath(os.path.join(config.DataRoot, "resources.xml"))
         origResourcesFile.copyTo(copyResourcesFile)
 
-        origAugmentFile = FilePath(os.path.join(os.path.dirname(__file__),
-            "principals", "augments.xml"))
+        origAugmentFile = FilePath(
+            os.path.join(
+                os.path.dirname(__file__),
+                "principals",
+                "augments.xml"
+            )
+        )
         copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml"))
         origAugmentFile.copyTo(copyAugmentFile)
 
@@ -116,6 +128,7 @@
         self.assertTrue("users" in results)
         self.assertTrue("locations" in results)
         self.assertTrue("resources" in results)
+        self.assertTrue("addresses" in results)
 
 
     @inlineCallbacks
@@ -135,28 +148,36 @@
 
     @inlineCallbacks
     def test_addRemove(self):
-        results = yield self.runCommand("--add", "resources", "New Resource",
-            "newresource", "edaa6ae6-011b-4d89-ace3-6b688cdd91d9")
+        results = yield self.runCommand(
+            "--add", "resources",
+            "New Resource", "newresource", "newresourceuid"
+        )
         self.assertTrue("Added 'New Resource'" in results)
 
-        results = yield self.runCommand("--get-auto-schedule",
-            "resources:newresource")
-        self.assertTrue(results.startswith('Auto-schedule for "New Resource" (resources:newresource) is true'))
+        results = yield self.runCommand(
+            "--get-auto-schedule-mode",
+            "resources:newresource"
+        )
+        self.assertTrue(
+            results.startswith(
+                'Auto-schedule mode for "New Resource" newresourceuid (resource) newresource is Default'
+            )
+        )
 
-        results = yield self.runCommand("--get-auto-schedule-mode",
-            "resources:newresource")
-        self.assertTrue(results.startswith('Auto-schedule mode for "New Resource" (resources:newresource) is default'))
-
         results = yield self.runCommand("--list-principals=resources")
         self.assertTrue("newresource" in results)
 
-        results = yield self.runCommand("--add", "resources", "New Resource",
-            "newresource1", "edaa6ae6-011b-4d89-ace3-6b688cdd91d9")
-        self.assertTrue("Duplicate guid" in results)
+        results = yield self.runCommand(
+            "--add", "resources", "New Resource",
+            "newresource1", "newresourceuid"
+        )
+        self.assertTrue("UID already in use: newresourceuid" in results)
 
-        results = yield self.runCommand("--add", "resources", "New Resource",
-            "newresource", "fdaa6ae6-011b-4d89-ace3-6b688cdd91d9")
-        self.assertTrue("Duplicate shortName" in results)
+        results = yield self.runCommand(
+            "--add", "resources", "New Resource",
+            "newresource", "uniqueuid"
+        )
+        self.assertTrue("Record name already in use" in results)
 
         results = yield self.runCommand("--remove", "resources:newresource")
         self.assertTrue("Removed 'New Resource'" in results)
@@ -167,29 +188,13 @@
 
     def test_parseCreationArgs(self):
 
-        self.assertEquals(("full name", None, None),
-            parseCreationArgs(("full name",)))
-
-        self.assertEquals(("full name", "short name", None),
-            parseCreationArgs(("full name", "short name")))
-
-        guid = "02C3DE93-E655-4856-47B76B8BB1A7BDCE"
-
-        self.assertEquals(("full name", "short name", guid),
-            parseCreationArgs(("full name", "short name", guid)))
-
-        self.assertEquals(("full name", "short name", guid),
-            parseCreationArgs(("full name", guid, "short name")))
-
-        self.assertEquals(("full name", None, guid),
-            parseCreationArgs(("full name", guid)))
-
-        self.assertRaises(
-            ValueError,
-            parseCreationArgs, ("full name", "non guid", "non guid")
+        self.assertEquals(
+            ("full name", "short name", "uid"),
+            parseCreationArgs(("full name", "short name", "uid"))
         )
 
 
+
     def test_matchStrings(self):
         self.assertEquals("abc", matchStrings("a", ("abc", "def")))
         self.assertEquals("def", matchStrings("de", ("abc", "def")))
@@ -201,161 +206,126 @@
 
     @inlineCallbacks
     def test_modifyWriteProxies(self):
-        results = yield self.runCommand("--add-write-proxy=users:user01",
-            "locations:location01")
-        self.assertTrue(results.startswith('Added "Test User 01" (users:user01) as a write proxy for "Room 01" (locations:location01)'))
+        results = yield self.runCommand(
+            "--add-write-proxy=users:user01", "locations:location01"
+        )
+        self.assertTrue(
+            results.startswith('Added "User 01" user01 (user) user01 as a write proxy for "Room 01" location01 (location) location01')
+        )
 
-        results = yield self.runCommand("--list-write-proxies",
-            "locations:location01")
-        self.assertTrue("Test User 01" in results)
+        results = yield self.runCommand(
+            "--list-write-proxies", "locations:location01"
+        )
+        self.assertTrue("User 01" in results)
 
-        results = yield self.runCommand("--remove-proxy=users:user01",
-            "locations:location01")
+        results = yield self.runCommand(
+            "--remove-proxy=users:user01", "locations:location01"
+        )
 
-        results = yield self.runCommand("--list-write-proxies",
-            "locations:location01")
-        self.assertTrue('No write proxies for "Room 01" (locations:location01)' in results)
+        results = yield self.runCommand(
+            "--list-write-proxies", "locations:location01"
+        )
+        self.assertTrue(
+            'No write proxies for "Room 01" location01 (location) location01' in results
+        )
 
 
     @inlineCallbacks
     def test_modifyReadProxies(self):
-        results = yield self.runCommand("--add-read-proxy=users:user01",
-            "locations:location01")
-        self.assertTrue(results.startswith('Added "Test User 01" (users:user01) as a read proxy for "Room 01" (locations:location01)'))
+        results = yield self.runCommand(
+            "--add-read-proxy=users:user01", "locations:location01"
+        )
+        self.assertTrue(
+            results.startswith('Added "User 01" user01 (user) user01 as a read proxy for "Room 01" location01 (location) location01')
+        )
 
-        results = yield self.runCommand("--list-read-proxies",
-            "locations:location01")
-        self.assertTrue("Test User 01" in results)
+        results = yield self.runCommand(
+            "--list-read-proxies", "locations:location01"
+        )
+        self.assertTrue("User 01" in results)
 
-        results = yield self.runCommand("--remove-proxy=users:user01",
-            "locations:location01")
+        results = yield self.runCommand(
+            "--remove-proxy=users:user01", "locations:location01"
+        )
 
-        results = yield self.runCommand("--list-read-proxies",
-            "locations:location01")
-        self.assertTrue('No read proxies for "Room 01" (locations:location01)' in results)
+        results = yield self.runCommand(
+            "--list-read-proxies", "locations:location01"
+        )
+        self.assertTrue(
+            'No read proxies for "Room 01" location01 (location) location01' in results
+        )
 
 
     @inlineCallbacks
-    def test_autoSchedule(self):
-        results = yield self.runCommand("--get-auto-schedule",
-            "locations:location01")
-        self.assertTrue(results.startswith('Auto-schedule for "Room 01" (locations:location01) is false'))
-
-        results = yield self.runCommand("--set-auto-schedule=true",
-            "locations:location01")
-        self.assertTrue(results.startswith('Setting auto-schedule to true for "Room 01" (locations:location01)'))
-
-        results = yield self.runCommand("--get-auto-schedule",
-            "locations:location01")
-        self.assertTrue(results.startswith('Auto-schedule for "Room 01" (locations:location01) is true'))
-
-        results = yield self.runCommand("--set-auto-schedule=true",
-            "users:user01")
-        self.assertTrue(results.startswith('Enabling auto-schedule for (users)user01 is not allowed.'))
-
-
-    @inlineCallbacks
     def test_autoScheduleMode(self):
-        results = yield self.runCommand("--get-auto-schedule-mode",
-            "locations:location01")
-        self.assertTrue(results.startswith('Auto-schedule mode for "Room 01" (locations:location01) is default'))
+        results = yield self.runCommand(
+            "--get-auto-schedule-mode", "locations:location01"
+        )
+        self.assertTrue(
+            results.startswith('Auto-schedule mode for "Room 01" location01 (location) location01 is Default')
+        )
 
-        results = yield self.runCommand("--set-auto-schedule-mode=accept-if-free",
-            "locations:location01")
-        self.assertTrue(results.startswith('Setting auto-schedule mode to accept-if-free for "Room 01" (locations:location01)'))
+        results = yield self.runCommand(
+            "--set-auto-schedule-mode=accept-if-free", "locations:location01"
+        )
+        self.assertTrue(
+            results.startswith('Setting auto-schedule-mode to accept if free for "Room 01" location01 (location) location01')
+        )
 
-        results = yield self.runCommand("--get-auto-schedule-mode",
-            "locations:location01")
-        self.assertTrue(results.startswith('Auto-schedule mode for "Room 01" (locations:location01) is accept-if-free'))
+        results = yield self.runCommand(
+            "--get-auto-schedule-mode",
+            "locations:location01"
+        )
+        self.assertTrue(
+            results.startswith('Auto-schedule mode for "Room 01" location01 (location) location01 is accept if free')
+        )
 
-        results = yield self.runCommand("--set-auto-schedule-mode=decline-if-busy",
-            "users:user01")
-        self.assertTrue(results.startswith('Setting auto-schedule mode for (users)user01 is not allowed.'))
+        results = yield self.runCommand(
+            "--set-auto-schedule-mode=decline-if-busy", "users:user01"
+        )
+        self.assertTrue(results.startswith('Setting auto-schedule-mode for "User 01" user01 (user) user01 is not allowed.'))
 
         try:
-            results = yield self.runCommand("--set-auto-schedule-mode=bogus",
-                "users:user01")
+            results = yield self.runCommand(
+                "--set-auto-schedule-mode=bogus",
+                "users:user01"
+            )
         except ErrorOutput:
             pass
         else:
             self.fail("Expected command failure")
 
 
-    @inlineCallbacks
-    def test_updateRecord(self):
-        directory = directoryFromConfig(config)
-        guid = "EEE28807-A8C5-46C8-A558-A08281C558A7"
 
-        (yield updateRecord(True, directory, "locations",
-            guid=guid, fullName="Test Location", shortNames=["testlocation", ],)
-        )
-        try:
-            (yield updateRecord(True, directory, "locations",
-                guid=guid, fullName="Test Location", shortNames=["testlocation", ],)
-            )
-        except DirectoryError:
-            # We're expecting an error for trying to create a record with
-            # an existing GUID
-            pass
-        else:
-            raise self.failureException("Duplicate guid expected")
+class SetProxiesTestCase(StoreTestCase):
 
-        record = directory.recordWithGUID(guid)
-        self.assertTrue(record is not None)
-        self.assertEquals(record.fullName, "Test Location")
-        self.assertTrue(record.autoSchedule)
-
-        (yield updateRecord(False, directory, "locations",
-            guid=guid, fullName="Changed", shortNames=["testlocation", ],)
-        )
-        record = directory.recordWithGUID(guid)
-        self.assertTrue(record is not None)
-        self.assertEquals(record.fullName, "Changed")
-
-        directory.destroyRecord("locations", guid=guid)
-        record = directory.recordWithGUID(guid)
-        self.assertTrue(record is None)
-
-        # Create a user, change autoSchedule
-        guid = "F0DE73A8-39D4-4830-8D32-1FA03ABA3470"
-        (yield updateRecord(True, directory, "users",
-            guid=guid, fullName="Test User", shortNames=["testuser", ],
-            autoSchedule=True)
-        )
-        record = directory.recordWithGUID(guid)
-        self.assertTrue(record is not None)
-        self.assertEquals(record.fullName, "Test User")
-        self.assertTrue(record.autoSchedule)
-
-        (yield updateRecord(False, directory, "users",
-            guid=guid, fullName="Test User", shortNames=["testuser", ],
-            autoSchedule=False)
-        )
-        record = directory.recordWithGUID(guid)
-        self.assertTrue(record is not None)
-        self.assertEquals(record.fullName, "Test User")
-        self.assertFalse(record.autoSchedule)
-
-
     @inlineCallbacks
     def test_setProxies(self):
         """
         Read and Write proxies can be set en masse
         """
-        directory = directoryFromConfig(config)
+        directory = self.directory
+        record = yield recordForPrincipalID(directory, "users:user01")
 
-        principal = principalForPrincipalID("users:user01", directory=directory)
-        readProxies, writeProxies = (yield getProxies(principal, directory=directory))
-        self.assertEquals(readProxies, []) # initially empty
-        self.assertEquals(writeProxies, []) # initially empty
+        readProxies, writeProxies = yield getProxies(record)
+        self.assertEquals(readProxies, [])  # initially empty
+        self.assertEquals(writeProxies, [])  # initially empty
 
-        (yield setProxies(None, principal, ["users:user03", "users:user04"], ["users:user05"], directory=directory))
-        readProxies, writeProxies = (yield getProxies(principal, directory=directory))
-        self.assertEquals(set(readProxies), set(["user03", "user04"]))
-        self.assertEquals(set(writeProxies), set(["user05"]))
+        readProxies = [
+            (yield recordForPrincipalID(directory, "users:user03")),
+            (yield recordForPrincipalID(directory, "users:user04")),
+        ]
+        writeProxies = [
+            (yield recordForPrincipalID(directory, "users:user05")),
+        ]
+        yield setProxies(record, readProxies, writeProxies)
 
+        readProxies, writeProxies = yield getProxies(record)
+        self.assertEquals(set([r.uid for r in readProxies]), set(["user03", "user04"]))
+        self.assertEquals(set([r.uid for r in writeProxies]), set(["user05"]))
+
         # Using None for a proxy list indicates a no-op
-        (yield setProxies(None, principal, [], None, directory=directory))
-        readProxies, writeProxies = (yield getProxies(principal, directory=directory))
-        self.assertEquals(readProxies, []) # now empty
-        self.assertEquals(set(writeProxies), set(["user05"])) # unchanged
+        yield setProxies(record, [], None)
+        readProxies, writeProxies = yield getProxies(record)
+        self.assertEquals(readProxies, [])  # now empty
+        self.assertEquals(set([r.uid for r in writeProxies]), set(["user05"]))  # unchanged

Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml	2014-03-21 02:05:52 UTC (rev 12985)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml	2014-03-21 18:47:20 UTC (rev 12986)
@@ -170,6 +170,23 @@
     <email>user04 at example.com</email>
   </record>
 
+  <record type="user">
+    <short-name>user05</short-name>
+    <uid>user05</uid>
+    <password>user05</password>
+    <full-name>User 05</full-name>
+    <email>user05 at example.com</email>
+  </record>
+
+  <record type="user">
+    <short-name>user06</short-name>
+    <uid>user06</uid>
+    <password>user06</password>
+    <full-name>User 06</full-name>
+    <email>user06 at example.com</email>
+  </record>
+
+
   <!-- Repeat is not (yet?) supported in twext.who.xml
   <user repeat="100">
     <short-name>user%02d</short-name>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140321/d9baa231/attachment-0001.html>


More information about the calendarserver-changes mailing list