[CalendarServer-changes] [11098] CalendarServer/branches/users/cdaboo/store-scheduling

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 25 09:57:58 PDT 2013


Revision: 11098
          http://trac.calendarserver.org//changeset/11098
Author:   cdaboo at apple.com
Date:     2013-04-25 09:57:58 -0700 (Thu, 25 Apr 2013)
Log Message:
-----------
Checkpoint: ischedule support.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tap/util.py
    CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/__init__.py
    CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/scheduling/ischedule/delivery.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/delivery.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/remoteservers.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/resource.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/scheduler.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_delivery.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_dkim.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_localservers.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_remoteservers.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_resource.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_utils.py
    CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/test/util.py

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tap/util.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tap/util.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/calendarserver/tap/util.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -61,8 +61,8 @@
 from calendarserver.push.applepush import APNSubscriptionResource
 from twistedcaldav.directorybackedaddressbook import DirectoryBackedAddressBookResource
 from twistedcaldav.resource import AuthenticationWrapper
-from twistedcaldav.scheduling.ischedule.dkim import DKIMUtils, DomainKeyResource
-from twistedcaldav.scheduling.ischedule.resource import IScheduleInboxResource
+from txdav.caldav.datastore.scheduling.ischedule.dkim import DKIMUtils, DomainKeyResource
+from txdav.caldav.datastore.scheduling.ischedule.resource import IScheduleInboxResource
 from twistedcaldav.simpleresource import SimpleResource, SimpleRedirectResource
 from twistedcaldav.timezones import TimezoneCache
 from twistedcaldav.timezoneservice import TimezoneServiceResource

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/__init__.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/__init__.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/__init__.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -42,7 +42,6 @@
 import twistedcaldav.mkcolxml
 import twistedcaldav.customxml
 import twistedcaldav.timezonexml
-import twistedcaldav.scheduling.ischedule.xml
 
 twistedcaldav # Shhh.. pyflakes
 

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/scheduling/ischedule/delivery.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/scheduling/ischedule/delivery.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/scheduling/ischedule/delivery.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -45,9 +45,9 @@
 from twistedcaldav.scheduling.ischedule.remoteservers import IScheduleServerRecord
 from twistedcaldav.scheduling.ischedule.remoteservers import IScheduleServers
 from twistedcaldav.scheduling.ischedule.utils import lookupServerViaSRV
-from twistedcaldav.scheduling.ischedule.xml import ScheduleResponse, Response, \
-    RequestStatus, Recipient, ischedule_namespace, CalendarData, \
-    ResponseDescription, Error
+#from twistedcaldav.scheduling.ischedule.xml import ScheduleResponse, Response, \
+#    RequestStatus, Recipient, ischedule_namespace, CalendarData, \
+#    ResponseDescription, Error
 from twistedcaldav.scheduling.itip import iTIPRequestStatus
 from twistedcaldav.util import utf8String, normalizationLookup
 

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/delivery.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/delivery.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/delivery.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -45,7 +45,7 @@
 from txdav.caldav.datastore.scheduling.ischedule.remoteservers import IScheduleServerRecord
 from txdav.caldav.datastore.scheduling.ischedule.remoteservers import IScheduleServers
 from txdav.caldav.datastore.scheduling.ischedule.utils import lookupServerViaSRV
-from twistedcaldav.scheduling.ischedule.xml import ScheduleResponse, Response, \
+from txdav.caldav.datastore.scheduling.ischedule.xml import ScheduleResponse, Response, \
     RequestStatus, Recipient, ischedule_namespace, CalendarData, \
     ResponseDescription, Error
 from txdav.caldav.datastore.scheduling.itip import iTIPRequestStatus

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/remoteservers.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/remoteservers.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/remoteservers.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -43,7 +43,8 @@
 
     def __init__(self):
 
-        self._loadConfig()
+        if IScheduleServers._servers is None:
+            self._loadConfig()
 
 
     def _loadConfig(self):

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/resource.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/resource.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/resource.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -18,22 +18,25 @@
 from pycalendar.timezone import PyCalendarTimezone
 
 from twext.web2 import responsecode
+from twext.web2.dav.http import ErrorResponse
 from twext.web2.dav.noneprops import NonePropertyStore
 from twext.web2.http import Response, HTTPError, StatusResponse, XMLResponse
 from twext.web2.http_headers import MimeType
 
 from twisted.internet.defer import succeed, returnValue, inlineCallbacks
