[CalendarServer-changes] [6274] CalendarServer/trunk/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Sep 10 13:10:17 PDT 2010
Revision: 6274
http://trac.macosforge.org/projects/calendarserver/changeset/6274
Author: glyph at apple.com
Date: 2010-09-10 13:10:16 -0700 (Fri, 10 Sep 2010)
Log Message:
-----------
factor out calendar-population-from-requirements logic so it can be used in other tests (and fix file store so it can be used with the file store)
Modified Paths:
--------------
CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
CalendarServer/trunk/txdav/common/datastore/file.py
CalendarServer/trunk/txdav/common/datastore/test/util.py
Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py 2010-09-10 20:03:37 UTC (rev 6273)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py 2010-09-10 20:10:16 UTC (rev 6274)
@@ -24,8 +24,7 @@
from txdav.caldav.datastore.test.common import CommonTests as CalendarCommonTests
from txdav.common.datastore.sql import ECALENDARTYPE
-from txdav.common.datastore.test.util import buildStore
-from txdav.common.icommondatastore import NoSuchHomeChildError
+from txdav.common.datastore.test.util import buildStore, populateCalendarsFrom
from twisted.trial import unittest
from twisted.internet.defer import inlineCallbacks
@@ -52,29 +51,7 @@
def populate(self):
- populateTxn = self.storeUnderTest().newTransaction()
- for homeUID in self.requirements:
- calendars = self.requirements[homeUID]
- if calendars is not None:
- home = populateTxn.calendarHomeWithUID(homeUID, True)
- # We don't want the default calendar or inbox to appear unless it's
- # explicitly listed.
- try:
- home.removeCalendarWithName("calendar")
- home.removeCalendarWithName("inbox")
- except NoSuchHomeChildError:
- pass
- for calendarName in calendars:
- calendarObjNames = calendars[calendarName]
- if calendarObjNames is not None:
- home.createCalendarWithName(calendarName)
- calendar = home.calendarWithName(calendarName)
- for objectName in calendarObjNames:
- objData = calendarObjNames[objectName]
- calendar.createCalendarObjectWithName(
- objectName, VComponent.fromString(objData)
- )
- populateTxn.commit()
+ populateCalendarsFrom(self.requirements, self.storeUnderTest())
self.notifierFactory.reset()
Modified: CalendarServer/trunk/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/file.py 2010-09-10 20:03:37 UTC (rev 6273)
+++ CalendarServer/trunk/txdav/common/datastore/file.py 2010-09-10 20:10:16 UTC (rev 6274)
@@ -470,6 +470,7 @@
raise NoSuchHomeChildError(name)
def do(transaction=self._transaction):
+ childPath = self._path.child(name)
for i in xrange(1000):
trash = childPath.sibling("._del_%s_%d" % (childPath.basename(), i))
if not trash.exists():
Modified: CalendarServer/trunk/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/util.py 2010-09-10 20:03:37 UTC (rev 6273)
+++ CalendarServer/trunk/txdav/common/datastore/test/util.py 2010-09-10 20:10:16 UTC (rev 6274)
@@ -22,6 +22,7 @@
import gc
from twext.python.filepath import CachingFilePath
+from twext.python.vcomponent import VComponent
from twisted.internet import reactor
from twisted.internet.defer import Deferred, succeed
@@ -31,7 +32,9 @@
from txdav.common.datastore.sql import CommonDataStore, v1_schema
from txdav.base.datastore.subpostgres import PostgresService,\
DiagnosticConnectionWrapper
+from txdav.common.icommondatastore import NoSuchHomeChildError
+
def allInstancesOf(cls):
for o in gc.get_referrers(cls):
if isinstance(o, cls):
@@ -141,3 +144,38 @@
theStoreBuilder = SQLStoreBuilder()
buildStore = theStoreBuilder.buildStore
+
+
+def populateCalendarsFrom(requirements, store):
+ """
+ Populate C{store} from C{requirements}.
+
+ @param requirements: a dictionary of the format described by
+ L{txdav.caldav.datastore.test.common.CommonTests.requirements}.
+
+ @param store: the L{IDataStore} to populate with calendar data.
+ """
+ populateTxn = store.newTransaction()
+ for homeUID in requirements:
+ calendars = requirements[homeUID]
+ if calendars is not None:
+ home = populateTxn.calendarHomeWithUID(homeUID, True)
+ # We don't want the default calendar or inbox to appear unless it's
+ # explicitly listed.
+ try:
+ home.removeCalendarWithName("calendar")
+ home.removeCalendarWithName("inbox")
+ except NoSuchHomeChildError:
+ pass
+ for calendarName in calendars:
+ calendarObjNames = calendars[calendarName]
+ if calendarObjNames is not None:
+ home.createCalendarWithName(calendarName)
+ calendar = home.calendarWithName(calendarName)
+ for objectName in calendarObjNames:
+ objData = calendarObjNames[objectName]
+ calendar.createCalendarObjectWithName(
+ objectName, VComponent.fromString(objData)
+ )
+ populateTxn.commit()
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100910/de4405e1/attachment.html>
More information about the calendarserver-changes
mailing list