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

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 21 19:55:46 PDT 2014


Revision: 12990
          http://trac.calendarserver.org//changeset/12990
Author:   sagen at apple.com
Date:     2014-03-21 19:55:46 -0700 (Fri, 21 Mar 2014)
Log Message:
-----------
Starting to get test_gateway working again

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/gateway.py
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/augments.xml
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/caldavd.plist
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/resources-locations.xml
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/users-groups.xml
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_gateway.py
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/augment.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/gateway.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/gateway.py	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/gateway.py	2014-03-22 02:55:46 UTC (rev 12990)
@@ -19,31 +19,53 @@
 
 from getopt import getopt, GetoptError
 import os
+from plistlib import readPlistFromString, writePlistToString
 import sys
 import xml
 
-from plistlib import readPlistFromString, writePlistToString
-
-from twisted.internet.defer import inlineCallbacks, succeed
-from twistedcaldav.directory.directory import DirectoryError
-from txdav.xml import element as davxml
-
+from calendarserver.tools.cmdline import utilityMain
+from calendarserver.tools.config import WRITABLE_CONFIG_KEYS, setKeyPath, getKeyPath, flattenDictionary, WritableConfig
+from calendarserver.tools.principals import (
+    getProxies, setProxies
+)
+from calendarserver.tools.purge import WorkerService, PurgeOldEventsService, DEFAULT_BATCH_SIZE, DEFAULT_RETAIN_DAYS
 from calendarserver.tools.util import (
     principalForPrincipalID, proxySubprincipal, addProxy, removeProxy,
     ProxyError, ProxyWarning, autoDisableMemcached
 )
-from calendarserver.tools.principals import (
-    getProxies, setProxies, updateRecord, attrMap
-)
-from calendarserver.tools.purge import WorkerService, PurgeOldEventsService, DEFAULT_BATCH_SIZE, DEFAULT_RETAIN_DAYS
-from calendarserver.tools.cmdline import utilityMain
-
 from pycalendar.datetime import DateTime
-
+from twext.who.directory import DirectoryRecord
+from twisted.internet.defer import inlineCallbacks, succeed
 from twistedcaldav.config import config, ConfigDict
+from txdav.xml import element as davxml
 
-from calendarserver.tools.config import WRITABLE_CONFIG_KEYS, setKeyPath, getKeyPath, flattenDictionary, WritableConfig
+from txdav.who.idirectory import RecordType as CalRecordType
+from twext.who.idirectory import FieldName
 
+
+attrMap = {
+    'GeneratedUID': {'attr': 'uid', },
+    'RealName': {'attr': 'fullNames', },
+    'RecordName': {'attr': 'shortNames', },
+    'AutoScheduleMode': {'attr': 'autoScheduleMode', },
+    'AutoAcceptGroup': {'attr': 'autoAcceptGroup', },
+
+    # 'Comment': {'extras': True, 'attr': 'comment', },
+    # 'Description': {'extras': True, 'attr': 'description', },
+    # 'Type': {'extras': True, 'attr': 'type', },
+
+    # For "Locations", i.e. scheduled spaces
+    'Capacity': {'attr': 'capacity', },
+    'Floor': {'attr': 'floor', },
+    'AssociatedAddress': {'attr': 'associatedAddress', },
+
+    # For "Addresses", i.e. nonscheduled areas containing Locations
+    'AbbreviatedName': {'attr': 'abbreviatedName', },
+    'StreetAddress': {'attr': 'streetAddress', },
+    'GeographicLocation': {'attr': 'geographicLocation', },
+}
+
+
 def usage(e=None):
 
     name = os.path.basename(sys.argv[0])
@@ -76,9 +98,7 @@
         """
         Create/run a Runner to execute the commands
         """
-        rootResource = self.rootResource()
-        directory = rootResource.getDirectory()
-        runner = Runner(rootResource, directory, self.store, self.commands)
+        runner = Runner(self.store, self.commands)
         if runner.validate():
             yield runner.run()
 
@@ -145,10 +165,9 @@
 
 class Runner(object):
 