+from twisted.python.failure import Failure
 
 from twistedcaldav import caldavxml
 from twistedcaldav.config import config
 from twistedcaldav.directory.util import transactionFromRequest
-from twistedcaldav.extensions import DAVResource, \
-    DAVResourceWithoutChildrenMixin
+from twistedcaldav.extensions import DAVResource, DAVResourceWithoutChildrenMixin
+from twistedcaldav.ical import Component
 from twistedcaldav.resource import ReadOnlyNoCopyResourceMixIn
+from twistedcaldav.scheduling_store.caldav.resource import deliverSchedulePrivilegeSet
 
-from txdav.caldav.datastore.scheduling.caldav.resource import deliverSchedulePrivilegeSet
 from txdav.caldav.datastore.scheduling.ischedule.dkim import ISCHEDULE_CAPABILITIES
 from txdav.caldav.datastore.scheduling.ischedule.scheduler import IScheduleScheduler
+from txdav.caldav.datastore.scheduling.ischedule.xml import ischedule_namespace
 from txdav.xml import element as davxml
 import txdav.caldav.datastore.scheduling.ischedule.xml  as ischedulexml
 
@@ -212,30 +215,98 @@
         The server-to-server POST method.
         """
 
-        # This is a server-to-server scheduling operation.
-        scheduler = IScheduleScheduler(request, self)
-
         # Need a transaction to work with
         txn = transactionFromRequest(request, self._newStore)
-        request._newStoreTransaction = txn
 
+        # This is a server-to-server scheduling operation.
+        scheduler = IScheduleScheduler(txn, None)
+
+        originator = self.loadOriginatorFromRequestHeaders(request)
+        recipients = self.loadRecipientsFromRequestHeaders(request)
+        calendar = (yield self.loadCalendarFromRequest(request))
+
         # Do the POST processing treating this as a non-local schedule
         try:
-            result = (yield scheduler.doSchedulingViaPOST(txn, use_request_headers=True))
-        except Exception, e:
+            result = (yield scheduler.doSchedulingViaPOST(request, originator, recipients, calendar))
+        except Exception:
+            ex = Failure()
             yield txn.abort()
-            raise e
+            ex.raiseException()
         else:
             yield txn.commit()
         response = result.response()
         response.headers.addRawHeader(ISCHEDULE_CAPABILITIES, str(config.Scheduling.iSchedule.SerialNumber))
         returnValue(response)
 
+
+    def loadOriginatorFromRequestHeaders(self, request):
+        # Must have Originator header
+        originator = request.headers.getRawHeaders("originator")
+        if originator is None or (len(originator) != 1):
+            self.log_error("iSchedule POST request must have Originator header")
+            raise HTTPError(ErrorResponse(
+                responsecode.FORBIDDEN,
+                (ischedule_namespace, "originator-missing"),
+                "Missing originator",
+            ))
+        else:
+            originator = originator[0]
+        return originator
+
+
+    def loadRecipientsFromRequestHeaders(self, request):
+        # Get list of Recipient headers
+        rawRecipients = request.headers.getRawHeaders("recipient")
+        if rawRecipients is None or (len(rawRecipients) == 0):
+            self.log_error("%s request must have at least one Recipient header" % (self.method,))
+            raise HTTPError(ErrorResponse(
+                responsecode.FORBIDDEN,
+                (ischedule_namespace, "recipient-missing"),
+                "No recipients",
+            ))
+
+        # Recipient header may be comma separated list
+        recipients = []
+        for rawRecipient in rawRecipients:
+            for r in rawRecipient.split(","):
+                r = r.strip()
+                if len(r):
+                    recipients.append(r)
+
+        return recipients
+
+
+    @inlineCallbacks
+    def loadCalendarFromRequest(self, request):
+        # Must be content-type text/calendar
+        contentType = request.headers.getHeader("content-type")
+        if contentType is not None and (contentType.mediaType, contentType.mediaSubtype) != ("text", "calendar"):
+            self.log_error("MIME type %s not allowed in iSchedule POST request" % (contentType,))
+            raise HTTPError(ErrorResponse(
+                responsecode.FORBIDDEN,
+                (ischedule_namespace, "invalid-calendar-data-type"),
+                "Data is not calendar data",
+            ))
+
+        # Parse the calendar object from the HTTP request stream
+        try:
+            calendar = (yield Component.fromIStream(request.stream))
+        except:
+            # FIXME: Bare except
+            self.log_error("Error while handling iSchedule POST: %s" % (Failure(),))
+            raise HTTPError(ErrorResponse(
+                responsecode.FORBIDDEN,
+                (ischedule_namespace, "invalid-calendar-data"),
+                description="Can't parse calendar data"
+            ))
+
+        returnValue(calendar)
+
+
     ##
     # ACL
     ##
 
-
     def supportedPrivileges(self, request):
         return succeed(deliverSchedulePrivilegeSet)
 

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/scheduler.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/scheduler.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/scheduler.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -17,31 +17,34 @@
 from twext.python.log import Logger
 from twext.web2 import responsecode
 from twext.web2.http import HTTPError, Response
+from twext.web2.http_headers import MimeType
+
 from twisted.internet.abstract import isIPAddress
 from twisted.internet.defer import inlineCallbacks, returnValue
+
+from twistedcaldav.config import config
+from twistedcaldav.ical import normalizeCUAddress
+
 from txdav.caldav.datastore.scheduling import addressmapping
 from txdav.caldav.datastore.scheduling.cuaddress import RemoteCalendarUser
 from txdav.caldav.datastore.scheduling.cuaddress import calendarUserFromPrincipal
+from txdav.caldav.datastore.scheduling.ischedule import xml
+from txdav.caldav.datastore.scheduling.ischedule.dkim import DKIMVerifier, \
+    DKIMVerificationError, DKIMMissingError
+from txdav.caldav.datastore.scheduling.ischedule.localservers import Servers
 from txdav.caldav.datastore.scheduling.ischedule.remoteservers import IScheduleServers
+from txdav.caldav.datastore.scheduling.ischedule.utils import getIPsFromHost
+from txdav.caldav.datastore.scheduling.ischedule.xml import ischedule_namespace
+import txdav.caldav.datastore.scheduling.ischedule.xml as ixml
 from txdav.caldav.datastore.scheduling.scheduler import RemoteScheduler, \
     ScheduleResponseQueue
-import txdav.caldav.datastore.scheduling.ischedule.xml as ixml
-from txdav.caldav.datastore.scheduling.ischedule.localservers import Servers
-from twistedcaldav.util import normalizationLookup
-from txdav.xml import element as davxml
+from txdav.caldav.datastore.util import normalizationLookup
+from txdav.xml.base import WebDAVUnknownElement
+
 import itertools
 import re
 import socket
 import urlparse
-from twistedcaldav.config import config
-from txdav.caldav.datastore.scheduling.ischedule.dkim import DKIMVerifier, \
-    DKIMVerificationError, DKIMMissingError
-from twext.web2.http_headers import MimeType
-from txdav.caldav.datastore.scheduling.ischedule.xml import ischedule_namespace
-from txdav.xml.base import WebDAVUnknownElement
-from txdav.caldav.datastore.scheduling.ischedule.utils import getIPsFromHost
-from txdav.caldav.datastore.scheduling.ischedule import xml
-from twistedcaldav.ical import normalizeCUAddress
 
 """
 L{IScheduleScheduler} - handles deliveries for scheduling messages being POSTed to the iSchedule inbox.
