diff idavoll/test/test_gateway.py @ 206:274a45d2a5ab

Implement root collection that includes all leaf nodes.
author Ralph Meijer <ralphm@ik.nu>
date Mon, 04 Aug 2008 13:47:10 +0000
parents b4bf0a5ce50d
children 7f3ffb7a1a9e
line wrap: on
line diff
--- a/idavoll/test/test_gateway.py	Mon Aug 04 07:10:45 2008 +0000
+++ b/idavoll/test/test_gateway.py	Mon Aug 04 13:47:10 2008 +0000
@@ -18,11 +18,12 @@
 AGENT = "Idavoll Test Script"
 NS_ATOM = "http://www.w3.org/2005/Atom"
 
-entry = domish.Element((NS_ATOM, 'entry'))
-entry.addElement("id", content="urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")
-entry.addElement("title", content="Atom-Powered Robots Run Amok")
-entry.addElement("author").addElement("name", content="John Doe")
-entry.addElement("content", content="Some text.")
+TEST_ENTRY = domish.Element((NS_ATOM, 'entry'))
+TEST_ENTRY.addElement("id",
+                      content="urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")
+TEST_ENTRY.addElement("title", content="Atom-Powered Robots Run Amok")
+TEST_ENTRY.addElement("author").addElement("name", content="John Doe")
+TEST_ENTRY.addElement("content", content="Some text.")
 
 baseURI = "http://localhost:8086/"
 componentJID = "pubsub"
@@ -33,10 +34,27 @@
     def setUp(self):
         self.client = gateway.GatewayClient(baseURI)
         self.client.startService()
+        self.addCleanup(self.client.stopService)
+
+        def trapConnectionRefused(failure):
+            from twisted.internet.error import ConnectionRefusedError
+            failure.trap(ConnectionRefusedError)
+            raise unittest.SkipTest("Gateway to test against is not available")
+
+        def trapNotFound(failure):
+            from twisted.web.error import Error
+            failure.trap(Error)
+
+        d = self.client.ping()
+        d.addErrback(trapConnectionRefused)
+        d.addErrback(trapNotFound)
+        return d
+
 
     def tearDown(self):
         return self.client.stopService()
 
+
     def test_create(self):
 
         def cb(response):
@@ -51,7 +69,7 @@
         def cb(response):
             self.assertIn('uri', response)
 
-        d = self.client.publish(entry)
+        d = self.client.publish(TEST_ENTRY)
         d.addCallback(cb)
         return d
 
@@ -62,7 +80,7 @@
 
         def cb1(response):
             xmppURI = response['uri']
-            d = self.client.publish(entry, xmppURI)
+            d = self.client.publish(TEST_ENTRY, xmppURI)
             d.addCallback(cb2, xmppURI)
             return d
 
@@ -74,7 +92,7 @@
         def cb(err):
             self.assertEqual('404', err.status)
 
-        d = self.client.publish(entry, 'xmpp:%s?node=test' % componentJID)
+        d = self.client.publish(TEST_ENTRY, 'xmpp:%s?node=test' % componentJID)
         self.assertFailure(d, error.Error)
         d.addCallback(cb)
         return d
@@ -93,7 +111,6 @@
         d.addCallback(cb)
         return d
 
-
     def test_subscribeGetNotification(self):
 
         def onNotification(data, headers):
@@ -106,7 +123,7 @@
             return d
 
         def cb2(xmppURI):
-            d = self.client.publish(entry, xmppURI)
+            d = self.client.publish(TEST_ENTRY, xmppURI)
             return d
 
 
@@ -140,7 +157,7 @@
             return d
 
         def cb3(xmppURI):
-            d = self.client.publish(entry, xmppURI)
+            d = self.client.publish(TEST_ENTRY, xmppURI)
             return d
 
 
@@ -169,7 +186,7 @@
         def cb(response):
             xmppURI = response['uri']
             self.assertNot(self.client.deferred.called)
-            d = self.client.publish(entry, xmppURI)
+            d = self.client.publish(TEST_ENTRY, xmppURI)
             d.addCallback(lambda _: xmppURI)
             return d
 
@@ -202,7 +219,7 @@
             xmppURI = response['uri']
             self.assertNot(client1.deferred.called)
             self.assertNot(client2.deferred.called)
-            d = self.client.publish(entry, xmppURI)
+            d = self.client.publish(TEST_ENTRY, xmppURI)
             d.addCallback(lambda _: xmppURI)
             return d
 
@@ -224,6 +241,7 @@
         client2.callback = onNotification2
         client2.deferred = defer.Deferred()
 
+
         d = self.client.create()
         d.addCallback(cb)
         d.addCallback(cb2)
@@ -242,6 +260,32 @@
         return d
 
 
+    def test_subscribeRootGetNotification(self):
+
+        def onNotification(data, headers):
+            self.client.deferred.callback(None)
+
+        def cb(response):
+            xmppURI = response['uri']
+            jid, nodeIdentifier = gateway.getServiceAndNode(xmppURI)
+            rootNode = gateway.getXMPPURI(jid, '')
+
+            d = self.client.subscribe(rootNode)
+            d.addCallback(lambda _: xmppURI)
+            return d
+
+        def cb2(xmppURI):
+            return self.client.publish(TEST_ENTRY, xmppURI)
+
+
+        self.client.callback = onNotification
+        self.client.deferred = defer.Deferred()
+        d = self.client.create()
+        d.addCallback(cb)
+        d.addCallback(cb2)
+        return defer.gatherResults([d, self.client.deferred])
+
+
     def test_unsubscribeNonExisting(self):
         def cb(err):
             self.assertEqual('403', err.status)
@@ -258,7 +302,7 @@
             d = self.client.items(xmppURI)
             return d
 
-        d = self.client.publish(entry)
+        d = self.client.publish(TEST_ENTRY)
         d.addCallback(cb)
         return d
 
@@ -269,6 +313,6 @@
             d = self.client.items(xmppURI, 2)
             return d
 
-        d = self.client.publish(entry)
+        d = self.client.publish(TEST_ENTRY)
         d.addCallback(cb)
         return d