-    def __init__(self, root, directory, store, commands, output=None):
-        self.root = root
-        self.dir = directory
+    def __init__(self, store, commands, output=None):
         self.store = store
+        self.dir = store.directoryService()
         self.commands = commands
         if output is None:
             output = sys.stdout
@@ -180,12 +199,13 @@
             pool.ClientEnabled = True
         autoDisableMemcached(config)
 
-        from twistedcaldav.directory import calendaruserproxy
-        if calendaruserproxy.ProxyDBService is not None:
-            # Reset the proxy db memcacher because memcached may have come or
-            # gone since the last time through here.
-            # TODO: figure out a better way to do this
-            calendaruserproxy.ProxyDBService._memcacher._memcacheProtocol = None
+        # FIXME:
+        # from twistedcaldav.directory import calendaruserproxy
+        # if calendaruserproxy.ProxyDBService is not None:
+        #     # Reset the proxy db memcacher because memcached may have come or
+        #     # gone since the last time through here.
+        #     # TODO: figure out a better way to do this
+        #     calendaruserproxy.ProxyDBService._memcacher._memcacheProtocol = None
 
         try:
             for command in self.commands:
@@ -203,47 +223,85 @@
 
     # Locations
 
+    # deferred
     def command_getLocationList(self, command):
-        self.respondWithRecordsOfTypes(self.dir, command, ["locations"])
+        return self.respondWithRecordsOfTypes(self.dir, command, ["locations"])
 
 
     @inlineCallbacks
     def command_createLocation(self, command):
-        kwargs = {}
+
+        fields = {
+            FieldName.recordType: CalRecordType.location
+        }
         for key, info in attrMap.iteritems():
             if key in command:
-                kwargs[info['attr']] = command[key]
+                attrName = info['attr']
+                field = self.dir.fieldName.lookupByName(attrName)
+                valueType = self.dir.fieldName.valueType(field)
+                value = command[key]
+                if self.dir.fieldName.isMultiValue(field) and not isinstance(value, list):
+                    value = [value]
+                if valueType == int:
+                    value = int(value)
+                else:
+                    if isinstance(value, list):
+                        newList = []
+                        for item in value:
+                            if isinstance(item, str):
+                                newList.append(item.decode("utf-8"))
+                            else:
+                                newList.append(item)
+                        value = newList
+                    elif isinstance(value, str):
+                        value = value.decode("utf-8")
 
-        try:
-            record = (yield updateRecord(True, self.dir, "locations", **kwargs))
-        except DirectoryError, e:
-            self.respondWithError(str(e))
-            return
+                fields[field] = value
 
+        record = DirectoryRecord(self.dir, fields)
+        yield self.dir.updateRecords([record], create=True)
+
+
         readProxies = command.get("ReadProxies", None)
+        if readProxies:
+            proxyRecords = []
+            for proxyUID in readProxies:
+                proxyRecord = yield self.dir.recordWithUID(proxyUID)
+                if proxyRecord is not None:
+                    proxyRecords.append(proxyRecord)
+            readProxies = proxyRecords
+
         writeProxies = command.get("WriteProxies", None)
-        principal = principalForPrincipalID(record.guid, directory=self.dir)
-        (yield setProxies(self.store, principal, readProxies, writeProxies, directory=self.dir))
+        if writeProxies:
+            proxyRecords = []
+            for proxyUID in writeProxies:
+                proxyRecord = yield self.dir.recordWithUID(proxyUID)
+                if proxyRecord is not None:
+                    proxyRecords.append(proxyRecord)
+            writeProxies = proxyRecords
 
-        self.respondWithRecordsOfTypes(self.dir, command, ["locations"])
+        yield setProxies(record, readProxies, writeProxies)
 
+        yield self.respondWithRecordsOfTypes(self.dir, command, ["locations"])
 
+
     @inlineCallbacks
     def command_getLocationAttributes(self, command):
-        guid = command['GeneratedUID']
-        record = self.dir.recordWithGUID(guid)
+        uid = command['GeneratedUID']
+        record = yield self.dir.recordWithUID(uid)
         if record is None:
