<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14530] CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14530">14530</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2015-03-09 10:01:19 -0700 (Mon, 09 Mar 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Adds a test for sharee removing an event</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagentrashcan5txdavcommondatastoretesttest_sqlpy">CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_sql.py</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagentrashcan5txdavcommondatastoretesttest_trashpy">CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_trash.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagentrashcan5txdavcommondatastoretesttest_sqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_sql.py (14529 => 14530)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_sql.py        2015-03-09 16:00:57 UTC (rev 14529)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_sql.py        2015-03-09 17:01:19 UTC (rev 14530)
</span><span class="lines">@@ -20,17 +20,12 @@
</span><span class="cx">
</span><span class="cx"> from uuid import UUID
</span><span class="cx">
</span><del>-from pycalendar.datetime import DateTime
</del><span class="cx"> from twext.enterprise.dal.syntax import Insert
</span><span class="cx"> from twext.enterprise.dal.syntax import Select
</span><del>-from twext.enterprise.jobqueue import JobItem
-from twisted.internet import reactor
</del><span class="cx"> from twisted.internet.defer import Deferred
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</span><span class="cx"> from twisted.internet.task import Clock
</span><span class="cx"> from twisted.trial.unittest import TestCase
</span><del>-from twistedcaldav.ical import Component
-from twistedcaldav.test.util import StoreTestCase
</del><span class="cx"> # from twistedcaldav.vcard import Component as VCard
</span><span class="cx"> from txdav.common.datastore.sql import (
</span><span class="cx"> log, CommonStoreTransactionMonitor,
</span><span class="lines">@@ -512,1825 +507,3 @@
</span><span class="cx"> def abort(self):
</span><span class="cx"> self.action = "aborted"
</span><span class="cx"> return succeed(None)
</span><del>-
-
-
-class CommonTrashTests(StoreTestCase):
-
- def _homeForUser(self, txn, userName):
- return txn.calendarHomeWithUID(userName, create=True)
-
- @inlineCallbacks
- def _collectionForUser(self, txn, userName, collectionName, create=False, onlyInTrash=False):
- home = yield txn.calendarHomeWithUID(userName, create=True)
- collection = yield home.childWithName(collectionName, onlyInTrash=onlyInTrash)
- if collection is None:
- if create:
- collection = yield home.createCalendarWithName(collectionName)
- returnValue(collection)
-
-
- @inlineCallbacks
- def _createResource(self, txn, userName, collectionName, resourceName, data):
- collection = yield self._collectionForUser(txn, userName, collectionName)
- resource = yield collection.createObjectResourceWithName(
- resourceName, Component.allFromString(data)
- )
- returnValue(resource)
-
-
- @inlineCallbacks
- def _getResource(self, txn, userName, collectionName, resourceName):
- collection = yield self._collectionForUser(txn, userName, collectionName)
- if not resourceName:
- # Get the first one
- resourceNames = yield collection.listObjectResources()
- if len(resourceNames) == 0:
- returnValue(None)
- resourceName = resourceNames[0]
- resource = yield collection.calendarObjectWithName(resourceName)
- returnValue(resource)
-
-
- @inlineCallbacks
- def _getResourceNames(self, txn, userName, collectionName):
- collection = yield self._collectionForUser(txn, userName, collectionName)
- resourceNames = yield collection.listObjectResources()
- returnValue(resourceNames)
-
-
- @inlineCallbacks
- def _updateResource(self, txn, userName, collectionName, resourceName, data):
- resource = yield self._getResource(txn, userName, collectionName, resourceName)
- yield resource.setComponent(Component.fromString(data))
- returnValue(resource)
-
-
- @inlineCallbacks
- def _getResourceData(self, txn, userName, collectionName, resourceName):
- resource = yield self._getResource(txn, userName, collectionName, resourceName)
- if resource is None:
- returnValue(None)
- component = yield resource.component()
- returnValue(str(component).replace("\r\n ", ""))
-
-
- @inlineCallbacks
- def test_trashUnscheduled(self):
- """
- Verify the "resource is entirely in the trash" flag
- """
-
- 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()
-
- #
- # First, use a calendar object
- #
-
- home = yield txn.calendarHomeWithUID("user01", create=True)
- collection = yield home.childWithName("calendar")
- trash = yield home.childWithName("trash")
-
- # No objects
- objects = yield collection.listObjectResources()
- self.assertEquals(len(objects), 0)
-
- # Create an object
- resource = yield collection.createObjectResourceWithName(
- "test.ics",
- Component.allFromString(data1)
- )
-
- # One object in collection
- objects = yield collection.listObjectResources()
- self.assertEquals(len(objects), 1)
-
- # No objects in trash
- objects = yield trash.listObjectResources()
- self.assertEquals(len(objects), 0)
-
- # Verify it's not in the trash
- self.assertFalse((yield resource.isInTrash()))
- trashed = yield resource.whenTrashed()
- self.assertTrue(trashed is None)
-
- # Move object to trash
- newName = yield resource.toTrash()
-
- yield txn.commit()
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- # Verify it's in the trash
- resource = yield self._getResource(txn, "user01", "trash", newName)
- self.assertTrue((yield resource.isInTrash()))
- trashed = yield resource.whenTrashed()
- self.assertFalse(trashed is None)
-
- # No objects in collection
- resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
- self.assertEqual(len(resourceNames), 0)
-
- # One object in trash
- resourceNames = yield self._getResourceNames(txn, "user01", "trash")
- self.assertEqual(len(resourceNames), 1)
-
- # Put back from trash
- yield resource.fromTrash()
-
- yield txn.commit()
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- # Not in trash
- resource = yield self._getResource(txn, "user01", "trash", "")
- self.assertTrue(resource is None)
-
-
- # One object in collection
- resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
- self.assertEqual(len(resourceNames), 1)
- resource = yield self._getResource(txn, "user01", "calendar", newName)
- self.assertFalse((yield resource.isInTrash()))
- trashed = yield resource.whenTrashed()
- self.assertTrue(trashed is None)
-
- # No objects in trash
- resourceNames = yield self._getResourceNames(txn, "user01", "trash")
- self.assertEqual(len(resourceNames), 0)
-
- yield txn.commit()
-
-
- # Not implemented
-# #
-# # Now with addressbook
-# #
-
-# data2 = """BEGIN:VCARD
-# VERSION:3.0
-# PRODID:-//Apple Inc.//iOS 6.0//EN
-# UID:41425f1b-b831-40f2-b0bb-e70ec0938afd
-# FN:Test User
-# N:User;Test;;;
-# REV:20120613T002007Z
-# TEL;type=CELL;type=VOICE;type=pref:(408) 555-1212
-# END:VCARD
-# """
-
-# print("ADDRESSBOOK TIME")
-
-# home = yield txn.addressbookHomeWithUID("user01", create=True)
-# collection = yield home.childWithName("addressbook")
-# trash = yield home.childWithName("trash")
-
-# # Create an object
-# resource = yield collection.createObjectResourceWithName(
-# "test.vcf",
-# VCard.fromString(data2)
-# )
-
-# # One object
-# objects = yield collection.listObjectResources()
-# self.assertEquals(len(objects), 1)
-
-# # Verify it's not in the trash
-# self.assertFalse((yield resource.isInTrash()))
-
-# # Move object to trash
-# yield resource.toTrash()
-
-# # Verify it's in the trash
-# self.assertTrue((yield resource.isInTrash()))
-
-# # No objects
-# objects = yield collection.listObjectResources()
-# self.assertEquals(len(objects), 0)
-
-# # One object in trash
-# objects = yield trash.listObjectResources()
-# print("OBJECT LIST", objects)
-# self.assertEquals(len(objects), 1)
-
-# # Put back from trash
-# print("FETCHING FROM TRASH USING", objects[0])
-# resource = yield self._getResource(txn, "user01", "trash", objects[0])
-# yield resource.fromTrash()
-
-# # Not in trash
-# self.assertFalse((yield resource.isInTrash()))
-
-# # One object
-# objects = yield collection.listObjectResources()
-# self.assertEquals(len(objects), 1)
-
-# yield txn.commit()
-
-
-
-
- @inlineCallbacks
- def test_trashScheduledFullyInFuture(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- # A month in the future
- start = DateTime.getNowUTC()
- start.setHHMMSS(0, 0, 0)
- start.offsetMonth(1)
- end = DateTime.getNowUTC()
- end.setHHMMSS(1, 0, 0)
- end.offsetMonth(1)
- subs = {
- "start": start,
- "end": end,
- }
-
- data1 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data2 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- # user01 invites user02
- txn = self.store.newTransaction()
- yield self._createResource(
- txn, "user01", "calendar", "test.ics", data1
- )
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy has SCHEDULE-STATUS update
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=1.2" in data)
-
- # user02 has an inbox item
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user02 accepts
- yield self._updateResource(txn, "user02", "calendar", "", data2)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 has an inbox item
- txn = self.store.newTransaction()
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user01's copy has SCHEDULE-STATUS update
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=2.0" in data)
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user01 trashes event
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user01", "calendar", "test.ics")
- yield resource.remove()
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy is in the trash, still with user02 accepted
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user01", "trash", "")
- self.assertTrue((yield resource.isInTrash()))
- trashed = yield resource.whenTrashed()
- self.assertFalse(trashed is None)
- data = yield self._getResourceData(txn, "user01", "trash", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
- yield txn.commit()
-
- # user02's copy is cancelled
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user02", "inbox", "")
- self.assertTrue("METHOD:CANCEL" in data)
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("STATUS:CANCELLED" in data)
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
- data = yield self._getResource(txn, "user02", "trash", "")
- self.assertEquals(data, None)
- yield txn.commit()
-
- # user01 restores event from the trash
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user01", "trash", "")
- data = yield self._getResourceData(txn, "user01", "trash", "")
- yield resource.fromTrash()
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- # user01's copy should be back on their calendar
- resource = yield self._getResource(txn, "user01", "calendar", "")
- self.assertFalse((yield resource.isInTrash()))
- trashed = yield resource.whenTrashed()
- self.assertTrue(trashed is None)
- data = yield self._getResourceData(txn, "user01", "calendar", "")
- self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
-
- # user02's copy should be back on their calendar
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
-
- yield txn.commit()
-
-
-
- @inlineCallbacks
- def test_trashScheduledFullyInFutureAttendeeTrashedThenOrganizerChanged(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- # A month in the future
- start = DateTime.getNowUTC()
- start.setHHMMSS(0, 0, 0)
- start.offsetMonth(1)
- end = DateTime.getNowUTC()
- end.setHHMMSS(1, 0, 0)
- end.offsetMonth(1)
- subs = {
- "start": start,
- "end": end,
- }
-
- data1 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data2 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
-
- start.offsetHours(1)
- end.offsetHours(1)
-
- data3 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=DECLINED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data4 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:CHANGED!
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=DECLINED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
-
- # user01 invites user02
- txn = self.store.newTransaction()
- yield self._createResource(
- txn, "user01", "calendar", "test.ics", data1
- )
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy has SCHEDULE-STATUS update
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=1.2" in data)
-
- # user02 has an inbox item
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user02 accepts
- yield self._updateResource(txn, "user02", "calendar", "", data2)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 has an inbox item
- txn = self.store.newTransaction()
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user01's copy has SCHEDULE-STATUS update
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=2.0" in data)
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user02 trashes event
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
-
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's calendar copy shows user02 declined
- txn = self.store.newTransaction()
-
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=DECLINED" in data)
-
- # user01's inbox copy also shows user02 declined
- data = yield self._getResourceData(txn, "user01", "inbox", "")
- self.assertTrue("PARTSTAT=DECLINED" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
-
- # user02's copy is in the trash only, and still has ACCEPTED
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "trash", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- # result = yield txn.execSQL("select * from calendar_object", [])
- # for row in result:
- # print("calendar object ROW", row)
-
- # result = yield txn.execSQL("select * from calendar_metadata", [])
- # for row in result:
- # print("calendar ROW", row)
-
-
- yield txn.commit()
-
- # user01 makes a change to event while user02's copy is in the trash
- txn = self.store.newTransaction()
-
- yield self._updateResource(txn, "user01", "calendar", "test.ics", data3)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
-
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user02 trashes event again
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
-
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's calendar copy shows user02 declined
- txn = self.store.newTransaction()
-
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=DECLINED" in data)
-
- # user01's inbox copy also shows user02 declined
- data = yield self._getResourceData(txn, "user01", "inbox", "")
- self.assertTrue("PARTSTAT=DECLINED" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 makes a SUMMARY change to event while user02's copy is in the trash
- txn = self.store.newTransaction()
-
- yield self._updateResource(txn, "user01", "calendar", "test.ics", data4)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
-
- txn = self.store.newTransaction()
-
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- yield txn.commit()
-
-
- @inlineCallbacks
- def test_trashScheduledFullyInFutureAttendeeRemovedThenOrganizerChanged(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- # A month in the future
- start = DateTime.getNowUTC()
- start.setHHMMSS(0, 0, 0)
- start.offsetMonth(1)
- end = DateTime.getNowUTC()
- end.setHHMMSS(1, 0, 0)
- end.offsetMonth(1)
- subs = {
- "start": start,
- "end": end,
- }
-
- data1 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data2 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
-
- data3 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:CHANGED!
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=DECLINED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
-
- start.offsetHours(1)
- end.offsetHours(1)
-
- data4 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:CHANGED!
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=DECLINED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
-
- # user01 invites user02
- txn = self.store.newTransaction()
- yield self._createResource(
- txn, "user01", "calendar", "test.ics", data1
- )
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy has SCHEDULE-STATUS update
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=1.2" in data)
-
- # user02 has an inbox item
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user02 accepts
- yield self._updateResource(txn, "user02", "calendar", "", data2)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 has an inbox item
- txn = self.store.newTransaction()
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user01's copy has SCHEDULE-STATUS update
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=2.0" in data)
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user02 trashes event
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
-
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's calendar copy shows user02 declined
- txn = self.store.newTransaction()
-
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=DECLINED" in data)
-
- # user01's inbox copy also shows user02 declined
- data = yield self._getResourceData(txn, "user01", "inbox", "")
- self.assertTrue("PARTSTAT=DECLINED" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user02's copy is in the trash only, and still has ACCEPTED
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "trash", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
- yield txn.commit()
-
-
- # user02 removes the event completely from the trash
-
- txn = self.store.newTransaction()
-
- resource = yield self._getResource(txn, "user02", "trash", "")
- yield resource.reallyRemove()
-
- yield txn.commit()
-
-
- # user01 makes a SUMMARY change to event (user02 does not get notified because they are fully declined)
- txn = self.store.newTransaction()
-
- yield self._updateResource(txn, "user01", "calendar", "test.ics", data3)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- yield txn.commit()
-
- # user01 makes a time change to event (user02 gets notified)
- txn = self.store.newTransaction()
-
- yield self._updateResource(txn, "user01", "calendar", "test.ics", data4)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
-
- yield txn.commit()
-
-
-
- @inlineCallbacks
- def test_trashScheduledFullyInFutureAttendeeTrashedThenPutBack(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- # A month in the future
- start = DateTime.getNowUTC()
- start.setHHMMSS(0, 0, 0)
- start.offsetMonth(1)
- end = DateTime.getNowUTC()
- end.setHHMMSS(1, 0, 0)
- end.offsetMonth(1)
- subs = {
- "start": start,
- "end": end,
- }
-
- data1 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data2 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
-
- # user01 invites user02
- txn = self.store.newTransaction()
- yield self._createResource(
- txn, "user01", "calendar", "test.ics", data1
- )
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy has SCHEDULE-STATUS update
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=1.2" in data)
-
- # user02 has an inbox item
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user02 accepts
- yield self._updateResource(txn, "user02", "calendar", "", data2)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 has an inbox item
- txn = self.store.newTransaction()
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user01's copy has SCHEDULE-STATUS update
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=2.0" in data)
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user02 trashes event
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
-
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's calendar copy shows user02 declined
- txn = self.store.newTransaction()
-
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=DECLINED" in data)
-
- # user01's inbox copy also shows user02 declined
- data = yield self._getResourceData(txn, "user01", "inbox", "")
- self.assertTrue("PARTSTAT=DECLINED" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # result = yield txn.execSQL("select * from calendar_object", [])
- # for row in result:
- # print("ROW", row)
-
- # user02's copy is in the trash only, and still has ACCEPTED
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "trash", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- yield txn.commit()
-
- # user02 moves it from trash
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "trash", "")
- yield resource.fromTrash()
- yield txn.commit()
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's calendar copy shows user02 accepted
- txn = self.store.newTransaction()
-
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- # user01's inbox copy also shows user02 accepted
- data = yield self._getResourceData(txn, "user01", "inbox", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user02 has nothing in trash
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- yield txn.commit()
-
-
-
- @inlineCallbacks
- def test_trashScheduledFullyInPast(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- # A month in the past
- start = DateTime.getNowUTC()
- start.setHHMMSS(0, 0, 0)
- start.offsetMonth(-1)
- end = DateTime.getNowUTC()
- end.setHHMMSS(1, 0, 0)
- end.offsetMonth(-1)
- subs = {
- "start": start,
- "end": end,
- }
-
- data1 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data2 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=TENTATIVE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- # user01 invites user02
- txn = self.store.newTransaction()
- yield self._createResource(
- txn, "user01", "calendar", "test.ics", data1
- )
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy has SCHEDULE-STATUS update
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=1.2" in data)
-
- # user02 has an inbox item
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user02 accepts
- yield self._updateResource(txn, "user02", "calendar", "", data2)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 has an inbox item
- txn = self.store.newTransaction()
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user01's copy has SCHEDULE-STATUS update
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=2.0" in data)
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user01 trashes event
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user01", "calendar", "test.ics")
- yield resource.remove()
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy is in the trash, still with user02 partstat
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "trash", "")
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
- yield txn.commit()
-
- # user02's copy is cancelled
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user02", "inbox", "")
- self.assertTrue("METHOD:CANCEL" in data)
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("STATUS:CANCELLED" in data)
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
- data = yield self._getResource(txn, "user02", "trash", "")
- self.assertEquals(data, None)
- yield txn.commit()
-
- # user01 restores event from the trash
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user01", "trash", "")
- data = yield self._getResourceData(txn, "user01", "trash", "")
- yield resource.fromTrash()
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- # user01's copy should be back on their calendar
- data = yield self._getResourceData(txn, "user01", "calendar", "")
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
-
- # user02's copy should be back on their calendar
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
-
-
- yield txn.commit()
-
-
- @inlineCallbacks
- def test_trashScheduledFullyInPastAttendeeTrashedThenPutBack(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- # A month in the past
- start = DateTime.getNowUTC()
- start.setHHMMSS(0, 0, 0)
- start.offsetMonth(-1)
- end = DateTime.getNowUTC()
- end.setHHMMSS(1, 0, 0)
- end.offsetMonth(-1)
- subs = {
- "start": start,
- "end": end,
- }
-
- data1 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data2 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=TENTATIVE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- # user01 invites user02
- txn = self.store.newTransaction()
- yield self._createResource(
- txn, "user01", "calendar", "test.ics", data1
- )
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy has SCHEDULE-STATUS update
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=1.2" in data)
-
- # user02 has an inbox item
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user02 accepts
- yield self._updateResource(txn, "user02", "calendar", "", data2)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 has an inbox item
- txn = self.store.newTransaction()
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user01's copy has SCHEDULE-STATUS update
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=2.0" in data)
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
-
- # clear the inbox items
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user02 trashes event
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's calendar copy shows user02 declined
- txn = self.store.newTransaction()
-
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=DECLINED" in data)
-
- # user01's inbox copy also shows user02 declined
- data = yield self._getResourceData(txn, "user01", "inbox", "")
- self.assertTrue("PARTSTAT=DECLINED" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user02's copy is in the trash only, and still has TENTATIVE
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "trash", "")
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
-
- yield txn.commit()
-
- # user02 moves it from trash
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "trash", "")
- yield resource.fromTrash()
- yield txn.commit()
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's calendar copy shows user02 tentative again
- txn = self.store.newTransaction()
-
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
-
- # user01's inbox copy also shows user02 tentative
- data = yield self._getResourceData(txn, "user01", "inbox", "")
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user02 has nothing in trash
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("PARTSTAT=TENTATIVE" in data)
-
- yield txn.commit()
-
-
-
- @inlineCallbacks
- def test_trashScheduledSpanningNow(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- # A month in the past
- start = DateTime.getNowUTC()
- start.setHHMMSS(0, 0, 0)
- start.offsetMonth(-1)
- end = DateTime.getNowUTC()
- end.setHHMMSS(1, 0, 0)
- end.offsetMonth(-1)
- subs = {
- "start": start,
- "end": end,
- }
-
- data1 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-RRULE:FREQ=WEEKLY;COUNT=20
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data2 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-RRULE:FREQ=WEEKLY;COUNT=20
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- # user01 invites user02
- txn = self.store.newTransaction()
- yield self._createResource(
- txn, "user01", "calendar", "test.ics", data1
- )
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy has SCHEDULE-STATUS update
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=1.2" in data)
-
- # user02 has an inbox item
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user02 accepts
- yield self._updateResource(txn, "user02", "calendar", "", data2)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 has an inbox item
- txn = self.store.newTransaction()
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user01's copy has SCHEDULE-STATUS update
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=2.0" in data)
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user01 trashes event
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user01", "calendar", "test.ics")
- yield resource.remove()
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy is in the trash, still with user02 accepted
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "trash", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
- yield txn.commit()
-
- # user02's copy is cancelled
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user02", "inbox", "")
- self.assertTrue("METHOD:CANCEL" in data)
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("STATUS:CANCELLED" in data)
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
- data = yield self._getResource(txn, "user02", "trash", "")
- self.assertEquals(data, None)
- yield txn.commit()
-
- # user01 restores event from the trash
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user01", "trash", "")
- trashedName = yield resource.fromTrash()
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- # user01's trash should be empty
- resourceNames = yield self._getResourceNames(txn, "user01", "trash")
- self.assertEquals(len(resourceNames), 0)
-
- # user01 should have two .ics
- resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
- self.assertEquals(len(resourceNames), 2)
- self.assertTrue(trashedName in resourceNames)
- resourceNames.remove(trashedName)
- newName = resourceNames[0]
-
- # user01's test.ics -- verify it got split correctly, by making sure
- # it's got a count other than 20 now
- data = yield self._getResourceData(txn, "user01", "calendar", trashedName)
- self.assertTrue("COUNT=" in data)
- self.assertFalse("COUNT=20" in data)
-
- # user01's new .ics -- verify it got split correctly
- data = yield self._getResourceData(txn, "user01", "calendar", newName)
- self.assertTrue("RRULE:FREQ=WEEKLY;UNTIL=" in data)
-
- # user02's copy should be back on their calendar, and not in trash
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEquals(len(resourceNames), 1)
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEquals(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
-
- yield txn.commit()
-
-
- @inlineCallbacks
- def test_trashScheduledSpanningNowAttendeeTrashedThenPutBack(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- # A month in the past
- start = DateTime.getNowUTC()
- start.setHHMMSS(0, 0, 0)
- start.offsetMonth(-1)
- end = DateTime.getNowUTC()
- end.setHHMMSS(1, 0, 0)
- end.offsetMonth(-1)
- subs = {
- "start": start,
- "end": end,
- }
-
- data1 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-RRULE:FREQ=WEEKLY;COUNT=20
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- data2 = """BEGIN:VCALENDAR
-VERSION:2.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-BEGIN:VEVENT
-UID:12345-67890-attendee-reply
-DTSTART;TZID=America/Los_Angeles:%(start)s
-DTEND;TZID=America/Los_Angeles:%(end)s
-DTSTAMP:20150204T192546Z
-RRULE:FREQ=WEEKLY;COUNT=20
-SUMMARY:Scheduled
-ORGANIZER;CN="User 01":mailto:user01@example.com
-ATTENDEE:mailto:user01@example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
-END:VEVENT
-END:VCALENDAR
-""" % subs
-
- # user01 invites user02
- txn = self.store.newTransaction()
- yield self._createResource(
- txn, "user01", "calendar", "test.ics", data1
- )
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy has SCHEDULE-STATUS update
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=1.2" in data)
-
- # user02 has an inbox item
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user02 accepts
- yield self._updateResource(txn, "user02", "calendar", "", data2)
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01 has an inbox item
- txn = self.store.newTransaction()
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
-
- # user01's copy has SCHEDULE-STATUS update
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("SCHEDULE-STATUS=2.0" in data)
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
- resource = yield self._getResource(txn, "user02", "inbox", "")
- yield resource.remove()
-
- yield txn.commit()
-
- # user02 trashes event
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "calendar", "")
- yield resource.remove()
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's copy shows user02 declined
- txn = self.store.newTransaction()
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=DECLINED" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
- self.assertEqual(len(resourceNames), 1)
- resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
- self.assertEqual(len(resourceNames), 1)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user02's copy is in the trash only, and still has ACCEPTED
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "trash", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- yield txn.commit()
- # user02 moves it from trash
- txn = self.store.newTransaction()
- resource = yield self._getResource(txn, "user02", "trash", "")
- yield resource.fromTrash()
- yield txn.commit()
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- # user01's calendar copy shows user02 accepted
- txn = self.store.newTransaction()
-
- data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- # user01's inbox copy also shows user02 accepted
- data = yield self._getResourceData(txn, "user01", "inbox", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
- resource = yield self._getResource(txn, "user01", "inbox", "")
- yield resource.remove()
-
- # user02 has nothing in trash
- resourceNames = yield self._getResourceNames(txn, "user02", "trash")
- self.assertEqual(len(resourceNames), 0)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
- self.assertEqual(len(resourceNames), 1)
-
- resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
- self.assertEqual(len(resourceNames), 0)
-
- data = yield self._getResourceData(txn, "user02", "calendar", "")
- self.assertTrue("PARTSTAT=ACCEPTED" in data)
-
- yield txn.commit()
-
-
- @inlineCallbacks
- def test_trashCalendar(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- txn = self.store.newTransaction()
-
- collection = yield self._collectionForUser(txn, "user01", "test", create=True)
- isInTrash = collection.isInTrash()
- self.assertFalse(isInTrash)
- whenTrashed = collection.whenTrashed()
- self.assertEquals(whenTrashed, None)
-
- home = yield self._homeForUser(txn, "user01")
- names = yield home.listChildren()
- self.assertTrue("test" in names)
- names = yield home.listChildren(onlyInTrash=True)
- self.assertFalse("test" in names)
-
- yield collection.remove()
- isInTrash = collection.isInTrash()
- self.assertTrue(isInTrash)
- whenTrashed = collection.whenTrashed()
- self.assertNotEquals(whenTrashed, None)
-
- collection = yield self._collectionForUser(txn, "user01", "test")
- self.assertEquals(collection, None)
-
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
-
- collection = yield self._collectionForUser(txn, "user01", "test")
- self.assertEquals(collection, None)
- home = yield self._homeForUser(txn, "user01")
- names = yield home.listChildren(onlyInTrash=True)
- trashedName = names[0]
- collection = yield self._collectionForUser(txn, "user01", trashedName, onlyInTrash=True)
- self.assertNotEquals(collection, None)
- home = yield self._homeForUser(txn, "user01")
- names = yield home.listChildren()
- self.assertFalse("test" in names)
- names = yield home.listChildren(onlyInTrash=True)
- self.assertTrue(trashedName in names)
-
- yield collection.fromTrash()
-
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
- home = yield self._homeForUser(txn, "user01")
- names = yield home.listChildren()
- self.assertTrue(trashedName in names)
- names = yield home.listChildren(onlyInTrash=True)
- self.assertFalse("test" in names)
- yield txn.commit()
-
-
- @inlineCallbacks
- def test_trashCalendarWithUnscheduled(self):
-
- from twistedcaldav.stdconfig import config
- self.patch(config, "EnableTrashCollection", True)
-
- txn = self.store.newTransaction()
-
- collection = yield self._collectionForUser(txn, "user01", "test", create=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
-"""
-
- # Create an object
- resource = yield collection.createObjectResourceWithName(
- "test.ics",
- Component.allFromString(data1)
- )
-
- # One object in collection
- objects = yield collection.listObjectResources()
- self.assertEquals(len(objects), 1)
-
- # No objects in trash
- trash = yield self._collectionForUser(txn, "user01", "trash")
- objects = yield trash.listObjectResources()
- self.assertEquals(len(objects), 0)
-
- # Verify it's not in the trash
- self.assertFalse((yield resource.isInTrash()))
- trashed = yield resource.whenTrashed()
- self.assertTrue(trashed is None)
-
- collection = yield self._collectionForUser(txn, "user01", "test")
- resources = yield trash.trashForCollection(collection._resourceID)
- self.assertEquals(len(resources), 0)
-
- yield txn.commit()
-
- txn = self.store.newTransaction()
- collection = yield self._collectionForUser(txn, "user01", "test")
- yield collection.remove()
- yield txn.commit()
-
- txn = self.store.newTransaction()
- # One object in trash
- trash = yield self._collectionForUser(txn, "user01", "trash")
- objects = yield trash.listObjectResources()
- self.assertEquals(len(objects), 1)
-
- resources = yield trash.trashForCollection(collection._resourceID)
- self.assertEquals(len(resources), 1)
-
- home = yield self._homeForUser(txn, "user01")
- names = yield home.listChildren(onlyInTrash=True)
- trashedName = names[0]
- collection = yield self._collectionForUser(txn, "user01", trashedName, onlyInTrash=True)
- yield collection.fromTrash()
-
- yield txn.commit()
-
- yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
-
- txn = self.store.newTransaction()
- home = yield self._homeForUser(txn, "user01")
- names = yield home.listChildren()
- self.assertTrue(trashedName in names)
- names = yield home.listChildren(onlyInTrash=True)
- self.assertFalse(trashedName in names)
- resourceNames = yield self._getResourceNames(txn, "user01", trashedName)
- self.assertEqual(len(resourceNames), 1)
-
- yield txn.commit()
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagentrashcan5txdavcommondatastoretesttest_trashpy"></a>
<div class="addfile"><h4>Added: CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_trash.py (0 => 14530)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_trash.py         (rev 0)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_trash.py        2015-03-09 17:01:19 UTC (rev 14530)
</span><span class="lines">@@ -0,0 +1,1856 @@
</span><ins>+##
+# Copyright (c) 2015 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Trash-specific tests for L{txdav.common.datastore.sql}.
+"""
+
+from pycalendar.datetime import DateTime
+from twext.enterprise.jobqueue import JobItem
+from twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twistedcaldav.ical import Component
+from twistedcaldav.test.util import StoreTestCase
+from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE
+
+
+
+class TrashTests(StoreTestCase):
+
+
+ def _homeForUser(self, txn, userName):
+ return txn.calendarHomeWithUID(userName, create=True)
+
+ @inlineCallbacks
+ def _collectionForUser(self, txn, userName, collectionName, create=False, onlyInTrash=False):
+ home = yield txn.calendarHomeWithUID(userName, create=True)
+ collection = yield home.childWithName(collectionName, onlyInTrash=onlyInTrash)
+ if collection is None:
+ if create:
+ collection = yield home.createCalendarWithName(collectionName)
+ returnValue(collection)
+
+
+ @inlineCallbacks
+ def _createResource(self, txn, userName, collectionName, resourceName, data):
+ collection = yield self._collectionForUser(txn, userName, collectionName)
+ resource = yield collection.createObjectResourceWithName(
+ resourceName, Component.allFromString(data)
+ )
+ returnValue(resource)
+
+
+ @inlineCallbacks
+ def _getResource(self, txn, userName, collectionName, resourceName):
+ collection = yield self._collectionForUser(txn, userName, collectionName)
+ if not resourceName:
+ # Get the first one
+ resourceNames = yield collection.listObjectResources()
+ if len(resourceNames) == 0:
+ returnValue(None)
+ resourceName = resourceNames[0]
+ resource = yield collection.calendarObjectWithName(resourceName)
+ returnValue(resource)
+
+
+ @inlineCallbacks
+ def _getResourceNames(self, txn, userName, collectionName):
+ collection = yield self._collectionForUser(txn, userName, collectionName)
+ resourceNames = yield collection.listObjectResources()
+ returnValue(resourceNames)
+
+
+ @inlineCallbacks
+ def _updateResource(self, txn, userName, collectionName, resourceName, data):
+ resource = yield self._getResource(txn, userName, collectionName, resourceName)
+ yield resource.setComponent(Component.fromString(data))
+ returnValue(resource)
+
+
+ @inlineCallbacks
+ def _getResourceData(self, txn, userName, collectionName, resourceName):
+ resource = yield self._getResource(txn, userName, collectionName, resourceName)
+ if resource is None:
+ returnValue(None)
+ component = yield resource.component()
+ returnValue(str(component).replace("\r\n ", ""))
+
+
+ @inlineCallbacks
+ def test_trashUnscheduled(self):
+ """
+ Verify the "resource is entirely in the trash" flag
+ """
+
+ 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()
+
+ #
+ # First, use a calendar object
+ #
+
+ home = yield txn.calendarHomeWithUID("user01", create=True)
+ collection = yield home.childWithName("calendar")
+ trash = yield home.childWithName("trash")
+
+ # No objects
+ objects = yield collection.listObjectResources()
+ self.assertEquals(len(objects), 0)
+
+ # Create an object
+ resource = yield collection.createObjectResourceWithName(
+ "test.ics",
+ Component.allFromString(data1)
+ )
+
+ # One object in collection
+ objects = yield collection.listObjectResources()
+ self.assertEquals(len(objects), 1)
+
+ # No objects in trash
+ objects = yield trash.listObjectResources()
+ self.assertEquals(len(objects), 0)
+
+ # Verify it's not in the trash
+ self.assertFalse((yield resource.isInTrash()))
+ trashed = yield resource.whenTrashed()
+ self.assertTrue(trashed is None)
+
+ # Move object to trash
+ newName = yield resource.toTrash()
+
+ yield txn.commit()
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ # Verify it's in the trash
+ resource = yield self._getResource(txn, "user01", "trash", newName)
+ self.assertTrue((yield resource.isInTrash()))
+ trashed = yield resource.whenTrashed()
+ self.assertFalse(trashed is None)
+
+ # No objects in collection
+ resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
+ self.assertEqual(len(resourceNames), 0)
+
+ # One object in trash
+ resourceNames = yield self._getResourceNames(txn, "user01", "trash")
+ self.assertEqual(len(resourceNames), 1)
+
+ # Put back from trash
+ yield resource.fromTrash()
+
+ yield txn.commit()
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ # Not in trash
+ resource = yield self._getResource(txn, "user01", "trash", "")
+ self.assertTrue(resource is None)
+
+
+ # One object in collection
+ resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
+ self.assertEqual(len(resourceNames), 1)
+ resource = yield self._getResource(txn, "user01", "calendar", newName)
+ self.assertFalse((yield resource.isInTrash()))
+ trashed = yield resource.whenTrashed()
+ self.assertTrue(trashed is None)
+
+ # No objects in trash
+ resourceNames = yield self._getResourceNames(txn, "user01", "trash")
+ self.assertEqual(len(resourceNames), 0)
+
+ yield txn.commit()
+
+
+
+ @inlineCallbacks
+ def test_trashScheduledFullyInFuture(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ # A month in the future
+ start = DateTime.getNowUTC()
+ start.setHHMMSS(0, 0, 0)
+ start.offsetMonth(1)
+ end = DateTime.getNowUTC()
+ end.setHHMMSS(1, 0, 0)
+ end.offsetMonth(1)
+ subs = {
+ "start": start,
+ "end": end,
+ }
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ # user01 invites user02
+ txn = self.store.newTransaction()
+ yield self._createResource(
+ txn, "user01", "calendar", "test.ics", data1
+ )
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy has SCHEDULE-STATUS update
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=1.2" in data)
+
+ # user02 has an inbox item
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user02 accepts
+ yield self._updateResource(txn, "user02", "calendar", "", data2)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 has an inbox item
+ txn = self.store.newTransaction()
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user01's copy has SCHEDULE-STATUS update
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=2.0" in data)
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user01 trashes event
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user01", "calendar", "test.ics")
+ yield resource.remove()
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy is in the trash, still with user02 accepted
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user01", "trash", "")
+ self.assertTrue((yield resource.isInTrash()))
+ trashed = yield resource.whenTrashed()
+ self.assertFalse(trashed is None)
+ data = yield self._getResourceData(txn, "user01", "trash", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+ yield txn.commit()
+
+ # user02's copy is cancelled
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user02", "inbox", "")
+ self.assertTrue("METHOD:CANCEL" in data)
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("STATUS:CANCELLED" in data)
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+ data = yield self._getResource(txn, "user02", "trash", "")
+ self.assertEquals(data, None)
+ yield txn.commit()
+
+ # user01 restores event from the trash
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user01", "trash", "")
+ data = yield self._getResourceData(txn, "user01", "trash", "")
+ yield resource.fromTrash()
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ # user01's copy should be back on their calendar
+ resource = yield self._getResource(txn, "user01", "calendar", "")
+ self.assertFalse((yield resource.isInTrash()))
+ trashed = yield resource.whenTrashed()
+ self.assertTrue(trashed is None)
+ data = yield self._getResourceData(txn, "user01", "calendar", "")
+ self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
+
+ # user02's copy should be back on their calendar
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
+
+ yield txn.commit()
+
+
+
+ @inlineCallbacks
+ def test_trashScheduledFullyInFutureAttendeeTrashedThenOrganizerChanged(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ # A month in the future
+ start = DateTime.getNowUTC()
+ start.setHHMMSS(0, 0, 0)
+ start.offsetMonth(1)
+ end = DateTime.getNowUTC()
+ end.setHHMMSS(1, 0, 0)
+ end.offsetMonth(1)
+ subs = {
+ "start": start,
+ "end": end,
+ }
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+
+ start.offsetHours(1)
+ end.offsetHours(1)
+
+ data3 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data4 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:CHANGED!
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+
+ # user01 invites user02
+ txn = self.store.newTransaction()
+ yield self._createResource(
+ txn, "user01", "calendar", "test.ics", data1
+ )
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy has SCHEDULE-STATUS update
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=1.2" in data)
+
+ # user02 has an inbox item
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user02 accepts
+ yield self._updateResource(txn, "user02", "calendar", "", data2)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 has an inbox item
+ txn = self.store.newTransaction()
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user01's copy has SCHEDULE-STATUS update
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=2.0" in data)
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user02 trashes event
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's calendar copy shows user02 declined
+ txn = self.store.newTransaction()
+
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+
+ # user01's inbox copy also shows user02 declined
+ data = yield self._getResourceData(txn, "user01", "inbox", "")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+
+ # user02's copy is in the trash only, and still has ACCEPTED
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "trash", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ # result = yield txn.execSQL("select * from calendar_object", [])
+ # for row in result:
+ # print("calendar object ROW", row)
+
+ # result = yield txn.execSQL("select * from calendar_metadata", [])
+ # for row in result:
+ # print("calendar ROW", row)
+
+
+ yield txn.commit()
+
+ # user01 makes a change to event while user02's copy is in the trash
+ txn = self.store.newTransaction()
+
+ yield self._updateResource(txn, "user01", "calendar", "test.ics", data3)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
+
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user02 trashes event again
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's calendar copy shows user02 declined
+ txn = self.store.newTransaction()
+
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+
+ # user01's inbox copy also shows user02 declined
+ data = yield self._getResourceData(txn, "user01", "inbox", "")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 makes a SUMMARY change to event while user02's copy is in the trash
+ txn = self.store.newTransaction()
+
+ yield self._updateResource(txn, "user01", "calendar", "test.ics", data4)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+
+ txn = self.store.newTransaction()
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ yield txn.commit()
+
+
+ @inlineCallbacks
+ def test_trashScheduledFullyInFutureAttendeeRemovedThenOrganizerChanged(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ # A month in the future
+ start = DateTime.getNowUTC()
+ start.setHHMMSS(0, 0, 0)
+ start.offsetMonth(1)
+ end = DateTime.getNowUTC()
+ end.setHHMMSS(1, 0, 0)
+ end.offsetMonth(1)
+ subs = {
+ "start": start,
+ "end": end,
+ }
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+
+ data3 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:CHANGED!
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+
+ start.offsetHours(1)
+ end.offsetHours(1)
+
+ data4 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:CHANGED!
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+
+ # user01 invites user02
+ txn = self.store.newTransaction()
+ yield self._createResource(
+ txn, "user01", "calendar", "test.ics", data1
+ )
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy has SCHEDULE-STATUS update
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=1.2" in data)
+
+ # user02 has an inbox item
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user02 accepts
+ yield self._updateResource(txn, "user02", "calendar", "", data2)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 has an inbox item
+ txn = self.store.newTransaction()
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user01's copy has SCHEDULE-STATUS update
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=2.0" in data)
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user02 trashes event
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's calendar copy shows user02 declined
+ txn = self.store.newTransaction()
+
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+
+ # user01's inbox copy also shows user02 declined
+ data = yield self._getResourceData(txn, "user01", "inbox", "")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user02's copy is in the trash only, and still has ACCEPTED
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "trash", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+ yield txn.commit()
+
+
+ # user02 removes the event completely from the trash
+
+ txn = self.store.newTransaction()
+
+ resource = yield self._getResource(txn, "user02", "trash", "")
+ yield resource.reallyRemove()
+
+ yield txn.commit()
+
+
+ # user01 makes a SUMMARY change to event (user02 does not get notified because they are fully declined)
+ txn = self.store.newTransaction()
+
+ yield self._updateResource(txn, "user01", "calendar", "test.ics", data3)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ yield txn.commit()
+
+ # user01 makes a time change to event (user02 gets notified)
+ txn = self.store.newTransaction()
+
+ yield self._updateResource(txn, "user01", "calendar", "test.ics", data4)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
+
+ yield txn.commit()
+
+
+
+ @inlineCallbacks
+ def test_trashScheduledFullyInFutureAttendeeTrashedThenPutBack(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ # A month in the future
+ start = DateTime.getNowUTC()
+ start.setHHMMSS(0, 0, 0)
+ start.offsetMonth(1)
+ end = DateTime.getNowUTC()
+ end.setHHMMSS(1, 0, 0)
+ end.offsetMonth(1)
+ subs = {
+ "start": start,
+ "end": end,
+ }
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+
+ # user01 invites user02
+ txn = self.store.newTransaction()
+ yield self._createResource(
+ txn, "user01", "calendar", "test.ics", data1
+ )
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy has SCHEDULE-STATUS update
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=1.2" in data)
+
+ # user02 has an inbox item
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user02 accepts
+ yield self._updateResource(txn, "user02", "calendar", "", data2)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 has an inbox item
+ txn = self.store.newTransaction()
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user01's copy has SCHEDULE-STATUS update
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=2.0" in data)
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user02 trashes event
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's calendar copy shows user02 declined
+ txn = self.store.newTransaction()
+
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+
+ # user01's inbox copy also shows user02 declined
+ data = yield self._getResourceData(txn, "user01", "inbox", "")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # result = yield txn.execSQL("select * from calendar_object", [])
+ # for row in result:
+ # print("ROW", row)
+
+ # user02's copy is in the trash only, and still has ACCEPTED
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "trash", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ yield txn.commit()
+
+ # user02 moves it from trash
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "trash", "")
+ yield resource.fromTrash()
+ yield txn.commit()
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's calendar copy shows user02 accepted
+ txn = self.store.newTransaction()
+
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ # user01's inbox copy also shows user02 accepted
+ data = yield self._getResourceData(txn, "user01", "inbox", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user02 has nothing in trash
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ yield txn.commit()
+
+
+
+ @inlineCallbacks
+ def test_trashScheduledFullyInPast(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ # A month in the past
+ start = DateTime.getNowUTC()
+ start.setHHMMSS(0, 0, 0)
+ start.offsetMonth(-1)
+ end = DateTime.getNowUTC()
+ end.setHHMMSS(1, 0, 0)
+ end.offsetMonth(-1)
+ subs = {
+ "start": start,
+ "end": end,
+ }
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=TENTATIVE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ # user01 invites user02
+ txn = self.store.newTransaction()
+ yield self._createResource(
+ txn, "user01", "calendar", "test.ics", data1
+ )
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy has SCHEDULE-STATUS update
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=1.2" in data)
+
+ # user02 has an inbox item
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user02 accepts
+ yield self._updateResource(txn, "user02", "calendar", "", data2)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 has an inbox item
+ txn = self.store.newTransaction()
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user01's copy has SCHEDULE-STATUS update
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=2.0" in data)
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user01 trashes event
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user01", "calendar", "test.ics")
+ yield resource.remove()
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy is in the trash, still with user02 partstat
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "trash", "")
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+ yield txn.commit()
+
+ # user02's copy is cancelled
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user02", "inbox", "")
+ self.assertTrue("METHOD:CANCEL" in data)
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("STATUS:CANCELLED" in data)
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+ data = yield self._getResource(txn, "user02", "trash", "")
+ self.assertEquals(data, None)
+ yield txn.commit()
+
+ # user01 restores event from the trash
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user01", "trash", "")
+ data = yield self._getResourceData(txn, "user01", "trash", "")
+ yield resource.fromTrash()
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ # user01's copy should be back on their calendar
+ data = yield self._getResourceData(txn, "user01", "calendar", "")
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+
+ # user02's copy should be back on their calendar
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+
+
+ yield txn.commit()
+
+
+ @inlineCallbacks
+ def test_trashScheduledFullyInPastAttendeeTrashedThenPutBack(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ # A month in the past
+ start = DateTime.getNowUTC()
+ start.setHHMMSS(0, 0, 0)
+ start.offsetMonth(-1)
+ end = DateTime.getNowUTC()
+ end.setHHMMSS(1, 0, 0)
+ end.offsetMonth(-1)
+ subs = {
+ "start": start,
+ "end": end,
+ }
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=TENTATIVE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ # user01 invites user02
+ txn = self.store.newTransaction()
+ yield self._createResource(
+ txn, "user01", "calendar", "test.ics", data1
+ )
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy has SCHEDULE-STATUS update
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=1.2" in data)
+
+ # user02 has an inbox item
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user02 accepts
+ yield self._updateResource(txn, "user02", "calendar", "", data2)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 has an inbox item
+ txn = self.store.newTransaction()
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user01's copy has SCHEDULE-STATUS update
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=2.0" in data)
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+
+ # clear the inbox items
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user02 trashes event
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's calendar copy shows user02 declined
+ txn = self.store.newTransaction()
+
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+
+ # user01's inbox copy also shows user02 declined
+ data = yield self._getResourceData(txn, "user01", "inbox", "")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user02's copy is in the trash only, and still has TENTATIVE
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "trash", "")
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+
+ yield txn.commit()
+
+ # user02 moves it from trash
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "trash", "")
+ yield resource.fromTrash()
+ yield txn.commit()
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's calendar copy shows user02 tentative again
+ txn = self.store.newTransaction()
+
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+
+ # user01's inbox copy also shows user02 tentative
+ data = yield self._getResourceData(txn, "user01", "inbox", "")
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user02 has nothing in trash
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("PARTSTAT=TENTATIVE" in data)
+
+ yield txn.commit()
+
+
+
+ @inlineCallbacks
+ def test_trashScheduledSpanningNow(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ # A month in the past
+ start = DateTime.getNowUTC()
+ start.setHHMMSS(0, 0, 0)
+ start.offsetMonth(-1)
+ end = DateTime.getNowUTC()
+ end.setHHMMSS(1, 0, 0)
+ end.offsetMonth(-1)
+ subs = {
+ "start": start,
+ "end": end,
+ }
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+RRULE:FREQ=WEEKLY;COUNT=20
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+RRULE:FREQ=WEEKLY;COUNT=20
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ # user01 invites user02
+ txn = self.store.newTransaction()
+ yield self._createResource(
+ txn, "user01", "calendar", "test.ics", data1
+ )
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy has SCHEDULE-STATUS update
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=1.2" in data)
+
+ # user02 has an inbox item
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user02 accepts
+ yield self._updateResource(txn, "user02", "calendar", "", data2)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 has an inbox item
+ txn = self.store.newTransaction()
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user01's copy has SCHEDULE-STATUS update
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=2.0" in data)
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user01 trashes event
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user01", "calendar", "test.ics")
+ yield resource.remove()
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy is in the trash, still with user02 accepted
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "trash", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+ yield txn.commit()
+
+ # user02's copy is cancelled
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user02", "inbox", "")
+ self.assertTrue("METHOD:CANCEL" in data)
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("STATUS:CANCELLED" in data)
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+ data = yield self._getResource(txn, "user02", "trash", "")
+ self.assertEquals(data, None)
+ yield txn.commit()
+
+ # user01 restores event from the trash
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user01", "trash", "")
+ trashedName = yield resource.fromTrash()
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ # user01's trash should be empty
+ resourceNames = yield self._getResourceNames(txn, "user01", "trash")
+ self.assertEquals(len(resourceNames), 0)
+
+ # user01 should have two .ics
+ resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
+ self.assertEquals(len(resourceNames), 2)
+ self.assertTrue(trashedName in resourceNames)
+ resourceNames.remove(trashedName)
+ newName = resourceNames[0]
+
+ # user01's test.ics -- verify it got split correctly, by making sure
+ # it's got a count other than 20 now
+ data = yield self._getResourceData(txn, "user01", "calendar", trashedName)
+ self.assertTrue("COUNT=" in data)
+ self.assertFalse("COUNT=20" in data)
+
+ # user01's new .ics -- verify it got split correctly
+ data = yield self._getResourceData(txn, "user01", "calendar", newName)
+ self.assertTrue("RRULE:FREQ=WEEKLY;UNTIL=" in data)
+
+ # user02's copy should be back on their calendar, and not in trash
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEquals(len(resourceNames), 1)
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEquals(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
+
+ yield txn.commit()
+
+
+ @inlineCallbacks
+ def test_trashScheduledSpanningNowAttendeeTrashedThenPutBack(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ # A month in the past
+ start = DateTime.getNowUTC()
+ start.setHHMMSS(0, 0, 0)
+ start.offsetMonth(-1)
+ end = DateTime.getNowUTC()
+ end.setHHMMSS(1, 0, 0)
+ end.offsetMonth(-1)
+ subs = {
+ "start": start,
+ "end": end,
+ }
+
+ data1 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+RRULE:FREQ=WEEKLY;COUNT=20
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ data2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-attendee-reply
+DTSTART;TZID=America/Los_Angeles:%(start)s
+DTEND;TZID=America/Los_Angeles:%(end)s
+DTSTAMP:20150204T192546Z
+RRULE:FREQ=WEEKLY;COUNT=20
+SUMMARY:Scheduled
+ORGANIZER;CN="User 01":mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+""" % subs
+
+ # user01 invites user02
+ txn = self.store.newTransaction()
+ yield self._createResource(
+ txn, "user01", "calendar", "test.ics", data1
+ )
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy has SCHEDULE-STATUS update
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=1.2" in data)
+
+ # user02 has an inbox item
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user02 accepts
+ yield self._updateResource(txn, "user02", "calendar", "", data2)
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01 has an inbox item
+ txn = self.store.newTransaction()
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+
+ # user01's copy has SCHEDULE-STATUS update
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("SCHEDULE-STATUS=2.0" in data)
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+ resource = yield self._getResource(txn, "user02", "inbox", "")
+ yield resource.remove()
+
+ yield txn.commit()
+
+ # user02 trashes event
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "calendar", "")
+ yield resource.remove()
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's copy shows user02 declined
+ txn = self.store.newTransaction()
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=DECLINED" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
+ self.assertEqual(len(resourceNames), 1)
+ resourceNames = yield self._getResourceNames(txn, "user01", "inbox")
+ self.assertEqual(len(resourceNames), 1)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user02's copy is in the trash only, and still has ACCEPTED
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "trash", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ yield txn.commit()
+ # user02 moves it from trash
+ txn = self.store.newTransaction()
+ resource = yield self._getResource(txn, "user02", "trash", "")
+ yield resource.fromTrash()
+ yield txn.commit()
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ # user01's calendar copy shows user02 accepted
+ txn = self.store.newTransaction()
+
+ data = yield self._getResourceData(txn, "user01", "calendar", "test.ics")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ # user01's inbox copy also shows user02 accepted
+ data = yield self._getResourceData(txn, "user01", "inbox", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+ resource = yield self._getResource(txn, "user01", "inbox", "")
+ yield resource.remove()
+
+ # user02 has nothing in trash
+ resourceNames = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEqual(len(resourceNames), 0)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "calendar")
+ self.assertEqual(len(resourceNames), 1)
+
+ resourceNames = yield self._getResourceNames(txn, "user02", "inbox")
+ self.assertEqual(len(resourceNames), 0)
+
+ data = yield self._getResourceData(txn, "user02", "calendar", "")
+ self.assertTrue("PARTSTAT=ACCEPTED" in data)
+
+ yield txn.commit()
+
+
+ @inlineCallbacks
+ def test_trashCalendar(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ txn = self.store.newTransaction()
+
+ collection = yield self._collectionForUser(txn, "user01", "test", create=True)
+ isInTrash = collection.isInTrash()
+ self.assertFalse(isInTrash)
+ whenTrashed = collection.whenTrashed()
+ self.assertEquals(whenTrashed, None)
+
+ home = yield self._homeForUser(txn, "user01")
+ names = yield home.listChildren()
+ self.assertTrue("test" in names)
+ names = yield home.listChildren(onlyInTrash=True)
+ self.assertFalse("test" in names)
+
+ yield collection.remove()
+ isInTrash = collection.isInTrash()
+ self.assertTrue(isInTrash)
+ whenTrashed = collection.whenTrashed()
+ self.assertNotEquals(whenTrashed, None)
+
+ collection = yield self._collectionForUser(txn, "user01", "test")
+ self.assertEquals(collection, None)
+
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+
+ collection = yield self._collectionForUser(txn, "user01", "test")
+ self.assertEquals(collection, None)
+ home = yield self._homeForUser(txn, "user01")
+ names = yield home.listChildren(onlyInTrash=True)
+ trashedName = names[0]
+ collection = yield self._collectionForUser(txn, "user01", trashedName, onlyInTrash=True)
+ self.assertNotEquals(collection, None)
+ home = yield self._homeForUser(txn, "user01")
+ names = yield home.listChildren()
+ self.assertFalse("test" in names)
+ names = yield home.listChildren(onlyInTrash=True)
+ self.assertTrue(trashedName in names)
+
+ yield collection.fromTrash()
+
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+ home = yield self._homeForUser(txn, "user01")
+ names = yield home.listChildren()
+ self.assertTrue(trashedName in names)
+ names = yield home.listChildren(onlyInTrash=True)
+ self.assertFalse("test" in names)
+ yield txn.commit()
+
+
+ @inlineCallbacks
+ def test_trashCalendarWithUnscheduled(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ txn = self.store.newTransaction()
+
+ collection = yield self._collectionForUser(txn, "user01", "test", create=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
+"""
+
+ # Create an object
+ resource = yield collection.createObjectResourceWithName(
+ "test.ics",
+ Component.allFromString(data1)
+ )
+
+ # One object in collection
+ objects = yield collection.listObjectResources()
+ self.assertEquals(len(objects), 1)
+
+ # No objects in trash
+ trash = yield self._collectionForUser(txn, "user01", "trash")
+ objects = yield trash.listObjectResources()
+ self.assertEquals(len(objects), 0)
+
+ # Verify it's not in the trash
+ self.assertFalse((yield resource.isInTrash()))
+ trashed = yield resource.whenTrashed()
+ self.assertTrue(trashed is None)
+
+ collection = yield self._collectionForUser(txn, "user01", "test")
+ resources = yield trash.trashForCollection(collection._resourceID)
+ self.assertEquals(len(resources), 0)
+
+ yield txn.commit()
+
+ txn = self.store.newTransaction()
+ collection = yield self._collectionForUser(txn, "user01", "test")
+ yield collection.remove()
+ yield txn.commit()
+
+ txn = self.store.newTransaction()
+ # One object in trash
+ trash = yield self._collectionForUser(txn, "user01", "trash")
+ objects = yield trash.listObjectResources()
+ self.assertEquals(len(objects), 1)
+
+ resources = yield trash.trashForCollection(collection._resourceID)
+ self.assertEquals(len(resources), 1)
+
+ home = yield self._homeForUser(txn, "user01")
+ names = yield home.listChildren(onlyInTrash=True)
+ trashedName = names[0]
+ collection = yield self._collectionForUser(txn, "user01", trashedName, onlyInTrash=True)
+ yield collection.fromTrash()
+
+ yield txn.commit()
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ txn = self.store.newTransaction()
+ home = yield self._homeForUser(txn, "user01")
+ names = yield home.listChildren()
+ self.assertTrue(trashedName in names)
+ names = yield home.listChildren(onlyInTrash=True)
+ self.assertFalse(trashedName in names)
+ resourceNames = yield self._getResourceNames(txn, "user01", trashedName)
+ self.assertEqual(len(resourceNames), 1)
+
+ yield txn.commit()
+
+
+
+ @inlineCallbacks
+ def test_shareeDelete(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()
+ calendar1 = yield self._collectionForUser(txn, "user01", "calendar")
+
+ yield calendar1.createObjectResourceWithName(
+ "test.ics",
+ Component.allFromString(data1)
+ )
+
+ shareeView = yield calendar1.inviteUIDToShare("user02", _BIND_MODE_WRITE, "summary")
+ inviteUID = shareeView.shareUID()
+ home2 = yield self._homeForUser(txn, "user02")
+ shareeView = yield home2.acceptShare(inviteUID)
+ calendarName2 = shareeView.name()
+ yield self._collectionForUser(txn, "user02", calendarName2)
+ yield txn.commit()
+
+ txn = self.store.newTransaction()
+ resource2 = yield self._getResource(txn, "user02", calendarName2, "test.ics")
+ yield resource2.remove()
+ yield txn.commit()
+
+ txn = self.store.newTransaction()
+ names = yield self._getResourceNames(txn, "user01", "trash")
+ self.assertEquals(len(names), 1)
+ names = yield self._getResourceNames(txn, "user01", "calendar")
+ self.assertEquals(len(names), 0)
+ names = yield self._getResourceNames(txn, "user02", "trash")
+ self.assertEquals(len(names), 0)
+ names = yield self._getResourceNames(txn, "user02", calendarName2)
+ self.assertEquals(len(names), 0)
+ yield txn.commit()
</ins></span></pre>
</div>
</div>
</body>
</html>