@@ -136,11 +139,12 @@
     }
 
     @inlineCallbacks
-    def doSchedulingViaPOST(self, transaction, use_request_headers=False):
+    def doSchedulingViaPOST(self, request, originator, recipients, calendar):
         """
         Carry out iSchedule specific processing.
         """
 
+        self.request = request
         self.verified = False
         if config.Scheduling.iSchedule.DKIM.Enabled:
             verifier = DKIMVerifier(self.request, protocol_debug=config.Scheduling.iSchedule.DKIM.ProtocolDebug)
@@ -166,20 +170,16 @@
                     msg,
                 ))
 
-        result = (yield super(IScheduleScheduler, self).doSchedulingViaPOST(transaction, use_request_headers))
-        returnValue(result)
+        if self.request.headers.getRawHeaders('x-calendarserver-itip-refreshonly', ("F"))[0] == "T":
+            self.txn.doing_attendee_refresh = 1
 
+        # Normalize recipient addresses
+        recipients = [normalizeCUAddress(recipient, normalizationLookup, self.txn.directoryService().recordWithCalendarUserAddress) for recipient in recipients]
 
-    def loadFromRequestHeaders(self):
-        """
-        Load Originator and Recipient from request headers.
-        """
-        super(IScheduleScheduler, self).loadFromRequestHeaders()
+        result = (yield super(IScheduleScheduler, self).doSchedulingViaPOST(originator, recipients, calendar))
+        returnValue(result)
 
