[CalendarServer-changes] [6013] CalendarServer/branches/users/glyph/sql-store/twistedcaldav/test/ test_calendarquery.py
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 9 10:28:03 PDT 2010
Revision: 6013
http://trac.macosforge.org/projects/calendarserver/changeset/6013
Author: glyph at apple.com
Date: 2010-08-09 10:28:03 -0700 (Mon, 09 Aug 2010)
Log Message:
-----------
don't cheat: use PUTs instead of file copying
Modified Paths:
--------------
CalendarServer/branches/users/glyph/sql-store/twistedcaldav/test/test_calendarquery.py
Modified: CalendarServer/branches/users/glyph/sql-store/twistedcaldav/test/test_calendarquery.py
===================================================================
--- CalendarServer/branches/users/glyph/sql-store/twistedcaldav/test/test_calendarquery.py 2010-08-09 17:11:55 UTC (rev 6012)
+++ CalendarServer/branches/users/glyph/sql-store/twistedcaldav/test/test_calendarquery.py 2010-08-09 17:28:03 UTC (rev 6013)
@@ -15,23 +15,25 @@
##
import os
-import shutil
from twisted.trial.unittest import SkipTest
+
+from twext.python.filepath import CachingFilePath as FilePath
+
from twext.web2 import responsecode
from twext.web2.iweb import IResponse
from twext.web2.stream import MemoryStream
from twext.web2.dav import davxml
-from twext.web2.dav.fileop import rmdir
from twext.web2.dav.util import davXMLFromStream
from twext.web2.test.test_server import SimpleRequest
from twistedcaldav import caldavxml
from twistedcaldav import ical
-from twistedcaldav.index import db_basename
+
from twistedcaldav.query import calendarqueryfilter
from twistedcaldav.config import config
from twistedcaldav.test.util import HomeTestCase
+from twisted.internet.defer import inlineCallbacks, returnValue
class CalendarQuery (HomeTestCase):
"""
@@ -180,7 +182,8 @@
All events.
(CalDAV-access-09, section 7.6.8)
"""
- uids = [r[0] for r in (os.path.splitext(f) for f in os.listdir(self.holidays_dir)) if r[1] == ".ics"]
+ uids = [r[0] for r in (os.path.splitext(f) for f in
+ os.listdir(self.holidays_dir)) if r[1] == ".ics"]
return self.simple_event_query("/calendar_query_events/", None, uids)
@@ -288,41 +291,35 @@
return self.calendar_query(cal_uri, query, got_xml)
+ @inlineCallbacks
def calendar_query(self, calendar_uri, query, got_xml):
- calendar_path = os.path.join(self.docroot, calendar_uri[1:])
- if os.path.exists(calendar_path): rmdir(calendar_path)
+ response = yield self.send(SimpleRequest(self.site, "MKCALENDAR", calendar_uri))
+ response = IResponse(response)
- mkrequest = SimpleRequest(self.site, "MKCALENDAR", calendar_uri)
+ if response.code != responsecode.CREATED:
+ self.fail("MKCALENDAR failed: %s" % (response.code,))
- def do_report(response):
- response = IResponse(response)
+ # Add holiday events to calendar
+ for child in FilePath(self.holidays_dir).children():
+ if child.basename().split(".")[-1] != "ics":
+ continue
+ request = SimpleRequest(self.site, "PUT", calendar_uri + "/" +
+ child.basename())
+ request.stream = MemoryStream(child.getContent())
+ response = yield self.send(request)
- if response.code != responsecode.CREATED:
- self.fail("MKCALENDAR failed: %s" % (response.code,))
+ request = SimpleRequest(self.site, "REPORT", calendar_uri)
+ request.stream = MemoryStream(query.toxml())
+ response = yield self.send(request)
- # Add holiday events to calendar
- # We're cheating by simply copying the files in
- for filename in os.listdir(self.holidays_dir):
- if os.path.splitext(filename)[1] != ".ics": continue
- path = os.path.join(self.holidays_dir, filename)
- shutil.copy(path, calendar_path)
+ response = IResponse(response)
- # Delete the index because we cheated
- index_path = os.path.join(calendar_path, db_basename)
- if os.path.isfile(index_path): os.remove(index_path)
+ if response.code != responsecode.MULTI_STATUS:
+ self.fail("REPORT failed: %s" % (response.code,))
- request = SimpleRequest(self.site, "REPORT", calendar_uri)
- request.stream = MemoryStream(query.toxml())
+ returnValue(
+ (yield davXMLFromStream(response.stream).addCallback(got_xml))
+ )
- def do_test(response):
- response = IResponse(response)
- if response.code != responsecode.MULTI_STATUS:
- self.fail("REPORT failed: %s" % (response.code,))
-
- return davXMLFromStream(response.stream).addCallback(got_xml)
-
- return self.send(request, do_test)
-
- return self.send(mkrequest, do_report)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100809/0017a56a/attachment.html>
More information about the calendarserver-changes
mailing list