-            self.respondWithError("Principal not found: %s" % (guid,))
+            self.respondWithError("Location not found: %s" % (uid,))
             return
         recordDict = recordToDict(record)
-        principal = principalForPrincipalID(guid, directory=self.dir)
-        if principal is None:
-            self.respondWithError("Principal not found: %s" % (guid,))
-            return
-        recordDict['AutoSchedule'] = principal.getAutoSchedule()
-        recordDict['AutoAcceptGroup'] = principal.getAutoAcceptGroup()
-        recordDict['ReadProxies'], recordDict['WriteProxies'] = (yield getProxies(principal,
-            directory=self.dir))
+        # recordDict['AutoSchedule'] = principal.getAutoSchedule()
+        try:
+            recordDict['AutoAcceptGroup'] = record.autoAcceptGroup
+        except AttributeError:
+            pass
+
+        readProxies, writeProxies = yield getProxies(record)
+        recordDict['ReadProxies'] = [r.uid for r in readProxies]
+        recordDict['WriteProxies'] = [r.uid for r in writeProxies]
         self.respond(command, recordDict)
 
     command_getResourceAttributes = command_getLocationAttributes
@@ -358,8 +416,9 @@
         self.respondWithRecordsOfTypes(self.dir, command, ["resources"])
 
 
+    # deferred
     def command_getLocationAndResourceList(self, command):
-        self.respondWithRecordsOfTypes(self.dir, command, ["locations", "resources"])
+        return self.respondWithRecordsOfTypes(self.dir, command, ["locations", "resources"])
 
 
     # Addresses
@@ -604,10 +663,12 @@
         })
 
 
+    @inlineCallbacks
     def respondWithRecordsOfTypes(self, directory, command, recordTypes):
         result = []
         for recordType in recordTypes:
-            for record in directory.recordsWithRecordType(recordType):
+            recordType = directory.oldNameToRecordType(recordType)
+            for record in (yield directory.recordsWithRecordType(recordType)):
                 recordDict = recordToDict(record)
                 result.append(recordDict)
         self.respond(command, result)
@@ -626,11 +687,10 @@
     recordDict = {}
     for key, info in attrMap.iteritems():
         try:
-            if info.get('extras', False):
-                value = record.extras[info['attr']]
-            else:
-                value = getattr(record, info['attr'])
-            if isinstance(value, str):
+            value = record.fields[record.service.fieldName.lookupByName(info['attr'])]
+            if value is None:
+                continue
+            elif isinstance(value, str):
                 value = value.decode("utf-8")
             recordDict[key] = value
         except KeyError:

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py	2014-03-22 02:55:46 UTC (rev 12990)
@@ -119,29 +119,7 @@
             yield self.function(self.store, *self.params)
 
 
