[CalendarServer-changes] [14572] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 11 21:19:46 PDT 2015
Revision: 14572
http://trac.calendarserver.org//changeset/14572
Author: sagen at apple.com
Date: 2015-03-11 21:19:45 -0700 (Wed, 11 Mar 2015)
Log Message:
-----------
Add a test for emptying the trash
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/trash.py
CalendarServer/trunk/txdav/common/datastore/test/test_trash.py
Modified: CalendarServer/trunk/calendarserver/tools/trash.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/trash.py 2015-03-12 02:51:01 UTC (rev 14571)
+++ CalendarServer/trunk/calendarserver/tools/trash.py 2015-03-12 04:19:45 UTC (rev 14572)
@@ -254,11 +254,12 @@
@inlineCallbacks
-def emptyTrashForPrincipal(service, store, principalUID, days):
+def emptyTrashForPrincipal(service, store, principalUID, days, txn=None, verbose=True):
directory = store.directoryService()
record = yield directory.recordWithUID(principalUID)
if record is None:
- print("No record found for:", principalUID)
+ if verbose:
+ print("No record found for:", principalUID)
returnValue(None)
@@ -266,17 +267,20 @@
def doIt(txn):
home = yield txn.calendarHomeWithUID(principalUID)
if home is None:
- print("No home for principal")
+ if verbose:
+ print("No home for principal")
returnValue(None)
trash = yield home.getTrash()
if trash is None:
- print("No trash available")
+ if verbose:
+ print("No trash available")
returnValue(None)
untrashedCollections = yield home.children(onlyInTrash=False)
if len(untrashedCollections) == 0:
- print("No untrashed collections for:", prettyRecord(record))
+ if verbose:
+ print("No untrashed collections for:", prettyRecord(record))
returnValue(None)
endTime = datetime.datetime.utcnow() - datetime.timedelta(days=-days)
@@ -288,20 +292,25 @@
if len(children) == 0:
continue
- print("Collection = \"{}\"".format(displayName.encode("utf-8")))
+ if verbose:
+ print("Collection = \"{}\"".format(displayName.encode("utf-8")))
for child in children:
component = yield child.component()
summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
whenTrashed = yield child.whenTrashed()
- print(
- " \"{}\", trashed = {}, id = {}".format(
- summary.encode("utf-8"), whenTrashed, child._resourceID
+ if verbose:
+ print(
+ " \"{}\", trashed = {}, id = {}".format(
+ summary.encode("utf-8"), whenTrashed, child._resourceID
+ )
)
- )
- print("Removing...")
+ print("Removing...")
yield child.reallyRemove()
- yield store.inTransaction(label="Empty trash", operation=doIt)
+ if txn is None:
+ yield store.inTransaction(label="Empty trash", operation=doIt)
+ else:
+ yield doIt(txn)
Modified: CalendarServer/trunk/txdav/common/datastore/test/test_trash.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_trash.py 2015-03-12 02:51:01 UTC (rev 14571)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_trash.py 2015-03-12 04:19:45 UTC (rev 14572)
@@ -18,6 +18,7 @@
Trash-specific tests for L{txdav.common.datastore.sql}.
"""
+from calendarserver.tools.trash import emptyTrashForPrincipal
from pycalendar.datetime import DateTime
from twext.enterprise.jobqueue import JobItem
from twisted.internet import reactor
@@ -27,7 +28,6 @@
from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE
-
class TrashTests(StoreTestCase):
@@ -1891,3 +1891,63 @@
self.assertEquals(len(names), 1)
yield txn.commit()
+
+
+ @inlineCallbacks
+ def test_tool_emptyTrashForPrincipal(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:5CE3B280-DBC9-4E8E-B0B2-996754020E5F
+DTSTART;TZID=America/Los_Angeles:20141108T093000
+DTEND;TZID=America/Los_Angeles:20141108T103000
+CREATED:20141106T192546Z
+DTSTAMP:20141106T192546Z
+RRULE:FREQ=DAILY
+SEQUENCE:0
+SUMMARY:repeating event
+TRANSP:OPAQUE
+END:VEVENT
+BEGIN:VEVENT
+UID:5CE3B280-DBC9-4E8E-B0B2-996754020E5F
+RECURRENCE-ID;TZID=America/Los_Angeles:20141111T093000
+DTSTART;TZID=America/Los_Angeles:20141111T110000
+DTEND;TZID=America/Los_Angeles:20141111T120000
+CREATED:20141106T192546Z
+DTSTAMP:20141106T192546Z
+SEQUENCE:0
+SUMMARY:repeating event
+TRANSP:OPAQUE
+END:VEVENT
+END:VCALENDAR
+"""
+
+ txn = self.store.newTransaction()
+ calendar = yield self._collectionForUser(txn, "user01", "calendar")
+
+ yield calendar.createObjectResourceWithName(
+ "test.ics",
+ Component.allFromString(data1)
+ )
+ yield txn.commit()
+
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user01", "calendar", "test.ics")
+ yield resource.remove()
+ home = yield self._homeForUser(txn, "user01")
+ trash = yield home.getTrash()
+ trashName = trash.name()
+ yield txn.commit()
+
+ txn = self.store.newTransaction()
+ names = yield self._getResourceNames(txn, "user01", trashName)
+ self.assertEquals(len(names), 1)
+ yield emptyTrashForPrincipal(None, self.store, "user01", 0, txn=txn, verbose=False)
+ names = yield self._getResourceNames(txn, "user01", trashName)
+ self.assertEquals(len(names), 0)
+ yield txn.commit()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150311/1f6d012a/attachment.html>
More information about the calendarserver-changes
mailing list