[CalendarServer-changes] [5034] CalendarServer/trunk/txcaldav/calendarstore
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 3 10:14:50 PST 2010
Revision: 5034
http://trac.macosforge.org/projects/calendarserver/changeset/5034
Author: wsanchez at apple.com
Date: 2010-02-03 10:14:49 -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 17:49:01 UTC (rev 5033)
+++ CalendarServer/trunk/txcaldav/calendarstore/file.py 2010-02-03 18:14:49 UTC (rev 5034)
@@ -32,20 +32,18 @@
from twisted.python.filepath import FilePath
from twext.log import LoggingMixIn
-from twext.python.icalendar import Component as iComponent, InvalidICalendarDataError
+from twext.python.icalendar import Component as iComponent
+from twext.python.icalendar import Component as InvalidICalendarDataError
from txdav.propertystore.xattr import PropertyStore
from txcaldav.icalendarstore import ICalendarHome, ICalendar, ICalendarObject
-#from txcaldav.icalendarstore import CalendarStoreError
-#from txcaldav.icalendarstore import AlreadyExistsError
-#from txcaldav.icalendarstore import CalendarAlreadyExistsError
-#from txcaldav.icalendarstore import CalendarObjectNameAlreadyExistsError
-#from txcaldav.icalendarstore import CalendarObjectUIDAlreadyExistsError
+from txcaldav.icalendarstore import CalendarNameNotAllowedError
+from txcaldav.icalendarstore import CalendarAlreadyExistsError
+from txcaldav.icalendarstore import CalendarObjectNameAlreadyExistsError
from txcaldav.icalendarstore import NotFoundError
-#from txcaldav.icalendarstore import NoSuchCalendarError
+from txcaldav.icalendarstore import NoSuchCalendarError
from txcaldav.icalendarstore import NoSuchCalendarObjectError
-#from txcaldav.icalendarstore import InvalidCalendarComponentError
from txcaldav.icalendarstore import InternalDataStoreError
@@ -97,6 +95,9 @@
)
def calendarWithName(self, name):
+ if name.startswith("."):
+ return None
+
childPath = self.path.child(name)
if childPath.isdir():
return Calendar(childPath, self)
@@ -104,11 +105,30 @@
return None
def createCalendarWithName(self, name):
- raise NotImplementedError()
+ if name.startswith("."):
+ raise CalendarNameNotAllowedError(name)
+ childPath = self.path.child(name)
+
+ try:
+ childPath.createDirectory()
+ except (IOError, OSError), e:
+ if e.errno == errno.EEXIST:
+ raise CalendarAlreadyExistsError(name)
+ raise
+
def removeCalendarWithName(self, name):
- raise NotImplementedError()
+ if name.startswith("."):
+ raise NoSuchCalendarError(name)
+ childPath = self.path.child(name)
+ try:
+ childPath.remove()
+ except (IOError, OSError), e:
+ if e.errno == errno.ENOENT:
+ raise NoSuchCalendarError(name)
+ raise
+
def properties(self):
if not hasattr(self, "_properties"):
self._properties = PropertyStore(self.path)
@@ -151,8 +171,13 @@
raise NotImplementedError()
def createCalendarObjectWithName(self, name, component):
- raise NotImplementedError()
+ childPath = self.path.child(name)
+ if childPath.exists():
+ raise CalendarObjectNameAlreadyExistsError(name)
+ calendarObject = CalendarObject(childPath, self)
+ calendarObject.setComponent(component)
+
def removeCalendarObjectWithName(self, name):
raise NotImplementedError()
@@ -188,8 +213,14 @@
return self.path.basename()
def setComponent(self, component):
- raise NotImplementedError()
+ # FIXME: validate the component
+ fh = self.path.open("w")
+ try:
+ fh.write(str(component))
+ finally:
+ fh.close()
+
def component(self):
if not hasattr(self, "_component"):
text = self.iCalendarText()
Modified: CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py 2010-02-03 17:49:01 UTC (rev 5033)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/test_file.py 2010-02-03 18:14:49 UTC (rev 5034)
@@ -27,14 +27,13 @@
from txdav.idav import IPropertyStore
-from txcaldav.icalendarstore import ICalendarHome
-from txcaldav.icalendarstore import ICalendar
-from txcaldav.icalendarstore import ICalendarObject
+from txcaldav.icalendarstore import ICalendarHome, ICalendar, ICalendarObject
+from txcaldav.icalendarstore import CalendarNameNotAllowedError
+from txcaldav.icalendarstore import CalendarAlreadyExistsError
+from txcaldav.icalendarstore import NoSuchCalendarError
-from txcaldav.calendarstore.file import CalendarStore
-from txcaldav.calendarstore.file import CalendarHome
-from txcaldav.calendarstore.file import Calendar
-from txcaldav.calendarstore.file import CalendarObject
+from txcaldav.calendarstore.file import CalendarStore, CalendarHome
+from txcaldav.calendarstore.file import Calendar, CalendarObject
storePath = FilePath(__file__).parent().child("calendar_store")
@@ -50,7 +49,48 @@
"3.ics",
)
+newEvent1_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:VTIMEZONE\r\n"
+ "TZID:US/Pacific\r\n"
+ "BEGIN:DAYLIGHT\r\n"
+ "TZOFFSETFROM:-0800\r\n"
+ "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\r\n"
+ "DTSTART:20070311T020000\r\n"
+ "TZNAME:PDT\r\n"
+ "TZOFFSETTO:-0700\r\n"
+ "END:DAYLIGHT\r\n"
+ "BEGIN:STANDARD\r\n"
+ "TZOFFSETFROM:-0700\r\n"
+ "RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\r\n"
+ "DTSTART:20071104T020000\r\n"
+ "TZNAME:PST\r\n"
+ "TZOFFSETTO:-0800\r\n"
+ "END:STANDARD\r\n"
+ "END:VTIMEZONE\r\n"
+ "BEGIN:VEVENT\r\n"
+ "CREATED:20100203T013849Z\r\n"
+ "UID:new-1\r\n"
+ "DTEND;TZID=US/Pacific:20100207T173000\r\n"
+ "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()
@@ -91,12 +131,15 @@
# self.fail(e)
def test_init(self):
- assert isinstance(self.calendarStore.path, FilePath), self.calendarStore.path
+ self.failUnless(
+ isinstance(self.calendarStore.path, FilePath),
+ self.calendarStore.path
+ )
def test_calendarHomeWithUID(self):
calendarHome = self.calendarStore.calendarHomeWithUID("home1")
- assert isinstance(calendarHome, CalendarHome)
+ self.failUnless(isinstance(calendarHome, CalendarHome))
class CalendarHomeTest(unittest.TestCase, PropertiesTestMixin):
@@ -123,6 +166,9 @@
self.assertEquals(self.home1.uid(), "home1")
def test_calendars(self):
+ # Add a dot directory to make sure we don't find it
+ self.home1.path.child(".foo").createDirectory()
+
calendars = tuple(self.home1.calendars())
for calendar in calendars:
@@ -133,22 +179,62 @@
home1_calendarNames
)
- def test_calendarWithName(self):
+ def test_calendarWithName_exists(self):
for name in home1_calendarNames:
calendar = self.home1.calendarWithName(name)
self.failUnless(isinstance(calendar, Calendar), calendar)
self.assertEquals(calendar.name(), name)
+
+ def test_calendarWithName_absent(self):
self.assertEquals(self.home1.calendarWithName("xyzzy"), None)
- def test_createCalendarWithName(self):
- raise NotImplementedError()
- test_createCalendarWithName.todo = "Unimplemented"
+ def test_calendarWithName_dot(self):
+ name = ".foo"
+ self.home1.path.child(name).createDirectory()
+ self.assertEquals(self.home1.calendarWithName(name), None)
- def test_removeCalendarWithName(self):
- raise NotImplementedError()
- test_removeCalendarWithName.todo = "Unimplemented"
+ def test_createCalendarWithName_absent(self):
+ name = "new"
+ assert self.home1.calendarWithName(name) is None
+ self.home1.createCalendarWithName(name)
+ self.failUnless(self.home1.calendarWithName(name) is not None)
+ def test_createCalendarWithName_exists(self):
+ for name in home1_calendarNames:
+ self.assertRaises(
+ CalendarAlreadyExistsError,
+ self.home1.createCalendarWithName,
+ name
+ )
+ def test_createCalendarWithName_dot(self):
+ self.assertRaises(
+ CalendarNameNotAllowedError,
+ self.home1.createCalendarWithName,
+ ".foo"
+ )
+
+ def test_removeCalendarWithName_exists(self):
+ for name in home1_calendarNames:
+ self.home1.removeCalendarWithName(name)
+ self.assertEquals(self.home1.calendarWithName(name), None)
+
+ def test_removeCalendarWithName_absent(self):
+ self.assertRaises(
+ NoSuchCalendarError,
+ self.home1.removeCalendarWithName,
+ "xyzzy"
+ )
+
+ def test_removeCalendarWithName_dot(self):
+ name = ".foo"
+ self.home1.path.child(name).createDirectory()
+ self.assertRaises(
+ NoSuchCalendarError,
+ self.home1.removeCalendarWithName,
+ name
+ )
+
class CalendarTest(unittest.TestCase, PropertiesTestMixin):
def setUp(self):
setUpCalendar1(self)
@@ -180,6 +266,9 @@
)
def test_calendarObjects(self):
+ # Add a dot file to make sure we don't find it
+ self.home1.path.child(".foo").createDirectory()
+
calendarObjects = tuple(self.calendar1.calendarObjects())
for calendarObject in calendarObjects:
@@ -193,7 +282,7 @@
calendar1_objectNames
)
- def test_calendarObjectWithName(self):
+ def test_calendarObjectWithName_exists(self):
for name in calendar1_objectNames:
calendarObject = self.calendar1.calendarObjectWithName(name)
self.failUnless(
@@ -202,20 +291,58 @@
)
self.assertEquals(calendarObject.name(), name)
+ def test_calendarObjectWithName_absent(self):
self.assertEquals(self.calendar1.calendarObjectWithName("xyzzy"), None)
+ def test_calendarObjectWithName_dot(self):
+ name = ".foo.ics"
+ 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_createCalendarObjectWithName(self):
+ def test_createCalendarObjectWithName_absent(self):
+ name = "new1.ics"
+
+ assert self.calendar1.calendarObjectWithName(name) is None
+
+ component = iComponent.fromString(newEvent1_text)
+ self.calendar1.createCalendarObjectWithName(name, component)
+
+ calendarObject = self.calendar1.calendarObjectWithName(name)
+ self.assertEquals(calendarObject.component(), component)
+
+
+ def test_createCalendarObjectWithName_exists(self):
raise NotImplementedError()
- test_createCalendarObjectWithName.todo = "Unimplemented"
+ test_createCalendarObjectWithName_exists.todo = "Unimplemented"
- def test_removeCalendarComponentWithName(self):
+ def test_createCalendarObjectWithName_dot(self):
raise NotImplementedError()
- test_removeCalendarComponentWithName.todo = "Unimplemented"
+ test_createCalendarObjectWithName_dot.todo = "Unimplemented"
+ def test_createCalendarObjectWithName_uidconflict(self):
+ raise NotImplementedError()
+ test_createCalendarObjectWithName_uidconflict.todo = "Unimplemented"
+
+ def test_createCalendarObjectWithName_invalid(self):
+ raise NotImplementedError()
+ test_createCalendarObjectWithName_invalid.todo = "Unimplemented"
+
+ def test_removeCalendarComponentWithName_exists(self):
+ raise NotImplementedError()
+ test_removeCalendarComponentWithName_exists.todo = "Unimplemented"
+
+ def test_removeCalendarComponentWithName_absent(self):
+ raise NotImplementedError()
+ test_removeCalendarComponentWithName_absent.todo = "Unimplemented"
+
+ def test_removeCalendarComponentWithName_dot(self):
+ raise NotImplementedError()
+ test_removeCalendarComponentWithName_dot.todo = "Unimplemented"
+
def test_removeCalendarComponentWithUID(self):
raise NotImplementedError()
test_removeCalendarComponentWithUID.todo = "Unimplemented"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100203/237b96b4/attachment-0001.html>
More information about the calendarserver-changes
mailing list