-attrMap = {
-    'GeneratedUID': {'attr': 'guid', },
-    'RealName': {'attr': 'fullName', },
-    'RecordName': {'attr': 'shortNames', },
-    'AutoSchedule': {'attr': 'autoSchedule', },
-    'AutoAcceptGroup': {'attr': 'autoAcceptGroup', },
 
-    'Comment': {'extras': True, 'attr': 'comment', },
-    'Description': {'extras': True, 'attr': 'description', },
-    'Type': {'extras': True, 'attr': 'type', },
-
-    # For "Locations", i.e. scheduled spaces
-    'Capacity': {'extras': True, 'attr': 'capacity', },
-    'Floor': {'extras': True, 'attr': 'floor', },
-    'AssociatedAddress': {'extras': True, 'attr': 'associatedAddress', },
-
-    # For "Addresses", i.e. nonscheduled areas containing Locations
-    'AbbreviatedName': {'extras': True, 'attr': 'abbreviatedName', },
-    'StreetAddress': {'extras': True, 'attr': 'streetAddress', },
-    'Geo': {'extras': True, 'attr': 'geo', },
-}
-
-
 def main():
     try:
         (optargs, args) = getopt(

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/augments.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/augments.xml	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/augments.xml	2014-03-22 02:55:46 UTC (rev 12990)
@@ -20,12 +20,6 @@
 
 <augments>
   <record>
-    <uid>Default</uid>
-    <enable>true</enable>
-    <enable-calendar>true</enable-calendar>
-    <enable-addressbook>true</enable-addressbook>
-  </record>
-  <record>
     <uid>user01</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/caldavd.plist
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/caldavd.plist	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/caldavd.plist	2014-03-22 02:55:46 UTC (rev 12990)
@@ -34,14 +34,6 @@
     <key>ServerHostName</key>
     <string></string> <!-- The hostname clients use when connecting -->
 
-    <!-- Enable Calendars -->
-    <key>EnableCalDAV</key>
-    <true/>
-
-    <!-- Enable AddressBooks -->
-    <key>EnableCardDAV</key>
-    <true/>
-
     <!-- HTTP port [0 = disable HTTP] -->
     <key>HTTPPort</key>
     <integer>8008</integer>
@@ -85,29 +77,29 @@
     <key>ServerRoot</key>
     <string>%(ServerRoot)s</string>
 
+    <!-- Data root -->
+    <key>DataRoot</key>
+    <string>%(DataRoot)s</string>
+
     <!-- Database root -->
     <key>DatabaseRoot</key>
     <string>%(DatabaseRoot)s</string>
 
-    <!-- Data root -->
-    <key>DataRoot</key>
-    <string>Data</string>
-
     <!-- Document root -->
     <key>DocumentRoot</key>
-    <string>Documents</string>
+    <string>%(DocumentRoot)s</string>
 
     <!-- Configuration root -->
     <key>ConfigRoot</key>
-    <string>config</string>
+    <string>%(ConfigRoot)s</string>
 
     <!-- Log root -->
     <key>LogRoot</key>
-    <string>Logs</string>
+    <string>%(LogRoot)s</string>
 
     <!-- Run root -->
     <key>RunRoot</key>
-    <string>Logs/state</string>
+    <string>%(RunRoot)s</string>
 
     <!-- Child aliases -->
     <key>Aliases</key>
@@ -147,7 +139,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.xmlfile.XMLDirectoryService</string>
-      
+
       <key>params</key>
       <dict>
         <key>xmlFile</key>
@@ -167,7 +159,7 @@
       <true/>
       <key>type</key>
       <string>twistedcaldav.directory.xmlfile.XMLDirectoryService</string>
-      
+
       <key>params</key>
       <dict>
         <key>xmlFile</key>
@@ -180,14 +172,14 @@
         </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>
@@ -211,7 +203,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.augment.AugmentXMLDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>xmlFiles</key>
@@ -220,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>
@@ -242,7 +234,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.augment.AugmentPostgreSQLDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>host</key>
@@ -258,7 +250,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.calendaruserproxy.ProxySqliteDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>dbpath</key>
@@ -272,7 +264,7 @@
     <dict>
       <key>type</key>
       <string>twistedcaldav.directory.calendaruserproxy.ProxyPostgreSQLDB</string>
-      
+
       <key>params</key>
       <dict>
         <key>host</key>
@@ -490,31 +482,65 @@
 
       <key>Services</key>
       <dict>
+        <key>SimpleLineNotifier</key>
+        <dict>
+          <!-- Simple line notification service (for testing) -->
+          <key>Service</key>
+          <string>twistedcaldav.notify.SimpleLineNotifierService</string>
+          <key>Enabled</key>
+          <false/>
+          <key>Port</key>
+          <integer>62308</integer>
+        </dict>
 
-        <key>APNS</key>
+        <key>XMPPNotifier</key>
         <dict>
+          <!-- XMPP notification service -->
+          <key>Service</key>
+          <string>twistedcaldav.notify.XMPPNotifierService</string>
           <key>Enabled</key>
           <false/>
-          <key>EnableStaggering</key>
-          <true/>
-          <key>StaggerSeconds</key>
-          <integer>5</integer>
-          <key>CalDAV</key>
+
+          <!-- XMPP host and port to contact -->
+          <key>Host</key>
+          <string>xmpp.host.name</string>
+          <key>Port</key>
+          <integer>5222</integer>
+
+          <!-- Jabber ID and password for the server -->
+          <key>JID</key>
+          <string>jid at xmpp.host.name/resource</string>
+          <key>Password</key>
+          <string>password_goes_here</string>
+
+          <!-- PubSub service address -->
+          <key>ServiceAddress</key>
+          <string>pubsub.xmpp.host.name</string>
+
+          <key>NodeConfiguration</key>
           <dict>
-            <key>CertificatePath</key>
-            <string>/example/calendar.cer</string>
-            <key>PrivateKeyPath</key>
-            <string>/example/calendar.pem</string>
+            <key>pubsub#deliver_payloads</key>
+            <string>1</string>
+            <key>pubsub#persist_items</key>
+            <string>1</string>
           </dict>
-          <key>CardDAV</key>
-          <dict>
-            <key>CertificatePath</key>
-            <string>/example/contacts.cer</string>
-            <key>PrivateKeyPath</key>
-            <string>/example/contacts.pem</string>
-          </dict>
+
+          <!-- Sends a presence notification to XMPP server at this interval (prevents disconnect) -->
+          <key>KeepAliveSeconds</key>
+          <integer>120</integer>
+
+          <!-- Sends a pubsub publish to a particular heartbeat node at this interval -->
+          <key>HeartbeatMinutes</key>
+          <integer>30</integer>
+
+          <!-- List of glob-like expressions defining which XMPP JIDs can converse with the server (for debugging) -->
+          <key>AllowedJIDs</key>
+          <array>
+            <!--
+            <string>*.example.com</string>
+             -->
+          </array>
         </dict>
-
       </dict>
     </dict>
 
@@ -651,6 +677,7 @@
 	<key>UsePackageTimezones</key>
 	<true/>
 
+
     <!--
         Miscellaneous items
       -->
@@ -666,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>
@@ -705,7 +732,6 @@
     <key>ResponseCacheTimeout</key>
     <integer>30</integer> <!-- in minutes -->
 
-
     <!-- For unit tests, enable SharedConnectionPool so we don't use up shared memory -->
     <key>SharedConnectionPool</key>
     <true/>
@@ -730,12 +756,5 @@
     </dict>
 
 
-    <key>Includes</key>
-    <array>
-        <string>%(WritablePlist)s</string>
-    </array>
-    <key>WritableConfigFile</key>
-    <string>%(WritablePlist)s</string>
-
   </dict>
 </plist>

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/resources-locations.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/resources-locations.xml	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/resources-locations.xml	2014-03-22 02:55:46 UTC (rev 12990)
@@ -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/gateway/users-groups.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/users-groups.xml	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/gateway/users-groups.xml	2014-03-22 02:55:46 UTC (rev 12990)
@@ -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,13 +125,5 @@
       <member type="users">user02</member>
     </members>
   </group>
-  <group>
-    <uid>testgroup2</uid>
-    <guid>f5a6142c-4189-4e9e-90b0-9cd0268b314b</guid>
-    <password>test</password>
-    <name>Group 02</name>
-    <members>
-      <member type="users">user01</member>
-    </members>
-  </group>
-</accounts>
+  -->
+</directory>

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_gateway.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_gateway.py	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_gateway.py	2014-03-22 02:55:46 UTC (rev 12990)
@@ -25,17 +25,45 @@
 from twisted.internet.defer import inlineCallbacks, Deferred, returnValue
 
 from twistedcaldav.config import config
-from twistedcaldav.test.util import TestCase, CapturingProcessProtocol
+from twistedcaldav.test.util import StoreTestCase, CapturingProcessProtocol
 import plistlib
-from twisted.trial.unittest import SkipTest
+from twistedcaldav.memcacheclient import ClientFactory
+from twistedcaldav import memcacher
 
 
-class RunCommandTestCase(TestCase):
+class RunCommandTestCase(StoreTestCase):
 
-    def setUp(self):
-        super(RunCommandTestCase, self).setUp()
-        raise SkipTest("Needs porting to twext.who still")
+    def configure(self):
+        """
+        Override the standard StoreTestCase configuration
+        """
+        self.serverRoot = self.mktemp()
+        os.mkdir(self.serverRoot)
+        absoluteServerRoot = os.path.abspath(self.serverRoot)
 
+        configRoot = os.path.join(absoluteServerRoot, "Config")
+        if not os.path.exists(configRoot):
+            os.makedirs(configRoot)
+
+        dataRoot = os.path.join(absoluteServerRoot, "Data")
+        if not os.path.exists(dataRoot):
+            os.makedirs(dataRoot)
+
+        documentRoot = os.path.join(absoluteServerRoot, "Documents")
+        if not os.path.exists(documentRoot):
+            os.makedirs(documentRoot)
+
+        logRoot = os.path.join(absoluteServerRoot, "Logs")
+        if not os.path.exists(logRoot):
+            os.makedirs(logRoot)
+
+        runRoot = os.path.join(absoluteServerRoot, "Run")
+        if not os.path.exists(runRoot):
+            os.makedirs(runRoot)
+
+        config.reset()
+        self.configInit()
+
         testRoot = os.path.join(os.path.dirname(__file__), "gateway")
         templateName = os.path.join(testRoot, "caldavd.plist")
         templateFile = open(templateName)
@@ -44,41 +72,79 @@
 
         databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid()))
         newConfig = template % {
-            "ServerRoot" : os.path.abspath(config.ServerRoot),
-            "DatabaseRoot" : databaseRoot,
-            "WritablePlist" : os.path.join(os.path.abspath(config.ConfigRoot), "caldavd-writable.plist"),
+            "ServerRoot": absoluteServerRoot,
+            "DataRoot": dataRoot,
+            "DatabaseRoot": databaseRoot,
+            "DocumentRoot": documentRoot,
+            "ConfigRoot": configRoot,
+            "LogRoot": logRoot,
+            "RunRoot": runRoot,
+            "WritablePlist": os.path.join(
+                os.path.abspath(configRoot), "caldavd-writable.plist"
+            ),
         }
