[CalendarServer-changes] [2674] CalendarServer/branches/users/sagen/xmpp/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jul 10 14:34:24 PDT 2008
Revision: 2674
http://trac.macosforge.org/projects/calendarserver/changeset/2674
Author: sagen at apple.com
Date: 2008-07-10 14:34:24 -0700 (Thu, 10 Jul 2008)
Log Message:
-----------
Added XMPP tests
Modified Paths:
--------------
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/config.py
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/static.py
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/test/test_notify.py
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/config.py 2008-07-10 17:39:06 UTC (rev 2673)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/config.py 2008-07-10 21:34:24 UTC (rev 2674)
@@ -184,6 +184,16 @@
"Enabled" : True,
"Port" : 62308,
},
+ {
+ "Service" : "twistedcaldav.notify.XMPPNotifierService",
+ "Enabled" : False,
+ "Host" : "xmpp.host.name",
+ "Port" : 5222,
+ "JID" : "jid at xmpp.host/resource",
+ "Password" : "password_goes_here",
+ "ServiceAddress" : "pubsub.xmpp.host.name",
+ "KeepAliveSeconds" : 120,
+ },
]
},
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py 2008-07-10 17:39:06 UTC (rev 2673)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py 2008-07-10 21:34:24 UTC (rev 2674)
@@ -432,12 +432,13 @@
'pubsub#persist_items' : '0',
}
- def __init__(self, settings, reactor=None):
+ def __init__(self, settings, reactor=None, configOverride=None):
self.xmlStream = None
self.settings = settings
if reactor is None:
from twisted.internet import reactor
self.reactor = reactor
+ self.config = configOverride or config
def enqueue(self, uri):
self.log_info("ENQUEUE %s" % (uri,))
@@ -448,7 +449,7 @@
self.publishNode(nodeName)
def uriToNodeName(self, uri):
- return getPubSubPath(uri, getPubSubConfiguration())
+ return getPubSubPath(uri, getPubSubConfiguration(self.config))
def publishNode(self, nodeName):
if self.xmlStream is not None:
@@ -456,7 +457,6 @@
pubsubElement = iq.addElement('pubsub', defaultUri=self.pubsubNS)
publishElement = pubsubElement.addElement('publish')
publishElement['node'] = nodeName
- # itemElement = publishElement.addElement('item')
iq.addCallback(self.responseFromPublish, nodeName)
iq.send(to=self.settings['ServiceAddress'])
@@ -649,7 +649,7 @@
'replace'))
-def getPubSubConfiguration():
+def getPubSubConfiguration(config):
# TODO: Should probably cache this
results = { 'enabled' : False }
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/static.py 2008-07-10 17:39:06 UTC (rev 2673)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/static.py 2008-07-10 21:34:24 UTC (rev 2674)
@@ -617,7 +617,7 @@
qname = property.qname()
if qname == (customxml.pubsubnode_namespace, "node"):
- pubSubConfiguration = getPubSubConfiguration()
+ pubSubConfiguration = getPubSubConfiguration(config)
if pubSubConfiguration['enabled']:
return succeed(customxml.PubSubNodeProperty(
customxml.PubSubService(pubSubConfiguration['service']),
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/test/test_notify.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/test/test_notify.py 2008-07-10 17:39:06 UTC (rev 2673)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/test/test_notify.py 2008-07-10 21:34:24 UTC (rev 2674)
@@ -14,9 +14,14 @@
# limitations under the License.
##
+from copy import deepcopy
+
from twisted.trial.unittest import TestCase
from twisted.internet.task import Clock
+from twisted.words.protocols.jabber.client import IQ
from twistedcaldav.notify import *
+from twistedcaldav import config as config_mod
+from twistedcaldav.config import Config
@@ -320,33 +325,141 @@
class XMPPNotifierTests(TestCase):
+ xmppEnabledConfig = Config(config_mod.defaultConfig)
+ xmppEnabledConfig.Notifications['Services'][1]['Enabled'] = True
+ xmppEnabledConfig.ServerHostName = "server.example.com"
+ xmppEnabledConfig.HTTPPort = 80
+
+ xmppDisabledConfig = Config(config_mod.defaultConfig)
+ xmppDisabledConfig.Notifications['Services'][1]['Enabled'] = False
+
+ def setUp(self):
+ self.xmlStream = StubXmlStream()
+ self.settings = { 'ServiceAddress' : 'pubsub.example.com' }
+ self.notifier = XMPPNotifier(self.settings, reactor=Clock(),
+ configOverride=self.xmppEnabledConfig)
+ self.notifier.streamOpened(self.xmlStream)
+
def test_sendWhileConnected(self):
- xmlStream = StubXmlStream()
- settings = { 'ServiceAddress' : 'pubsub.example.com' }
- notifier = XMPPNotifier(settings, reactor=Clock())
- notifier.streamOpened(xmlStream)
- notifier.enqueue("/principals/__uids__/test")
+ self.notifier.enqueue("/principals/__uids__/test")
- iq = xmlStream.elements[0]
+ iq = self.xmlStream.elements[0]
self.assertEquals(iq.name, "iq")
- pubsub = list(iq.elements())[0]
- self.assertEquals(pubsub.name, "pubsub")
- self.assertEquals(pubsub.uri, 'http://jabber.org/protocol/pubsub')
+ pubsubElement = list(iq.elements())[0]
+ self.assertEquals(pubsubElement.name, "pubsub")
+ self.assertEquals(pubsubElement.uri, 'http://jabber.org/protocol/pubsub')
- publish = list(pubsub.elements())[0]
- self.assertEquals(publish.name, "publish")
- self.assertEquals(publish.uri, 'http://jabber.org/protocol/pubsub')
- self.assertEquals(publish['node'], "/test/com.apple.iCal")
+ publishElement = list(pubsubElement.elements())[0]
+ self.assertEquals(publishElement.name, "publish")
+ self.assertEquals(publishElement.uri, 'http://jabber.org/protocol/pubsub')
+ self.assertEquals(publishElement['node'],
+ "/Public/CalDAV/server.example.com/80/principals/__uids__/test/")
def test_sendWhileNotConnected(self):
- xmlStream = StubXmlStream()
- settings = { 'ServiceAddress' : 'pubsub.example.com' }
- notifier = XMPPNotifier(settings, Clock())
+ notifier = XMPPNotifier(self.settings, reactor=Clock(),
+ configOverride=self.xmppDisabledConfig)
notifier.enqueue("/principals/__uids__/test")
- self.assertEquals(xmlStream.elements, [])
+ self.assertEquals(self.xmlStream.elements, [])
+ def test_publishNewNode(self):
+ self.notifier.publishNode("testNodeName")
+ iq = self.xmlStream.elements[0]
+ self.assertEquals(iq.name, "iq")
+ def test_publishReponse400(self):
+ response = IQ(self.xmlStream, type='error')
+ errorElement = response.addElement('error')
+ errorElement['code'] = '400'
+ self.assertEquals(len(self.xmlStream.elements), 0)
+ self.notifier.responseFromPublish("testNodeName", response)
+ self.assertEquals(len(self.xmlStream.elements), 1)
+ iq = self.xmlStream.elements[0]
+ self.assertEquals(iq.name, "iq")
+ self.assertEquals(iq['type'], "get")
+
+ pubsubElement = list(iq.elements())[0]
+ self.assertEquals(pubsubElement.name, "pubsub")
+ self.assertEquals(pubsubElement.uri,
+ 'http://jabber.org/protocol/pubsub#owner')
+ configElement = list(pubsubElement.elements())[0]
+ self.assertEquals(configElement.name, "configure")
+ self.assertEquals(configElement['node'], "testNodeName")
+
+
+ def test_publishReponse404(self):
+ response = IQ(self.xmlStream, type='error')
+ errorElement = response.addElement('error')
+ errorElement['code'] = '404'
+ self.assertEquals(len(self.xmlStream.elements), 0)
+ self.notifier.responseFromPublish("testNodeName", response)
+ self.assertEquals(len(self.xmlStream.elements), 1)
+ iq = self.xmlStream.elements[0]
+ self.assertEquals(iq.name, "iq")
+ self.assertEquals(iq['type'], "set")
+
+ pubsubElement = list(iq.elements())[0]
+ self.assertEquals(pubsubElement.name, "pubsub")
+ self.assertEquals(pubsubElement.uri,
+ 'http://jabber.org/protocol/pubsub')
+ createElement = list(pubsubElement.elements())[0]
+ self.assertEquals(createElement.name, "create")
+ self.assertEquals(createElement['node'], "testNodeName")
+
+
+ def test_configureResponse(self):
+
+ def _getChild(element, name):
+ for child in element.elements():
+ if child.name == name:
+ return child
+ return None
+
+ response = IQ(self.xmlStream)
+ pubsubElement = response.addElement('pubsub')
+ configElement = pubsubElement.addElement('configure')
+ formElement = configElement.addElement('x')
+ formElement['type'] = 'form'
+ fields = [
+ ( "unknown", "don't edit me" ),
+ ( "pubsub#deliver_payloads", "1" ),
+ ( "pubsub#persist_items", "1" ),
+ ]
+ expectedFields = {
+ "unknown" : "don't edit me",
+ "pubsub#deliver_payloads" : "0",
+ "pubsub#persist_items" : "0",
+ }
+ for field in fields:
+ fieldElement = formElement.addElement("field")
+ fieldElement['var'] = field[0]
+ fieldElement.addElement('value', content=field[1])
+
+ print response.toXml()
+ self.assertEquals(len(self.xmlStream.elements), 0)
+ self.notifier.responseFromConfigurationForm("testNodeName", response)
+ self.assertEquals(len(self.xmlStream.elements), 1)
+
+ iq = self.xmlStream.elements[0]
+ self.assertEquals(iq.name, "iq")
+ self.assertEquals(iq['type'], "set")
+
+ pubsubElement = list(iq.elements())[0]
+ self.assertEquals(pubsubElement.name, "pubsub")
+ configElement = list(pubsubElement.elements())[0]
+ self.assertEquals(configElement.name, "configure")
+ self.assertEquals(configElement['node'], "testNodeName")
+ formElement = list(configElement.elements())[0]
+ self.assertEquals(formElement['type'], "submit")
+ for field in formElement.elements():
+ print field.name, field['var']
+ valueElement = _getChild(field, "value")
+ if valueElement is not None:
+ self.assertEquals(expectedFields[field['var']],
+ str(valueElement))
+
+
+
class XMPPNotificationFactoryTests(TestCase):
def test_sendPresence(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080710/c3c1501b/attachment-0001.html
More information about the calendarserver-changes
mailing list