[CalendarServer-changes] [5036] CalendarServer/trunk/txcaldav/calendarstore
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 3 11:37:31 PST 2010
Revision: 5036
http://trac.macosforge.org/projects/calendarserver/changeset/5036
Author: wsanchez at apple.com
Date: 2010-02-03 11:37:28 -0800 (Wed, 03 Feb 2010)
Log Message:
-----------
More file store
Modified Paths:
--------------
CalendarServer/trunk/txcaldav/calendarstore/file.py
CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py
Modified: CalendarServer/trunk/txcaldav/calendarstore/file.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/file.py 2010-02-03 18:43:21 UTC (rev 5035)
+++ CalendarServer/trunk/txcaldav/calendarstore/file.py 2010-02-03 19:37:28 UTC (rev 5036)
@@ -33,7 +33,7 @@
from twext.log import LoggingMixIn
from twext.python.icalendar import Component as iComponent
-from twext.python.icalendar import Component as InvalidICalendarDataError
+from twext.python.icalendar import InvalidICalendarDataError
from txdav.propertystore.xattr import PropertyStore
@@ -44,6 +44,7 @@
from txcaldav.icalendarstore import NotFoundError
from txcaldav.icalendarstore import NoSuchCalendarError
from txcaldav.icalendarstore import NoSuchCalendarObjectError
+from txcaldav.icalendarstore import InvalidCalendarComponentError
from txcaldav.icalendarstore import InternalDataStoreError
@@ -221,8 +222,14 @@
return self.path.basename()
def setComponent(self, component):
- # FIXME: validate the component
+ if not isinstance(component, iComponent):
+ raise TypeError(iComponent)
+ try:
+ component.validateForCalDAV()
+ except InvalidICalendarDataError, e:
+ raise InvalidCalendarComponentError(e)
+
fh = self.path.open("w")
try:
fh.write(str(component))
Modified: CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py 2010-02-03 18:43:21 UTC (rev 5035)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py 2010-02-03 19:37:28 UTC (rev 5036)
@@ -29,8 +29,11 @@
from txcaldav.icalendarstore import ICalendarHome, ICalendar, ICalendarObject
from txcaldav.icalendarstore import CalendarNameNotAllowedError
+from txcaldav.icalendarstore import CalendarObjectNameNotAllowedError
from txcaldav.icalendarstore import CalendarAlreadyExistsError
+from txcaldav.icalendarstore import CalendarObjectNameAlreadyExistsError
from txcaldav.icalendarstore import NoSuchCalendarError
+from txcaldav.icalendarstore import InvalidCalendarComponentError
from txcaldav.calendarstore.file import CalendarStore, CalendarHome
from txcaldav.calendarstore.file import Calendar, CalendarObject
@@ -49,7 +52,7 @@
"3.ics",
)
-newEvent1_text = (
+event4_text = (
"BEGIN:VCALENDAR\r\n"
"VERSION:2.0\r\n"
"PRODID:-//Apple Inc.//iCal 4.0.1//EN\r\n"
@@ -73,7 +76,7 @@
"END:VTIMEZONE\r\n"
"BEGIN:VEVENT\r\n"
"CREATED:20100203T013849Z\r\n"
- "UID:new-1\r\n"
+ "UID:4\r\n"
"DTEND;TZID=US/Pacific:20100207T173000\r\n"
"TRANSP:OPAQUE\r\n"
"SUMMARY:New Event\r\n"
@@ -90,7 +93,33 @@
"END:VCALENDAR\r\n"
)
+event1conflict_text = event4_text.replace("\r\nUID:4\r\n", "\r\nUID:1\r\n")
+notFitForCalDAVEvent_text = (
+ "BEGIN:VCALENDAR\r\n"
+ "VERSION:2.0\r\n"
+ "PRODID:-//Apple Inc.//iCal 4.0.1//EN\r\n"
+ "CALSCALE:GREGORIAN\r\n"
+ "BEGIN:VEVENT\r\n"
+ "CREATED:20100203T013849Z\r\n"
+ "UID:4\r\n"
+ "DTEND;TZID=US/Pacific:20100207T173000\r\n" # TZID without VTIMEZONE
+ "TRANSP:OPAQUE\r\n"
+ "SUMMARY:New Event\r\n"
+ "DTSTART;TZID=US/Pacific:20100207T170000\r\n"
+ "DTSTAMP:20100203T013909Z\r\n"
+ "SEQUENCE:3\r\n"
+ "BEGIN:VALARM\r\n"
+ "X-WR-ALARMUID:1377CCC7-F85C-4610-8583-9513D4B364E1\r\n"
+ "TRIGGER:-PT20M\r\n"
+ "ATTACH;VALUE=URI:Basso\r\n"
+ "ACTION:AUDIO\r\n"
+ "END:VALARM\r\n"
+ "END:VEVENT\r\n"
+ "END:VCALENDAR\r\n"
+)
+
+
class PropertiesTestMixin(object):
def test_properties(self):
properties = self.home1.properties()
@@ -395,19 +424,37 @@
self.home1.path.child(name).touch()
self.assertEquals(self.calendar1.calendarObjectWithName(name), None)
- def test_calendarObjectWithUID(self):
- raise NotImplementedError()
- test_calendarObjectWithUID.todo = "Unimplemented"
+ def test_calendarObjectWithUID_exists(self):
+ """
+ Find existing calendar object by name.
+ """
+ calendarObject = self.calendar1.calendarObjectWithUID("1")
+ self.failUnless(
+ isinstance(calendarObject, CalendarObject),
+ calendarObject
+ )
+ self.assertEquals(
+ calendarObject.component(),
+ self.calendar1.calendarObjectWithName("1.ics").component()
+ )
+ test_calendarObjectWithUID_exists.todo = "Unimplemented"
+ def test_calendarObjectWithUID_absent(self):
+ """
+ Missing calendar object.
+ """
+ self.assertEquals(self.calendar1.calendarObjectWithUID("xyzzy"), None)
+ test_calendarObjectWithUID_absent.todo = "Unimplemented"
+
def test_createCalendarObjectWithName_absent(self):
"""
Create a new calendar object.
"""
- name = "new1.ics"
+ name = "4.ics"
assert self.calendar1.calendarObjectWithName(name) is None
- component = iComponent.fromString(newEvent1_text)
+ component = iComponent.fromString(event4_text)
self.calendar1.createCalendarObjectWithName(name, component)
calendarObject = self.calendar1.calendarObjectWithName(name)
@@ -417,8 +464,11 @@
"""
Attempt to create an existing calendar object should raise.
"""
- raise NotImplementedError()
- test_createCalendarObjectWithName_exists.todo = "Unimplemented"
+ self.assertRaises(
+ CalendarObjectNameAlreadyExistsError,
+ self.calendar1.createCalendarObjectWithName,
+ "1.ics", iComponent.fromString(event4_text)
+ )
def test_createCalendarObjectWithName_dot(self):
"""
@@ -426,7 +476,11 @@
implementation, so no calendar object names may start with
".".
"""
- raise NotImplementedError()
+ self.assertRaises(
+ CalendarObjectNameNotAllowedError,
+ self.calendar1.createCalendarObjectWithName,
+ ".foo", iComponent.fromString(event4_text)
+ )
test_createCalendarObjectWithName_dot.todo = "Unimplemented"
def test_createCalendarObjectWithName_uidconflict(self):
@@ -442,8 +496,11 @@
Attempt to create a calendar object with a invalid iCalendar text
should raise.
"""
- raise NotImplementedError()
- test_createCalendarObjectWithName_invalid.todo = "Unimplemented"
+ self.assertRaises(
+ InvalidCalendarComponentError,
+ self.calendar1.createCalendarObjectWithName,
+ "new", iComponent.fromString(notFitForCalDAVEvent_text)
+ )
def test_removeCalendarObjectWithName_exists(self):
"""
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100203/dcf5e32c/attachment.html>
More information about the calendarserver-changes
mailing list