Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Another go around on fixing trash unicode encoding issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrusdaboo committed Dec 22, 2016
1 parent d181df7 commit f25b49b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
4 changes: 2 additions & 2 deletions txdav/common/datastore/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2919,7 +2919,7 @@ def getTrashContents(self):
for child in children:
component = yield child.component()
summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
detail["children"].append(summary.encode("utf-8"))
detail["children"].append(summary)
result["trashedcollections"].append(detail)

untrashedCollections = yield self.children(onlyInTrash=False)
Expand Down Expand Up @@ -3601,7 +3601,7 @@ def fromTrash(
if verbose:
component = yield child.component()
summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
print("Recovering \"{}\"".format(summary.encode("utf-8")))
print("Recovering \"{}\"".format(summary))

try:
yield child.fromTrash()
Expand Down
85 changes: 84 additions & 1 deletion txdav/common/datastore/test/test_trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
Trash-specific tests for L{txdav.common.datastore.sql}.
"""

from calendarserver.tools.trash import emptyTrashForPrincipal
from calendarserver.tools.trash import emptyTrashForPrincipal,\
restoreTrashedEvent, restoreTrashedCollection
from pycalendar.datetime import DateTime
from twext.enterprise.jobs.jobitem import JobItem
from twisted.internet import reactor
Expand Down Expand Up @@ -2356,3 +2357,85 @@ def test_emptyTrashNonAscii(self):
result = yield txn.execSQL("select * from calendar_object", [])
self.assertEquals(len(result), 0)
yield txn.commit()

@inlineCallbacks
def test_recoverTrashNonAscii(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 évent
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
"""

txn = self.store.newTransaction()
calendar = yield self._collectionForUser(txn, "user01", "tést-calendar", create=True)
calendar.properties()[PropertyName.fromElement(element.DisplayName)] = element.DisplayName.fromString("tést-calendar-name")

yield calendar.createObjectResourceWithName(
"tést-resource.ics",
Component.allFromString(data1)
)
yield txn.commit()

txn = self.store.newTransaction()
resource = yield self._getResource(txn, "user01", "tést-calendar", "tést-resource.ics")
trashed_id = resource.id()
yield resource.remove()
names = yield self._getResourceNames(txn, "user01", "tést-calendar")
self.assertEquals(len(names), 0)
names = yield self._getTrashNames(txn, "user01")
self.assertEquals(len(names), 1)
yield txn.commit()

txn = self.store.newTransaction()
yield restoreTrashedEvent(None, self.store, "user01", trashed_id)
yield txn.commit()

txn = self.store.newTransaction()
names = yield self._getResourceNames(txn, "user01", "tést-calendar")
self.assertEquals(len(names), 1)
names = yield self._getTrashNames(txn, "user01")
self.assertEquals(len(names), 0)
yield txn.commit()

# This time remove the containing calendar
txn = self.store.newTransaction()
calendar = yield self._collectionForUser(txn, "user01", "tést-calendar")
trashed_id = calendar.id()
yield calendar.remove()
home = yield self._homeForUser(txn, "user01")
trashedCollections = yield home.children(onlyInTrash=True)
self.assertEquals(len(trashedCollections), 1)
yield txn.commit()

txn = self.store.newTransaction()
home = yield self._homeForUser(txn, "user01")
contents = yield home.getTrashContents()
self.assertEqual(len(contents["trashedcollections"]), 1)
yield txn.commit()

txn = self.store.newTransaction()
yield restoreTrashedCollection(None, self.store, "user01", trashed_id)
yield txn.commit()

txn = self.store.newTransaction()
home = yield self._homeForUser(txn, "user01")
trashedCollections = yield home.children(onlyInTrash=True)
self.assertEquals(len(trashedCollections), 0)
collections = yield home.children(onlyInTrash=False)
self.assertTrue(trashed_id in map(lambda x: x.id(), collections))
yield txn.commit()

0 comments on commit f25b49b

Please sign in to comment.