-        if self.request.headers.getRawHeaders('x-calendarserver-itip-refreshonly', ("F"))[0] == "T":
-            self.request.doing_attendee_refresh = 1
 
-
     def preProcessCalendarData(self):
         """
         For data coming in from outside we need to normalize the calendar user addresses so that later iTIP
@@ -190,7 +190,7 @@
         if not self.checkForFreeBusy():
             # Need to normalize the calendar data and recipient values to keep those in sync,
             # as we might later try to match them
-            self.calendar.normalizeCalendarUserAddresses(normalizationLookup, self.resource.principalForCalendarUserAddress)
+            self.calendar.normalizeCalendarUserAddresses(normalizationLookup, self.txn.directoryService().recordWithCalendarUserAddress)
 
 
     def loadRecipientsFromRequestHeaders(self):
@@ -199,13 +199,13 @@
         as we might later try to match them
         """
         super(IScheduleScheduler, self).loadRecipientsFromRequestHeaders()
-        self.recipients = [normalizeCUAddress(recipient, normalizationLookup, self.resource.principalForCalendarUserAddress) for recipient in self.recipients]
+        self.recipients = [normalizeCUAddress(recipient, normalizationLookup, self.txn.directoryService().recordWithCalendarUserAddress) for recipient in self.recipients]
 
 
     def checkAuthorization(self):
         # Must have an unauthenticated user
