[CalendarServer-changes] [13789] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jul 24 09:36:26 PDT 2014
Revision: 13789
http://trac.calendarserver.org//changeset/13789
Author: cdaboo at apple.com
Date: 2014-07-24 09:36:26 -0700 (Thu, 24 Jul 2014)
Log Message:
-----------
Fix use of inTransaction().
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/util.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/delivery.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/test_delivery.py
Modified: CalendarServer/trunk/calendarserver/tools/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/util.py 2014-07-24 16:02:02 UTC (rev 13788)
+++ CalendarServer/trunk/calendarserver/tools/util.py 2014-07-24 16:36:26 UTC (rev 13789)
@@ -215,7 +215,7 @@
def booleanArgument(arg):
- if arg in ("true", "yes", "yup", "uh-huh", "1", "t", "y"):
+ if arg in ("true", "yes", "yup", "uh-huh", "1", "t", "y"):
return True
elif arg in ("false", "no", "nope", "nuh-uh", "0", "f", "n"):
return False
@@ -312,14 +312,12 @@
os.chmod(dirpath, mode)
os.chown(dirpath, uid, gid)
except (OSError, IOError), e:
- print("Unable to change mode/owner of %s: %s"
- % (dirpath, e))
+ print("Unable to change mode/owner of %s: %s" % (dirpath, e))
print("Created directory: %s" % (dirpath,))
if not os.path.isdir(dirpath):
- raise ConfigurationError("%s is not a directory: %s"
- % (description, dirpath))
+ raise ConfigurationError("%s is not a directory: %s" % (description, dirpath))
if access and not os.access(dirpath, access):
raise ConfigurationError(
@@ -340,8 +338,10 @@
if principalID.startswith("/"):
segments = principalID.strip("/").split("/")
- if (len(segments) == 3 and
- segments[0] == "principals" and segments[1] == "__uids__"):
+ if (
+ len(segments) == 3 and
+ segments[0] == "principals" and segments[1] == "__uids__"
+ ):
uid = segments[2]
else:
raise ValueError("Can't resolve all paths yet")
@@ -396,8 +396,10 @@
if principalID.startswith("/"):
segments = principalID.strip("/").split("/")
- if (len(segments) == 3 and
- segments[0] == "principals" and segments[1] == "__uids__"):
+ if (
+ len(segments) == 3 and
+ segments[0] == "principals" and segments[1] == "__uids__"
+ ):
uid = segments[2]
else:
raise ValueError("Can't resolve all paths yet")
@@ -468,8 +470,10 @@
@inlineCallbacks
def action_removeProxyPrincipal(rootResource, directory, store, principal, proxyPrincipal, **kwargs):
try:
- removed = (yield removeProxy(rootResource, directory, store,
- principal, proxyPrincipal, **kwargs))
+ removed = (yield removeProxy(
+ rootResource, directory, store,
+ principal, proxyPrincipal, **kwargs
+ ))
if removed:
print("Removed %s as a proxy for %s" % (
prettyPrincipal(proxyPrincipal),
@@ -487,8 +491,12 @@
subPrincipal = proxySubprincipal(principal, proxyType)
if subPrincipal is None:
- raise ProxyError("Unable to edit %s proxies for %s\n" % (proxyType,
- prettyPrincipal(principal)))
+ raise ProxyError(
+ "Unable to edit %s proxies for %s\n" % (
+ proxyType,
+ prettyPrincipal(principal)
+ )
+ )
membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
@@ -507,13 +515,15 @@
proxyTypes = ["read", "write"]
proxyTypes.remove(proxyType)
- (yield action_removeProxyPrincipal(rootResource, directory, store,
- principal, proxyPrincipal, proxyTypes=proxyTypes))
+ yield action_removeProxyPrincipal(
+ rootResource, directory, store,
+ principal, proxyPrincipal, proxyTypes=proxyTypes
+ )
# Schedule work the PeerConnectionPool will pick up as overdue
def groupPollNow(txn):
return GroupCacherPollingWork.reschedule(txn, 0, force=True)
- yield store.inTransaction(groupPollNow)
+ yield store.inTransaction("addProxy groupPollNow", groupPollNow)
@@ -526,8 +536,12 @@
subPrincipal = proxySubprincipal(principal, proxyType)
if subPrincipal is None:
- raise ProxyError("Unable to edit %s proxies for %s\n" % (proxyType,
- prettyPrincipal(principal)))
+ raise ProxyError(
+ "Unable to edit %s proxies for %s\n" % (
+ proxyType,
+ prettyPrincipal(principal)
+ )
+ )
membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
@@ -549,7 +563,7 @@
# Schedule work the PeerConnectionPool will pick up as overdue
def groupPollNow(txn):
return GroupCacherPollingWork.reschedule(txn, 0, force=True)
- yield store.inTransaction(groupPollNow)
+ yield store.inTransaction("removeProxy groupPollNow", groupPollNow)
returnValue(removed)
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/delivery.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/delivery.py 2014-07-24 16:02:02 UTC (rev 13788)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/delivery.py 2014-07-24 16:36:26 UTC (rev 13789)
@@ -19,7 +19,6 @@
Handles the sending of scheduling messages via iMIP (mail gateway).
"""
-from twext.enterprise.jobqueue import inTransaction
from twext.python.log import Logger
from txweb2 import responsecode
from txweb2.dav.http import ErrorResponse
@@ -111,13 +110,14 @@
)
def enqueueOp(txn):
- return txn.enqueue(IMIPInvitationWork, fromAddr=fromAddr,
- toAddr=toAddr, icalendarText=caldata)
+ return txn.enqueue(
+ IMIPInvitationWork, fromAddr=fromAddr,
+ toAddr=toAddr, icalendarText=caldata
+ )
- yield inTransaction(
- lambda: self.scheduler.txn.store().newTransaction(
- "Submitting iMIP message for UID: {}".format(
- self.scheduler.calendar.resourceUID(),)),
+ yield self.scheduler.txn.store().inTransaction(
+ "Submitting iMIP message for UID: {}".format(
+ self.scheduler.calendar.resourceUID(),),
enqueueOp
)
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/test_delivery.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/test_delivery.py 2014-07-24 16:02:02 UTC (rev 13788)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/test/test_delivery.py 2014-07-24 16:36:26 UTC (rev 13789)
@@ -16,25 +16,39 @@
from txweb2 import responsecode
-from twisted.internet.defer import inlineCallbacks
+from twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, succeed
from twisted.trial import unittest
-from twistedcaldav.config import config
from twistedcaldav.ical import Component
+from twistedcaldav.stdconfig import config
-from txdav.caldav.datastore.scheduling.cuaddress import RemoteCalendarUser
+from txdav.caldav.datastore.scheduling.cuaddress import RemoteCalendarUser, \
+ LocalCalendarUser
from txdav.caldav.datastore.scheduling.imip.delivery import ScheduleViaIMip
from txdav.caldav.datastore.scheduling.itip import iTIPRequestStatus
from txdav.caldav.datastore.scheduling.scheduler import ScheduleResponseQueue
+from txdav.caldav.datastore.scheduling.imip.outbound import IMIPInvitationWork
+from txdav.common.datastore.test.util import CommonCommonTests
-class iMIPProcessing (unittest.TestCase):
+from twext.enterprise.jobqueue import JobItem
+
+class iMIPProcessing (CommonCommonTests, unittest.TestCase):
"""
iCalendar support tests
"""
+ @inlineCallbacks
+ def setUp(self):
+ super(iMIPProcessing, self).setUp()
+
+ yield self.buildStoreAndDirectory()
+
+
class FakeSchedule(object):
- def __init__(self, calendar):
+ def __init__(self, originator, calendar):
+ self.originator = originator
self.calendar = calendar
@@ -51,13 +65,16 @@
DTEND:20080601T130000Z
ORGANIZER;CN="User 01":mailto:user1 at example.com
ATTENDEE:mailto:user1 at example.com
-ATTENDEE:mailto:user2 at example.com
+ATTENDEE:mailto:user2 at example.org
END:VFREEBUSY
END:VCALENDAR
"""
- scheduler = iMIPProcessing.FakeSchedule(Component.fromString(data))
- recipients = (RemoteCalendarUser("mailto:user1 at example.com"),)
+ scheduler = iMIPProcessing.FakeSchedule(
+ LocalCalendarUser("mailto:user1 at example.com", None),
+ Component.fromString(data)
+ )
+ recipients = (RemoteCalendarUser("mailto:user2 at example.org"),)
responses = ScheduleResponseQueue("REQUEST", responsecode.OK)
delivery = ScheduleViaIMip(scheduler, recipients, responses, True)
@@ -68,6 +85,51 @@
@inlineCallbacks
+ def test_iMIP_delivery(self):
+
+ data = """BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REQUEST
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ORGANIZER;CN="User 01":mailto:user1 at example.com
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.org
+END:VEVENT
+END:VCALENDAR
+"""
+
+ results = []
+ class FakeSender(object):
+ def outbound(self, txn, fromAddr, toAddr, calendar):
+ results.append((fromAddr, toAddr))
+ return succeed(None)
+ self.patch(IMIPInvitationWork, "mailSender", FakeSender())
+
+ scheduler = iMIPProcessing.FakeSchedule(
+ LocalCalendarUser("mailto:user1 at example.com", None),
+ Component.fromString(data)
+ )
+ scheduler.txn = self.transactionUnderTest()
+ recipients = (RemoteCalendarUser("mailto:user2 at example.org"),)
+ responses = ScheduleResponseQueue("REQUEST", responsecode.OK)
+
+ delivery = ScheduleViaIMip(scheduler, recipients, responses, False)
+ yield delivery.generateSchedulingResponses()
+
+ self.assertEqual(len(responses.responses), 1)
+ self.assertEqual(str(responses.responses[0].reqstatus), iTIPRequestStatus.MESSAGE_SENT)
+
+ yield JobItem.waitEmpty(self.store.newTransaction, reactor, 60)
+
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0], ("mailto:user1 at example.com", "mailto:user2 at example.org",))
+
+
+ @inlineCallbacks
def test_matchCalendarUserAddress(self):
# iMIP not sensitive to case:
self.patch(config.Scheduling[ScheduleViaIMip.serviceType()], "AddressPatterns", ["mailto:.*"])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140724/92102006/attachment-0001.html>
More information about the calendarserver-changes
mailing list