source: ralphm-patches/request-xmpphandler.patch @ 53:fd2b3f70b221

Last change on this file since 53:fd2b3f70b221 was 53:fd2b3f70b221, checked in by Ralph Meijer <ralphm@…>, 11 years ago

Small cleanups for request handling.

File size: 2.2 KB
RevLine 
[47]1# HG changeset patch
[53]2# Parent 4d60ea3a5ab59d48e5080c913f6aeea9af55fccb
[47]3Add request method to XMPPHandler, passing up to its StreamManager.
4
[53]5diff -r 4d60ea3a5ab5 wokkel/subprotocols.py
6--- a/wokkel/subprotocols.py    Wed Aug 03 09:45:01 2011 +0200
7+++ b/wokkel/subprotocols.py    Wed Aug 03 09:46:32 2011 +0200
[47]8@@ -94,6 +94,18 @@
9         self.parent.send(obj)
10 
11 
12+    def request(self, request):
13+        """
14+        Send an IQ request and track the response.
15+
16+        This passes the request to the parent for sending and response
17+        tracking.
18+
19+        @see: L{StreamManager.request}.
20+        """
21+        return self.parent.request(request)
22+
23+
24 
25 class XMPPHandlerCollection(object):
26     """
[53]27diff -r 4d60ea3a5ab5 wokkel/test/test_subprotocols.py
28--- a/wokkel/test/test_subprotocols.py  Wed Aug 03 09:45:01 2011 +0200
29+++ b/wokkel/test/test_subprotocols.py  Wed Aug 03 09:46:32 2011 +0200
[47]30@@ -71,6 +71,15 @@
31 
32 
33 
34+class IQGetStanza(generic.Stanza):
35+    timeout = None
36+
37+    stanzaKind = 'iq'
38+    stanzaType = 'get'
39+    stanzaID = 'test'
40+
41+
42+
43 class XMPPHandlerTest(unittest.TestCase):
44     """
45     Tests for L{subprotocols.XMPPHandler}.
46@@ -126,6 +135,27 @@
47         self.assertIdentical(None, handler.xmlstream)
48 
49 
50+    def test_request(self):
51+        """
52+        A request is passed up to the stream manager.
53+        """
54+        class DummyStreamManager(object):
55+            def __init__(self):
56+                self.requests = []
57+
58+            def request(self, request):
59+                self.requests.append(request)
[53]60+                return defer.succeed(None)
[47]61+
62+        handler = subprotocols.XMPPHandler()
63+        handler.parent = DummyStreamManager()
64+        request = IQGetStanza()
65+        d = handler.request(request)
66+        self.assertEquals(1, len(handler.parent.requests))
67+        self.assertIdentical(request, handler.parent.requests[-1])
68+        return d
69+
70+
71 
72 class XMPPHandlerCollectionTest(unittest.TestCase):
73     """
[53]74@@ -165,13 +195,6 @@
[47]75 
76 
77 
78-class IQGetStanza(generic.Stanza):
79-    stanzaKind = 'iq'
80-    stanzaType = 'get'
81-    stanzaID = 'test'
82-
83-
84-
85 class StreamManagerTest(unittest.TestCase):
86     """
87     Tests for L{subprotocols.StreamManager}.
Note: See TracBrowser for help on using the repository browser.