comparison idavoll/test/test_gateway.py @ 209:7f3ffb7a1a9e

Add support for node deletion with redirect.
author Ralph Meijer <ralphm@ik.nu>
date Fri, 30 Jan 2009 14:35:05 +0000
parents 274a45d2a5ab
children bfc198af5d27
comparison
equal deleted inserted replaced
208:cc4f45ef793e 209:7f3ffb7a1a9e
94 94
95 d = self.client.publish(TEST_ENTRY, 'xmpp:%s?node=test' % componentJID) 95 d = self.client.publish(TEST_ENTRY, 'xmpp:%s?node=test' % componentJID)
96 self.assertFailure(d, error.Error) 96 self.assertFailure(d, error.Error)
97 d.addCallback(cb) 97 d.addCallback(cb)
98 return d 98 return d
99
100 def test_delete(self):
101 def cb(response):
102 xmppURI = response['uri']
103 d = self.client.delete(xmppURI)
104 return d
105
106 d = self.client.create()
107 d.addCallback(cb)
108 return d
109
110 def test_deleteWithRedirect(self):
111 def cb(response):
112 xmppURI = response['uri']
113 redirectURI = 'xmpp:%s?node=test' % componentJID
114 d = self.client.delete(xmppURI, redirectURI)
115 return d
116
117 d = self.client.create()
118 d.addCallback(cb)
119 return d
120
121 def test_deleteNotification(self):
122 def onNotification(data, headers):
123 try:
124 self.assertTrue(headers.hasHeader('Event'))
125 self.assertEquals(['DELETED'], headers.getRawHeaders('Event'))
126 self.assertFalse(headers.hasHeader('Link'))
127 except:
128 self.client.deferred.errback()
129 else:
130 self.client.deferred.callback(None)
131
132 def cb(response):
133 xmppURI = response['uri']
134 d = self.client.subscribe(xmppURI)
135 d.addCallback(lambda _: xmppURI)
136 return d
137
138 def cb2(xmppURI):
139 d = self.client.delete(xmppURI)
140 return d
141
142 self.client.callback = onNotification
143 self.client.deferred = defer.Deferred()
144 d = self.client.create()
145 d.addCallback(cb)
146 d.addCallback(cb2)
147 return defer.gatherResults([d, self.client.deferred])
148
149 def test_deleteNotificationWithRedirect(self):
150 redirectURI = 'xmpp:%s?node=test' % componentJID
151
152 def onNotification(data, headers):
153 try:
154 self.assertTrue(headers.hasHeader('Event'))
155 self.assertEquals(['DELETED'], headers.getRawHeaders('Event'))
156 self.assertEquals(['<%s>; rel=alternate' % redirectURI],
157 headers.getRawHeaders('Link'))
158 except:
159 self.client.deferred.errback()
160 else:
161 self.client.deferred.callback(None)
162
163 def cb(response):
164 xmppURI = response['uri']
165 d = self.client.subscribe(xmppURI)
166 d.addCallback(lambda _: xmppURI)
167 return d
168
169 def cb2(xmppURI):
170 d = self.client.delete(xmppURI, redirectURI)
171 return d
172
173 self.client.callback = onNotification
174 self.client.deferred = defer.Deferred()
175 d = self.client.create()
176 d.addCallback(cb)
177 d.addCallback(cb2)
178 return defer.gatherResults([d, self.client.deferred])
99 179
100 def test_list(self): 180 def test_list(self):
101 d = self.client.listNodes() 181 d = self.client.listNodes()
102 return d 182 return d
103 183