[CalendarServer-changes] [6144] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Aug 19 18:06:07 PDT 2010
Revision: 6144
http://trac.macosforge.org/projects/calendarserver/changeset/6144
Author: glyph at apple.com
Date: 2010-08-19 18:06:06 -0700 (Thu, 19 Aug 2010)
Log Message:
-----------
tests for notification overwrites
Modified Paths:
--------------
CalendarServer/trunk/txcaldav/calendarstore/postgres.py
CalendarServer/trunk/txcaldav/calendarstore/test/common.py
CalendarServer/trunk/txdav/common/datastore/file.py
Modified: CalendarServer/trunk/txcaldav/calendarstore/postgres.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/postgres.py 2010-08-20 01:00:01 UTC (rev 6143)
+++ CalendarServer/trunk/txcaldav/calendarstore/postgres.py 2010-08-20 01:06:06 UTC (rev 6144)
@@ -778,7 +778,8 @@
_BIND_MODE_READ: "read-only",
_BIND_MODE_WRITE: "read-write"
}[bindMode]
- principalURL = "/principals/__uids__/" + ownerUID
+ principalURL = "/principals/__uids__/%s/" % (ownerUID,)
+ print 'I am generating a principal URL that looks like this: %r from an ownerUID of this: %r' % (principalURL, ownerUID)
yield Invite(
inviteuid, userid, principalURL, common_name,
access, state, summary
@@ -814,7 +815,8 @@
}[record.state]
# principalURL is derived from a directory record's principalURL() so
# it will always contain the UID.
- principalUID = record.principalURL.split("/")[-1]
+ principalUID = record.principalURL.split("/")[-2]
+ print 'I am computing a principal UID which looks like this: %r from a principal URL that looks like this: %r' % (principalUID, record.principalURL)
shareeHome = self._txn.calendarHomeWithUID(principalUID, create=True)
rows = self._txn.execSQL(
"select RESOURCE_ID, HOME_RESOURCE_ID from INVITE where SENDER_ADDRESS = %s",
@@ -1936,9 +1938,16 @@
def writeNotificationObject(self, uid, xmltype, xmldata):
xmltypeString = xmltype.toxml()
- self._txn.execSQL(
- "insert into NOTIFICATION (NOTIFICATION_HOME_RESOURCE_ID, NOTIFICATION_UID, XML_TYPE, XML_DATA) "
- "values (%s, %s, %s, %s)", [self._resourceID, uid, xmltypeString, xmldata])
+ existing = self._txn.execSQL("select NOTIFICATION_UID from NOTIFICATION where NOTIFICATION_HOME_RESOURCE_ID = %s and NOTIFICATION_UID = %s",
+ [self._resourceID, uid])
+ if existing:
+ self._txn.execSQL(
+ "update NOTIFICATION set XML_TYPE = %s, XML_DATA = %s where NOTIFICATION_HOME_RESOURCE_ID = %s and NOTIFICATION_UID = %s",
+ [xmltypeString, xmldata, self._resourceID, uid])
+ else:
+ self._txn.execSQL(
+ "insert into NOTIFICATION (NOTIFICATION_HOME_RESOURCE_ID, NOTIFICATION_UID, XML_TYPE, XML_DATA) "
+ "values (%s, %s, %s, %s)", [self._resourceID, uid, xmltypeString, xmldata])
notificationObject = self.notificationObjectWithUID(uid)
notificationObject.properties()[PropertyName.fromElement(NotificationType)] = NotificationType(xmltype)
Modified: CalendarServer/trunk/txcaldav/calendarstore/test/common.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/test/common.py 2010-08-20 01:00:01 UTC (rev 6143)
+++ CalendarServer/trunk/txcaldav/calendarstore/test/common.py 2010-08-20 01:06:06 UTC (rev 6144)
@@ -48,7 +48,7 @@
from twext.python.vcomponent import VComponent
from twistedcaldav.notify import Notifier
-from twistedcaldav.customxml import InviteNotification
+from twistedcaldav.customxml import InviteNotification, InviteSummary
storePath = FilePath(__file__).parent().child("calendar_store")
@@ -315,7 +315,6 @@
return notificationObject
-
def test_notificationObjectProvides(self):
"""
The objects retrieved from the notification home (the object returned
@@ -325,6 +324,24 @@
self.assertProvides(INotificationObject, notificationObject)
+ def test_replaceNotification(self):
+ """
+ L{INotificationCollection.writeNotificationObject} will silently
+ overwrite the notification object.
+ """
+ notifications = self.transactionUnderTest().notificationsWithUID(
+ "home1"
+ )
+ inviteNotification = InviteNotification()
+ notifications.writeNotificationObject("abc", inviteNotification,
+ inviteNotification.toxml())
+ inviteNotification2 = InviteNotification(InviteSummary("a summary"))
+ notifications.writeNotificationObject(
+ "abc", inviteNotification, inviteNotification2.toxml())
+ abc = notifications.notificationObjectWithUID("abc")
+ self.assertEquals(abc.xmldata(), inviteNotification2.toxml())
+
+
def test_notificationObjectModified(self):
"""
The objects retrieved from the notification home have a C{modified}
Modified: CalendarServer/trunk/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/file.py 2010-08-20 01:00:01 UTC (rev 6143)
+++ CalendarServer/trunk/txdav/common/datastore/file.py 2010-08-20 01:06:06 UTC (rev 6144)
@@ -817,10 +817,9 @@
notificationObjectsSinceToken = CommonHomeChild.objectResourcesSinceToken
def notificationObjectWithUID(self, uid):
+ name = uid + ".xml"
+ return self.notificationObjectWithName(name)
- record = self.retrieveOldIndex().recordForUID(uid)
- return self.notificationObjectWithName(record.name) if record else None
-
def writeNotificationObject(self, uid, xmltype, xmldata):
name = uid + ".xml"
if name.startswith("."):
@@ -886,6 +885,8 @@
NotificationRecord(uid, rname, xmltype.name)
)
+ self._xmldata = xmldata
+
def do():
backup = None
if self._path.exists():
@@ -924,7 +925,12 @@
# manipulation methods won't work.
self._transaction.addOperation(self.properties().flush, "post-update property flush")
+
+ _xmldata = None
+
def xmldata(self):
+ if self._xmldata is not None:
+ return self._xmldata
try:
fh = self._path.open()
except IOError, e:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100819/a1a25005/attachment-0001.html>
More information about the calendarserver-changes
mailing list