[CalendarServer-changes] [2664] CalendarServer/branches/users/sagen/xmpp/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 7 11:36:54 PDT 2008


Revision: 2664
          http://trac.macosforge.org/projects/calendarserver/changeset/2664
Author:   sagen at apple.com
Date:     2008-07-07 11:36:54 -0700 (Mon, 07 Jul 2008)
Log Message:
-----------
Adding XMPPNotifier tests

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py
    CalendarServer/branches/users/sagen/xmpp/twistedcaldav/test/test_notify.py

Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py	2008-07-07 17:43:40 UTC (rev 2663)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py	2008-07-07 18:36:54 UTC (rev 2664)
@@ -56,7 +56,8 @@
 NotificationClient NotificationClientFactory NotificationClientLineProtocol
 NotificationClientUserMixIn NotificationOptions NotificationServiceMaker
 SimpleLineNotificationFactory SimpleLineNotificationProtocol
-SimpleLineNotifier SimpleLineNotifierService
+SimpleLineNotifier SimpleLineNotifierService XMPPNotificationFactory
+XMPPNotifier
 '''.split()
 
 

Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/test/test_notify.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/test/test_notify.py	2008-07-07 17:43:40 UTC (rev 2663)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/test/test_notify.py	2008-07-07 18:36:54 UTC (rev 2664)
@@ -297,3 +297,78 @@
 
     def getPeer(self):
         return "peer"
+
+
+
+
+
+
+class StubXmlStream(object):
+
+    def __init__(self):
+        self.elements = []
+
+    def send(self, element):
+        self.elements.append(element)
+
+    def addOnetimeObserver(*args, **kwds):
+        pass
+
+    def addObserver(*args, **kwds):
+        pass
+
+
+class XMPPNotifierTests(TestCase):
+
+    def test_sendWhileConnected(self):
+        xmlStream = StubXmlStream()
+        settings = { 'ServiceAddress' : 'pubsub.example.com' }
+        notifier = XMPPNotifier(settings, reactor=Clock())
+        notifier.streamOpened(xmlStream)
+        notifier.enqueue("A")
+
+        iq = 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')
+
+        publish = list(pubsub.elements())[0]
+        self.assertEquals(publish.name, "publish")
+        self.assertEquals(publish.uri, 'http://jabber.org/protocol/pubsub')
+        self.assertEquals(publish['node'], "A")
+
+    def test_sendWhileNotConnected(self):
+        xmlStream = StubXmlStream()
+        settings = { 'ServiceAddress' : 'pubsub.example.com' }
+        notifier = XMPPNotifier(settings, Clock())
+        notifier.enqueue("A")
+        self.assertEquals(xmlStream.elements, [])
+
+
+class XMPPNotificationFactoryTests(TestCase):
+
+    def test_sendPresence(self):
+        clock = Clock()
+        xmlStream = StubXmlStream()
+        settings = { 'ServiceAddress' : 'pubsub.example.com', 'JID' : 'jid',
+            'Password' : 'password', 'KeepAliveSeconds' : 5 }
+        notifier = XMPPNotifier(settings, reactor=clock)
+        factory = XMPPNotificationFactory(notifier, settings, reactor=clock)
+        factory.connected(xmlStream)
+        factory.authenticated(xmlStream)
+
+        self.assertEquals(len(xmlStream.elements), 1)
+        presence = xmlStream.elements[0]
+        self.assertEquals(presence.name, 'presence')
+
+        clock.advance(5)
+
+        self.assertEquals(len(xmlStream.elements), 2)
+        presence = xmlStream.elements[1]
+        self.assertEquals(presence.name, 'presence')
+
+        factory.disconnected(xmlStream)
+        clock.advance(5)
+        self.assertEquals(len(xmlStream.elements), 2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080707/0f41eb3e/attachment.html 


More information about the calendarserver-changes mailing list