-        configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist"))
+        configFilePath = FilePath(
+            os.path.join(configRoot, "caldavd.plist")
+        )
+
         configFilePath.setContent(newConfig)
 
         self.configFileName = configFilePath.path
         config.load(self.configFileName)
 
-        origUsersFile = FilePath(os.path.join(os.path.dirname(__file__),
-            "gateway", "users-groups.xml"))
-        copyUsersFile = FilePath(os.path.join(config.DataRoot, "accounts.xml"))
+        config.Memcached.Pools.Default.ClientEnabled = False
+        config.Memcached.Pools.Default.ServerEnabled = False
+        ClientFactory.allowTestCache = True
+        memcacher.Memcacher.allowTestCache = True
+        memcacher.Memcacher.memoryCacheInstance = None
+        config.DirectoryAddressBook.Enabled = False
+        config.UsePackageTimezones = True
+
+        origUsersFile = FilePath(
+            os.path.join(
+                os.path.dirname(__file__),
+                "gateway",
+                "users-groups.xml"
+            )
+        )
+        copyUsersFile = FilePath(
+            os.path.join(config.DataRoot, "accounts.xml")
+        )
         origUsersFile.copyTo(copyUsersFile)
 
-        origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__),
-            "gateway", "resources-locations.xml"))
-        copyResourcesFile = FilePath(os.path.join(config.DataRoot, "resources.xml"))
+        origResourcesFile = FilePath(
+            os.path.join(
+                os.path.dirname(__file__),
+                "gateway",
+                "resources-locations.xml"
+            )
+        )
+        copyResourcesFile = FilePath(
+            os.path.join(config.DataRoot, "resources.xml")
+        )
         origResourcesFile.copyTo(copyResourcesFile)
 