-        if self.resource.currentPrincipal(self.request) != davxml.Principal(davxml.Unauthenticated()):
-            log.err("Authenticated originators not allowed: %s" % (self.originator,))
+        if self.originator_uid is not None:
+            log.err("Authenticated originators not allowed: %s" % (self.originator_uid,))
             raise HTTPError(self.errorResponse(
                 responsecode.FORBIDDEN,
                 self.errorElements["originator-denied"],
@@ -220,7 +220,7 @@
         """
 
         # For remote requests we do not allow the originator to be a local user or one within our domain.
-        originatorPrincipal = self.resource.principalForCalendarUserAddress(self.originator)
+        originatorPrincipal = self.txn.directoryService().recordWithCalendarUserAddress(self.originator)
         localUser = (yield addressmapping.mapper.isCalendarUserInMyDomain(self.originator))
         if originatorPrincipal or localUser:
             if originatorPrincipal.locallyHosted():
@@ -367,7 +367,7 @@
         # Verify that the ORGANIZER's cu address does not map to a valid user
         organizer = self.calendar.getOrganizer()
         if organizer:
-            organizerPrincipal = self.resource.principalForCalendarUserAddress(organizer)
+            organizerPrincipal = self.txn.directoryService().recordWithCalendarUserAddress(organizer)
             if organizerPrincipal:
                 if organizerPrincipal.locallyHosted():
                     log.err("Invalid ORGANIZER in calendar data: %s" % (self.calendar,))
@@ -408,7 +408,7 @@
         """
 
         # Attendee cannot be local.
-        attendeePrincipal = self.resource.principalForCalendarUserAddress(self.attendee)
+        attendeePrincipal = self.txn.directoryService().recordWithCalendarUserAddress(self.attendee)
         if attendeePrincipal:
             if attendeePrincipal.locallyHosted():
                 log.err("Invalid ATTENDEE in calendar data: %s" % (self.calendar,))

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_delivery.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_delivery.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_delivery.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -14,15 +14,15 @@
 # limitations under the License.
 ##
 
-import twistedcaldav.test.util
 from twisted.internet.defer import inlineCallbacks
+from twisted.names import client
 from twisted.python.modules import getModule
-from twistedcaldav.config import config
+from twisted.trial import unittest
+from twistedcaldav.stdconfig import config
 from txdav.caldav.datastore.scheduling.ischedule import utils
-from twisted.names import client
 from txdav.caldav.datastore.scheduling.ischedule.delivery import ScheduleViaISchedule
 
-class CalDAV (twistedcaldav.test.util.TestCase):
+class CalDAV (unittest.TestCase):
     """
     txdav.caldav.datastore.scheduling.caldav tests
     """

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_dkim.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_dkim.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_dkim.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -22,8 +22,10 @@
 from twisted.internet.defer import inlineCallbacks, succeed
 from twisted.names import client
 from twisted.python.modules import getModule
+from twisted.trial import unittest
 
-from twistedcaldav.config import config
+from twistedcaldav.stdconfig import config
+
 from txdav.caldav.datastore.scheduling.ischedule import utils
 from txdav.caldav.datastore.scheduling.ischedule.dkim import DKIMRequest, DKIMVerifier, \
     DKIMVerificationError, DKIMUtils, PublicKeyLookup_DNSTXT, \
@@ -33,9 +35,8 @@
 import hashlib
 import os
 import time
-import twistedcaldav.test.util
 
-class TestDKIMBase (twistedcaldav.test.util.TestCase):
+class TestDKIMBase (unittest.TestCase):
     """
     DKIM support tests
     """

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_localservers.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_localservers.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_localservers.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -15,12 +15,16 @@
 ##
 
 from twext.web2.test.test_server import SimpleRequest
-from twistedcaldav.config import config
+
+from twisted.trial import unittest
+
+from twistedcaldav.stdconfig import config
+
 from txdav.caldav.datastore.scheduling.ischedule.localservers import Servers, SERVER_SECRET_HEADER
-from twistedcaldav.test.util import TestCase
+
 import StringIO as StringIO
 
-class ServerTests(TestCase):
+class ServerTests(unittest.TestCase):
 
     data1 = """<?xml version="1.0" encoding="utf-8"?>
 <servers>

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_remoteservers.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_remoteservers.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_remoteservers.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -15,10 +15,11 @@
 ##
 
 from twisted.python.filepath import FilePath
+from twisted.trial import unittest
+
 from txdav.caldav.datastore.scheduling.ischedule.remoteservers import IScheduleServersParser
-import twistedcaldav.test.util
 
-class Test_IScheduleServersParser(twistedcaldav.test.util.TestCase):
+class Test_IScheduleServersParser(unittest.TestCase):
     """
     Test L{IScheduleServersParser} implementation.
     """

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_resource.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_resource.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_resource.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -16,24 +16,72 @@
 
 from twext.web2 import http_headers, responsecode
 from twext.web2.test.test_server import SimpleRequest
+
 from twisted.internet.defer import inlineCallbacks
+
 from twistedcaldav.config import config
 from twistedcaldav.memcachelock import MemcacheLock
+
 from txdav.caldav.datastore.scheduling.ischedule.resource import IScheduleInboxResource
-from twistedcaldav.test.util import TestCase
+from txdav.caldav.datastore.scheduling.ischedule.remoteservers import IScheduleServerRecord, \
+    IScheduleServers
+from txdav.common.datastore.test.util import populateCalendarsFrom, \
+    CommonCommonTests
+from twext.python.clsprop import classproperty
+import twext.web2.dav.test.util
+from txdav.caldav.datastore.test.util import buildCalendarStore
 
-class iSchedulePOST (TestCase):
+class iSchedulePOST (CommonCommonTests, twext.web2.dav.test.util.TestCase):
 
+    @inlineCallbacks
     def setUp(self):
-        super(iSchedulePOST, self).setUp()
-        self.createStockDirectoryService()
-        self.setupCalendars()
-        self.site.resource.putChild(
-            "ischedule", IScheduleInboxResource(self.site.resource,
-                                                self.createDataStore()))
+        yield super(iSchedulePOST, self).setUp()
+        self._sqlCalendarStore = yield buildCalendarStore(self, self.notifierFactory)
+        self.directory = self._sqlCalendarStore.directoryService()
 
+        self.site.resource.putChild("ischedule", IScheduleInboxResource(self.site.resource, self.storeUnderTest()))
 
+        yield self.populate()
+
+
+    def storeUnderTest(self):
+        """
+        Return a store for testing.
+        """
+        return self._sqlCalendarStore
+
+
     @inlineCallbacks
+    def populate(self):
+        yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
+        self.notifierFactory.reset()
+
+
+    @classproperty(cache=False)
+    def requirements(cls): #@NoSelf
+        return {
+        "user01": {
+            "calendar_1": {
+            },
+            "inbox": {
+            },
+        },
+        "user02": {
+            "calendar_1": {
+            },
+            "inbox": {
+            },
+        },
+        "user03": {
+            "calendar_1": {
+            },
+            "inbox": {
+            },
+        },
+    }
+
+
+    @inlineCallbacks
     def test_deadlock(self):
         """
         Make calendar
@@ -73,3 +121,56 @@
 
         response = (yield self.send(request))
         self.assertEqual(response.code, responsecode.CONFLICT)
+
+    test_deadlock.skip = "Locking behavior is different now"
+
+
+    @inlineCallbacks
+    def test_receive(self):
+        """
+        Make calendar
+        """
+
+        IScheduleServers()
+        server = IScheduleServerRecord("http://127.0.0.1")
+        server.allow_from = True
+        IScheduleServers._domainMap["example.org"] = server
+
+        request = SimpleRequest(
+            self.site,
+            "POST",
+            "/ischedule",
+            headers=http_headers.Headers(rawHeaders={
+                "Originator": ("mailto:user01 at example.org",),
+                "Recipient": ("mailto:user02 at example.com",),
+            }),
+            content="""BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+VERSION:2.0
+METHOD:REQUEST
+BEGIN:VEVENT
+DTSTAMP:20051222T205953Z
+CREATED:20060101T150000Z
+DTSTART:20060101T100000Z
+DURATION:PT1H
+SUMMARY:event 1
+UID:deadlocked
+ORGANIZER:mailto:user01 at example.org
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.org
+ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION:mailto:user02 at example.com
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+        )
+
+        response = (yield self.send(request))
+        self.assertEqual(response.code, responsecode.OK)
+
+        calendar = (yield self.calendarUnderTest(name="calendar_1", home="user02"))
+        count = (yield calendar.listCalendarObjects())
+        self.assertEqual(len(count), 1)
+
+        inbox = (yield self.calendarUnderTest(name="inbox", home="user02"))
+        count = (yield inbox.listCalendarObjects())
+        self.assertEqual(len(count), 1)

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_utils.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_utils.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/scheduling/ischedule/test/test_utils.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -15,15 +15,15 @@
 ##
 
 from twisted.internet.defer import inlineCallbacks
-from twistedcaldav.config import config
-from txdav.caldav.datastore.scheduling.ischedule import utils
-from twistedcaldav.test.util import TestCase
-from twisted.python.modules import getModule
+from twisted.names import client
 from twisted.names.authority import BindAuthority
-from twisted.names import client
 from twisted.names.test.test_client import FakeResolver
+from twisted.python.modules import getModule
+from twisted.trial import unittest
+from twistedcaldav.stdconfig import config
+from txdav.caldav.datastore.scheduling.ischedule import utils
 
-class LookupService (TestCase):
+class LookupService (unittest.TestCase):
 
 
     def setUp(self):

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/test/util.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/test/util.py	2013-04-24 20:53:25 UTC (rev 11097)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/txdav/caldav/datastore/test/util.py	2013-04-25 16:57:58 UTC (rev 11098)
@@ -14,6 +14,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
+from twisted.trial.unittest import TestCase
+from twext.python.clsprop import classproperty
+from twisted.internet.defer import inlineCallbacks
 
 """
 Store test utility functions
@@ -23,7 +26,8 @@
 from txdav.caldav.icalendardirectoryservice import ICalendarStoreDirectoryService, \
     ICalendarStoreDirectoryRecord
 from txdav.common.datastore.test.util import TestStoreDirectoryService, \
-    TestStoreDirectoryRecord, theStoreBuilder
+    TestStoreDirectoryRecord, theStoreBuilder, CommonCommonTests, \
+    populateCalendarsFrom
 from zope.interface.declarations import implements
 
 class TestCalendarStoreDirectoryService(TestStoreDirectoryService):
@@ -181,3 +185,50 @@
     if directoryService is None:
         directoryService = buildDirectory(homes=homes)
     return theStoreBuilder.buildStore(testCase, notifierFactory, directoryService)
+
+
+
+class CommonStoreTests(CommonCommonTests, TestCase):
+
+    @inlineCallbacks
+    def setUp(self):
+        yield super(CommonStoreTests, self).setUp()
+        self._sqlCalendarStore = yield buildCalendarStore(self, self.notifierFactory)
+        yield self.populate()
+
+
+    @inlineCallbacks
+    def populate(self):
+        yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
+        self.notifierFactory.reset()
+
+
+    @classproperty(cache=False)
+    def requirements(cls): #@NoSelf
+        return {
+        "user01": {
+            "calendar_1": {
+            },
+            "inbox": {
+            },
+        },
+        "user02": {
+            "calendar_1": {
+            },
+            "inbox": {
+            },
+        },
+        "user03": {
+            "calendar_1": {
+            },
+            "inbox": {
+            },
+        },
+    }
+
+
+    def storeUnderTest(self):
+        """
+        Create and return a L{CalendarStore} for testing.
+        """
+        return self._sqlCalendarStore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130425/d666747c/attachment-0001.html>


More information about the calendarserver-changes mailing list