[CalendarServer-changes] [4813] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 30 19:56:26 PST 2009


Revision: 4813
          http://trac.macosforge.org/projects/calendarserver/changeset/4813
Author:   glyph at apple.com
Date:     2009-11-30 19:56:23 -0800 (Mon, 30 Nov 2009)
Log Message:
-----------
Include maximum value in `max-attendees-per-instance` elements created during validation as per the spec; also, use the existing `MaxAttendeesPerInstance` CalDAV XML class to represent it rather than a string-tuple.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/method/put_common.py

Added Paths:
-----------
    CalendarServer/trunk/twistedcaldav/test/test_validation.py

Modified: CalendarServer/trunk/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/put_common.py	2009-12-01 02:03:00 UTC (rev 4812)
+++ CalendarServer/trunk/twistedcaldav/method/put_common.py	2009-12-01 03:56:23 UTC (rev 4813)
@@ -1,3 +1,4 @@
+# -*- test-case-name: twistedcaldav.test.test_validation -*-
 ##
 # Copyright (c) 2005-2009 Apple Inc. All rights reserved.
 #
@@ -48,7 +49,7 @@
 from twistedcaldav.config import config
 from twistedcaldav.caldavxml import NoUIDConflict, ScheduleTag
 from twistedcaldav.caldavxml import NumberOfRecurrencesWithinLimits
-from twistedcaldav.caldavxml import caldav_namespace
+from twistedcaldav.caldavxml import caldav_namespace, MaxAttendeesPerInstance
 from twistedcaldav.customxml import calendarserver_namespace ,\
     TwistedCalendarHasPrivateCommentsProperty, TwistedSchedulingObjectResource,\
     TwistedScheduleMatchETags
@@ -339,7 +340,12 @@
                 result, message = self.validAttendeeListSizeCheck()
                 if not result:
                     log.err(message)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "max-attendees-per-instance")))
+                    raise HTTPError(
+                        ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            MaxAttendeesPerInstance.fromString(str(config.MaxAttendeesPerInstance))
+                        )
+                    )
 
                 # Normalize the calendar user addresses once we know we have valid
                 # calendar data

Added: CalendarServer/trunk/twistedcaldav/test/test_validation.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_validation.py	                        (rev 0)
+++ CalendarServer/trunk/twistedcaldav/test/test_validation.py	2009-12-01 03:56:23 UTC (rev 4813)
@@ -0,0 +1,105 @@
+##
+# Copyright (c) 2009 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from xml.etree.cElementTree import XML
+
+from twisted.internet.defer import inlineCallbacks
+from twisted.trial.unittest import TestCase
+
+# XXX this should be public, but it isn't, since it's in a test_* module.  Need
+# to address this to use system twisted.
+from twisted.web2.test.test_server import SimpleRequest
+from twisted.web2.http import HTTPError
+
+from twistedcaldav.static import CalDAVFile
+from twistedcaldav.config import config
+from twistedcaldav.ical import Component, Property
+from twistedcaldav.method.put_common import StoreCalendarObjectResource
+from twistedcaldav.caldavxml import MaxAttendeesPerInstance
+
+class TestCopyMoveValidation(TestCase):
+    """
+    Tests for the validation code in L{twistedcaldav.method.put_common}.
+    """
+
+    def setUp(self):
+        """
+        Set up some CalDAV stuff.
+        """
+        self.destination = CalDAVFile(self.mktemp())
+        self.destinationParent = CalDAVFile(self.mktemp())
+        self.sampleCalendar = Component.fromString("""
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20071114T000000Z
+ORGANIZER:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+RRULE:FREQ=YEARLY
+END:VEVENT
+END:VCALENDAR
+""")
+        req = SimpleRequest(None, "COPY", "http://example.com/foo/bar")
+        self.storer = StoreCalendarObjectResource(
+            req,
+            destination=self.destination,
+            destinationparent=self.destinationParent,
+            destination_uri="http://example.com/foo/baz",
+            calendar=self.sampleCalendar
+        )
+
+
+    @inlineCallbacks
+    def test_simpleValidRequest(self):
+        """
+        For a simple valid request,
+        L{StoreCalendarObjectResource.fullValidation} results in a L{Deferred}
+        which fires with C{None} (and raises no exception).
+        """
+        self.assertEquals((yield self.storer.fullValidation()), None)
+
+
+    @inlineCallbacks
+    def test_exceedMaximumAttendees(self):
+        """
+        If too many attendees are specified (more than the configured maximum
+        for the server), the storer raises an exception containing a
+        L{MaxAttendeesPerInstance} element that reports the maximum value, as
+        per U{RFC4791 section 5.2.9
+        <http://www.webdav.org/specs/rfc4791.html#max-attendees-per-instance>}.
+        """
+
+        # Get the event, and add too many attendees to it.
+        eventComponent = list(self.sampleCalendar.subcomponents())[0]
+        for x in xrange(config.MaxAttendeesPerInstance):
+            eventComponent.addProperty(
+                Property(u"ATTENDEE", u"mailto:user%d at example.com" % (x+3,)))
+
+        try:
+            yield self.storer.fullValidation()
+        except HTTPError, err:
+            element = XML(err.response.stream.mem)[0]
+            self.assertEquals(
+                element.tag,
+                "{%s}%s" % (
+                    MaxAttendeesPerInstance.namespace,
+                    MaxAttendeesPerInstance.name
+                )
+            )
+            self.assertEquals(int(element.text), config.MaxAttendeesPerInstance)
+        else:
+            self.fail("No error; validation should have failed!")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091130/6491d8b5/attachment.html>


More information about the calendarserver-changes mailing list