source: ralphm-patches/pubsub_client_sender.patch @ 12:fc40892815eb

Last change on this file since 12:fc40892815eb was 5:231bc3e8b810, checked in by Ralph Meijer <ralphm@…>, 13 years ago

A gazillion changes.

File size: 6.9 KB
RevLine 
[5]1diff -r 5a91781194ab wokkel/pubsub.py
2--- a/wokkel/pubsub.py  Mon Mar 23 21:43:25 2009 +0100
3+++ b/wokkel/pubsub.py  Mon Mar 23 21:50:36 2009 +0100
[4]4@@ -605,7 +605,7 @@
[3]5         pass
6 
7 
8-    def createNode(self, service, nodeIdentifier=None):
9+    def createNode(self, service, nodeIdentifier=None, sender=None):
10         """
11         Create a publish subscribe node.
12 
[4]13@@ -617,6 +617,7 @@
14         request = PubSubRequest('create')
15         request.recipient = service
16         request.nodeIdentifier = nodeIdentifier
17+        request.sender = sender
[3]18 
[4]19         def cb(iq):
20             try:
21@@ -631,7 +632,7 @@
22         return d
[3]23 
24 
25-    def deleteNode(self, service, nodeIdentifier):
26+    def deleteNode(self, service, nodeIdentifier, sender=None):
27         """
28         Delete a publish subscribe node.
29 
[4]30@@ -643,10 +644,11 @@
31         request = PubSubRequest('delete')
32         request.recipient = service
33         request.nodeIdentifier = nodeIdentifier
34+        request.sender = sender
35         return request.send(self.xmlstream)
[3]36 
37 
38-    def subscribe(self, service, nodeIdentifier, subscriber):
39+    def subscribe(self, service, nodeIdentifier, subscriber, sender=None):
40         """
41         Subscribe to a publish subscribe node.
42 
[4]43@@ -662,6 +664,7 @@
44         request.recipient = service
45         request.nodeIdentifier = nodeIdentifier
46         request.subscriber = subscriber
47+        request.sender = sender
48 
49         def cb(iq):
50             subscription = iq.pubsub.subscription["subscription"]
51@@ -681,7 +684,7 @@
52         return d
[3]53 
54 
55-    def unsubscribe(self, service, nodeIdentifier, subscriber):
56+    def unsubscribe(self, service, nodeIdentifier, subscriber, sender=None):
57         """
58         Unsubscribe from a publish subscribe node.
59 
[4]60@@ -696,10 +699,11 @@
61         request.recipient = service
62         request.nodeIdentifier = nodeIdentifier
63         request.subscriber = subscriber
64+        request.sender = sender
65         return request.send(self.xmlstream)
[3]66 
67 
68-    def publish(self, service, nodeIdentifier, items=None):
69+    def publish(self, service, nodeIdentifier, items=None, sender=None):
70         """
71         Publish to a publish subscribe node.
72 
[4]73@@ -714,10 +718,11 @@
74         request.recipient = service
75         request.nodeIdentifier = nodeIdentifier
76         request.items = items
77+        request.sender = sender
78         return request.send(self.xmlstream)
[3]79 
80 
81-    def items(self, service, nodeIdentifier, maxItems=None):
82+    def items(self, service, nodeIdentifier, maxItems=None, sender=None):
83         """
84         Retrieve previously published items from a publish subscribe node.
85 
[4]86@@ -733,6 +738,7 @@
87         request.nodeIdentifier = nodeIdentifier
88         if maxItems:
89             request.maxItems = str(int(maxItems))
90+        request.sender = sender
91 
92         def cb(iq):
93             items = []
[5]94diff -r 5a91781194ab wokkel/test/test_pubsub.py
95--- a/wokkel/test/test_pubsub.py        Mon Mar 23 21:43:25 2009 +0100
96+++ b/wokkel/test/test_pubsub.py        Mon Mar 23 21:50:36 2009 +0100
97@@ -258,6 +258,22 @@
[4]98         return d
99 
100 
101+    def test_createNodeWithSender(self):
102+        """
103+        Test sending create request from a specific JID.
104+        """
105+
106+        d = self.protocol.createNode(JID('pubsub.example.org'), 'test',
107+                                     sender=JID('user@example.org'))
108+
109+        iq = self.stub.output[-1]
110+        self.assertEquals('user@example.org', iq['from'])
111+
112+        response = toResponse(iq, 'result')
113+        self.stub.send(response)
114+        return d
115+
116+
117     def test_deleteNode(self):
[3]118         """
[4]119         Test sending delete request.
[5]120@@ -281,6 +297,22 @@
[4]121         return d
122 
123 
124+    def test_deleteNodeWithSender(self):
125+        """
126+        Test sending delete request.
127+        """
128+
129+        d = self.protocol.deleteNode(JID('pubsub.example.org'), 'test',
130+                                     sender=JID('user@example.org'))
131+
132+        iq = self.stub.output[-1]
133+        self.assertEquals('user@example.org', iq['from'])
134+
135+        response = toResponse(iq, 'result')
136+        self.stub.send(response)
137+        return d
138+
139+
140     def test_publish(self):
141         """
142         Test sending publish request.
[5]143@@ -332,6 +364,23 @@
[4]144         return d
145 
146 
147+    def test_publishWithSender(self):
148+        """
149+        Test sending publish request from a specific JID.
150+        """
151+
152+        item = pubsub.Item()
153+        d = self.protocol.publish(JID('pubsub.example.org'), 'test', [item],
154+                                  JID('user@example.org'))
155+
156+        iq = self.stub.output[-1]
157+        self.assertEquals('user@example.org', iq['from'])
158+
159+        response = toResponse(iq, 'result')
160+        self.stub.send(response)
161+        return d
162+
163+
164     def test_subscribe(self):
165         """
166         Test sending subscription request.
[5]167@@ -401,6 +450,27 @@
[4]168         return d
169 
170 
171+    def test_subscribeWithSender(self):
172+        """
173+        Test sending subscription request from a specific JID.
174+        """
175+        d = self.protocol.subscribe(JID('pubsub.example.org'), 'test',
176+                                      JID('user@example.org'),
177+                                      sender=JID('user@example.org'))
178+
179+        iq = self.stub.output[-1]
180+        self.assertEquals('user@example.org', iq['from'])
181+
182+        response = toResponse(iq, 'result')
183+        pubsub = response.addElement((NS_PUBSUB, 'pubsub'))
184+        subscription = pubsub.addElement('subscription')
185+        subscription['node'] = 'test'
186+        subscription['jid'] = 'user@example.org'
187+        subscription['subscription'] = 'subscribed'
188+        self.stub.send(response)
189+        return d
190+
191+
192     def test_unsubscribe(self):
193         """
194         Test sending unsubscription request.
[5]195@@ -424,6 +494,20 @@
[4]196         return d
197 
198 
199+    def test_unsubscribeWithSender(self):
200+        """
201+        Test sending unsubscription request from a specific JID.
202+        """
203+        d = self.protocol.unsubscribe(JID('pubsub.example.org'), 'test',
204+                                      JID('user@example.org'),
205+                                      sender=JID('user@example.org'))
206+
207+        iq = self.stub.output[-1]
208+        self.assertEquals('user@example.org', iq['from'])
209+        self.stub.send(toResponse(iq, 'result'))
210+        return d
211+
212+
213     def test_items(self):
214         """
215         Test sending items request.
[5]216@@ -490,6 +574,25 @@
[4]217         return d
218 
219 
220+    def test_itemsWithSender(self):
221+        """
222+        Test sending items request from a specific JID.
223+        """
224+
225+        d = self.protocol.items(JID('pubsub.example.org'), 'test',
226+                               sender=JID('user@example.org'))
227+
228+        iq = self.stub.output[-1]
229+        self.assertEquals('user@example.org', iq['from'])
230+
231+        response = toResponse(iq, 'result')
232+        items = response.addElement((NS_PUBSUB, 'pubsub')).addElement('items')
233+        items['node'] = 'test'
234+
235+        self.stub.send(response)
236+        return d
237+
238+
239 
[5]240 class PubSubRequestTest(unittest.TestCase):
241 
Note: See TracBrowser for help on using the repository browser.