[CalendarServer-changes] [14530] CalendarServer/branches/users/sagen/trashcan-5/txdav/common/ datastore/test
source_changes at macosforge.org
source_changes at macosforge.org
Mon Mar 9 10:01:19 PDT 2015
Revision: 14530
http://trac.calendarserver.org//changeset/14530
Author: sagen at apple.com
Date: 2015-03-09 10:01:19 -0700 (Mon, 09 Mar 2015)
Log Message:
-----------
Adds a test for sharee removing an event
Modified Paths:
--------------
CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_sql.py
Added Paths:
-----------
CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_trash.py
Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_sql.py
===================================================================
--- 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)
@@ -20,17 +20,12 @@
from uuid import UUID
-from pycalendar.datetime import DateTime
from twext.enterprise.dal.syntax import Insert
from twext.enterprise.dal.syntax import Select
-from twext.enterprise.jobqueue import JobItem
-from twisted.internet import reactor
from twisted.internet.defer import Deferred
from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from twisted.internet.task import Clock
from twisted.trial.unittest import TestCase
-from twistedcaldav.ical import Component
-from twistedcaldav.test.util import StoreTestCase
# from twistedcaldav.vcard import Component as VCard
from txdav.common.datastore.sql import (
log, CommonStoreTransactionMonitor,
@@ -512,1825 +507,3 @@
def abort(self):
self.action = "aborted"
return succeed(None)
-
-
-
-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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=DECLINED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=DECLINED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=DECLINED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=DECLINED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=TENTATIVE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=TENTATIVE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE:mailto:user02 at 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 at example.com
-ATTENDEE:mailto:user01 at example.com
-ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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()
Added: CalendarServer/branches/users/sagen/trashcan-5/txdav/common/datastore/test/test_trash.py
===================================================================
--- 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)
@@ -0,0 +1,1856 @@
+##
+# 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=TENTATIVE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=TENTATIVE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at 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 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02 at 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()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150309/f7f9c28a/attachment-0001.html>
More information about the calendarserver-changes
mailing list