-        origAugmentFile = FilePath(os.path.join(os.path.dirname(__file__),
-            "gateway", "augments.xml"))
+        origAugmentFile = FilePath(
+            os.path.join(
+                os.path.dirname(__file__),
+                "gateway",
+                "augments.xml"
+            )
+        )
         copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml"))
         origAugmentFile.copyTo(copyAugmentFile)
 
-        # Make sure trial puts the reactor in the right state, by letting it
-        # run one reactor iteration.  (Ignore me, please.)
-        d = Deferred()
-        reactor.callLater(0, d.callback, True)
-        return d
+        # # Make sure trial puts the reactor in the right state, by letting it
+        # # run one reactor iteration.  (Ignore me, please.)
+        # d = Deferred()
+        # reactor.callLater(0, d.callback, True)
+        # return d
 
 
     @inlineCallbacks
-    def runCommand(self, command, error=False,
-        script="calendarserver_command_gateway"):
+    def runCommand(
+        self, command, error=False, script="calendarserver_command_gateway"
+    ):
         """
         Run the given command by feeding it as standard input to
         calendarserver_command_gateway in a subprocess.
@@ -87,7 +153,9 @@
         if isinstance(command, unicode):
             command = command.encode("utf-8")
 
-        sourceRoot = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
+        sourceRoot = os.path.dirname(
+            os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+        )
         python = sys.executable
         script = os.path.join(sourceRoot, "bin", script)
 
@@ -98,7 +166,10 @@
         cwd = sourceRoot
 
         deferred = Deferred()
-        reactor.spawnProcess(CapturingProcessProtocol(deferred, command), python, args, env=os.environ, path=cwd)
+        reactor.spawnProcess(
+            CapturingProcessProtocol(deferred, command),
+            python, args, env=os.environ, path=cwd
+        )
         output = yield deferred
         try:
             plist = readPlistFromString(output)
@@ -158,15 +229,14 @@
 
     @inlineCallbacks
     def test_createAddress(self):
-        directory = getDirectory()
 
-        record = directory.recordWithUID("C701069D-9CA1-4925-A1A9-5CD94767B74B")
+        record = yield self.directory.recordWithUID("C701069D-9CA1-4925-A1A9-5CD94767B74B")
         self.assertEquals(record, None)
         yield self.runCommand(command_createAddress)
 
-        directory.flushCaches()
+        # directory.flushCaches()
 
-        record = directory.recordWithUID("C701069D-9CA1-4925-A1A9-5CD94767B74B")
+        record = yield self.directory.recordWithUID("C701069D-9CA1-4925-A1A9-5CD94767B74B")
         self.assertEquals(record.fullName.decode("utf-8"),
             "Created Address 01 %s %s" % (unichr(208), u"\ud83d\udca3"))
 
@@ -197,29 +267,27 @@
 
     @inlineCallbacks
     def test_createLocation(self):
-        directory = getDirectory()
 
-        record = directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
+        record = yield self.directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
         self.assertEquals(record, None)
         yield self.runCommand(command_createLocation)
 
-        directory.flushCaches()
+        # directory.flushCaches()
 
         # This appears to be necessary in order for record.autoSchedule to
         # reflect the change prior to the directory record expiration
-        augmentService = directory.serviceForRecordType(directory.recordType_locations).augmentService
-        augmentService.refresh()
+        # augmentService = directory.serviceForRecordType(directory.recordType_locations).augmentService
+        # augmentService.refresh()
 
-        record = directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
-        self.assertEquals(record.fullName.decode("utf-8"),
-            "Created Location 01 %s %s" % (unichr(208), u"\ud83d\udca3"))
+        record = yield self.directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
+        self.assertEquals(record.fullNames[0],
+            u"Created Location 01 %s %s" % (unichr(208), u"\ud83d\udca3"))
 
         self.assertNotEquals(record, None)
-        self.assertEquals(record.autoSchedule, True)
+        # self.assertEquals(record.autoScheduleMode, "")
 
-        self.assertEquals(record.extras["comment"], "Test Comment")
-        self.assertEquals(record.extras["floor"], "First")
-        self.assertEquals(record.extras["capacity"], "40")
+        self.assertEquals(record.floor, u"First")
+        # self.assertEquals(record.extras["capacity"], "40")
 
         results = yield self.runCommand(command_getLocationAttributes)
         self.assertEquals(set(results["result"]["ReadProxies"]), set(['user03', 'user04']))
@@ -437,8 +505,10 @@
 <dict>
         <key>command</key>
         <string>createLocation</string>
-        <key>AutoSchedule</key>
-        <true/>
+        <!--
+        <key>AutoScheduleMode</key>
+        <string></string>
+        -->
         <key>AutoAcceptGroup</key>
         <string>E5A6142C-4189-4E9E-90B0-9CD0268B314B</string>
         <key>GeneratedUID</key>
@@ -455,19 +525,21 @@
         <string>Test Description</string>
         <key>Floor</key>
         <string>First</string>
+        <!--
         <key>Capacity</key>
         <string>40</string>
+        -->
         <key>AssociatedAddress</key>
         <string>C701069D-9CA1-4925-A1A9-5CD94767B74B</string>
         <key>ReadProxies</key>
         <array>
-            <string>users:user03</string>
-            <string>users:user04</string>
+            <string>user03</string>
+            <string>user04</string>
         </array>
         <key>WriteProxies</key>
         <array>
-            <string>users:user05</string>
-            <string>users:user06</string>
+            <string>user05</string>
+            <string>user06</string>
         </array>
 </dict>
 </plist>

Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/augment.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/augment.py	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/augment.py	2014-03-22 02:55:46 UTC (rev 12990)
@@ -60,7 +60,7 @@
         enabledForCalendaring=False,
         autoSchedule=False,
         autoScheduleMode="default",
-        autoAcceptGroup="",
+        autoAcceptGroup=None,
         enabledForAddressBooks=False,
         enabledForLogin=True,
     ):

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py	2014-03-21 22:29:24 UTC (rev 12989)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py	2014-03-22 02:55:46 UTC (rev 12990)
@@ -199,15 +199,23 @@
                     AutoScheduleMode.declineIfBusy: "decline-if-busy",
                     AutoScheduleMode.acceptIfFreeDeclineIfBusy: "automatic",
                 }.get(augmentFields.get(FieldName.autoScheduleMode, None), None)
-                augmentRecord = AugmentRecord(
-                    uid=record.uid,
-                    enabledForCalendaring=augmentFields[FieldName.hasCalendars],
-                    enabledForAddressBooks=augmentFields[FieldName.hasContacts],
-                    autoScheduleMode=autoScheduleMode,
-                    enabledForLogin=augmentFields[FieldName.loginAllowed],
-                    autoAcceptGroup=augmentFields[FieldName.autoAcceptGroup],
-                    serverID=augmentFields[FieldName.serviceNodeUID],
-                )
+
+                kwargs = {
+                    "uid": record.uid,
+                    "autoScheduleMode": autoScheduleMode,
+                }
+                if FieldName.hasCalendars in augmentFields:
+                    kwargs["enabledForCalendaring"] = augmentFields[FieldName.hasCalendars]
+                if FieldName.hasContacts in augmentFields:
+                    kwargs["enabledForAddressBooks"] = augmentFields[FieldName.hasContacts]
+                if FieldName.loginAllowed in augmentFields:
+                    kwargs["enabledForLogin"] = augmentFields[FieldName.loginAllowed]
+                if FieldName.autoAcceptGroup in augmentFields:
+                    kwargs["autoAcceptGroup"] = augmentFields[FieldName.autoAcceptGroup]
+                if FieldName.serviceNodeUID in augmentFields:
+                    kwargs["serverID"] = augmentFields[FieldName.serviceNodeUID]
+                augmentRecord = AugmentRecord(**kwargs)
+
                 augmentRecords.append(augmentRecord)
 
             # Create new base records:
@@ -301,10 +309,11 @@
                 autoScheduleMode
             )
 
-            self._assignToField(
-                fields, "autoAcceptGroup",
-                augmentRecord.autoAcceptGroup.decode("utf-8")
-            )
+            if augmentRecord.autoAcceptGroup is not None:
+                self._assignToField(
+                    fields, "autoAcceptGroup",
+                    augmentRecord.autoAcceptGroup.decode("utf-8")
+                )
 
             self._assignToField(
                 fields, "loginAllowed",
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140321/573c502d/attachment-0001.html>


More information about the calendarserver-changes mailing list