| 1 |
# Copyright (c) Ralph Meijer. |
| 2 |
# See LICENSE for details. |
| 3 |
|
| 4 |
""" |
| 5 |
Tests for L{tx_xmpp.pubsub} |
| 6 |
""" |
| 7 |
|
| 8 |
from zope.interface import verify |
| 9 |
|
| 10 |
from twisted.trial import unittest |
| 11 |
from twisted.internet import defer |
| 12 |
from twisted.words.xish import domish |
| 13 |
from twisted.words.protocols.jabber import error |
| 14 |
from twisted.words.protocols.jabber.jid import JID |
| 15 |
from twisted.words.protocols.jabber.xmlstream import toResponse |
| 16 |
|
| 17 |
from .. import data_form, disco, itx_xmpp, pubsub, shim |
| 18 |
from ..generic import parseXml |
| 19 |
from .helpers import TestableRequestHandlerMixin, XmlStreamStub |
| 20 |
|
| 21 |
NS_PUBSUB = "http://jabber.org/protocol/pubsub" |
| 22 |
NS_PUBSUB_NODE_CONFIG = "http://jabber.org/protocol/pubsub#node_config" |
| 23 |
NS_PUBSUB_ERRORS = "http://jabber.org/protocol/pubsub#errors" |
| 24 |
NS_PUBSUB_EVENT = "http://jabber.org/protocol/pubsub#event" |
| 25 |
NS_PUBSUB_OWNER = "http://jabber.org/protocol/pubsub#owner" |
| 26 |
NS_PUBSUB_META_DATA = "http://jabber.org/protocol/pubsub#meta-data" |
| 27 |
NS_PUBSUB_SUBSCRIBE_OPTIONS = "http://jabber.org/protocol/pubsub#subscribe_options" |
| 28 |
|
| 29 |
|
| 30 |
def calledAsync(fn): |
| 31 |
""" |
| 32 |
Function wrapper that fires a deferred upon calling the given function. |
| 33 |
""" |
| 34 |
d = defer.Deferred() |
| 35 |
|
| 36 |
def func(*args, **kwargs): |
| 37 |
try: |
| 38 |
result = fn(*args, **kwargs) |
| 39 |
except: |
| 40 |
d.errback() |
| 41 |
else: |
| 42 |
d.callback(result) |
| 43 |
|
| 44 |
return d, func |
| 45 |
|
| 46 |
|
| 47 |
class SubscriptionTest(unittest.TestCase): |
| 48 |
""" |
| 49 |
Tests for L{pubsub.Subscription}. |
| 50 |
""" |
| 51 |
|
| 52 |
def test_fromElement(self): |
| 53 |
""" |
| 54 |
fromElement parses a subscription from XML DOM. |
| 55 |
""" |
| 56 |
xml = """ |
| 57 |
<subscription node='test' jid='[email protected]/Home' |
| 58 |
subscription='pending'/> |
| 59 |
""" |
| 60 |
subscription = pubsub.Subscription.fromElement(parseXml(xml)) |
| 61 |
self.assertEqual("test", subscription.nodeIdentifier) |
| 62 |
self.assertEqual(JID("[email protected]/Home"), subscription.subscriber) |
| 63 |
self.assertEqual("pending", subscription.state) |
| 64 |
self.assertIdentical(None, subscription.subscriptionIdentifier) |
| 65 |
|
| 66 |
def test_fromElementWithSubscriptionIdentifier(self): |
| 67 |
""" |
| 68 |
A subscription identifier in the subscription should be parsed, too. |
| 69 |
""" |
| 70 |
xml = """ |
| 71 |
<subscription node='test' jid='[email protected]/Home' subid='1234' |
| 72 |
subscription='pending'/> |
| 73 |
""" |
| 74 |
subscription = pubsub.Subscription.fromElement(parseXml(xml)) |
| 75 |
self.assertEqual("1234", subscription.subscriptionIdentifier) |
| 76 |
|
| 77 |
def test_toElement(self): |
| 78 |
""" |
| 79 |
Rendering a Subscription should yield the proper attributes. |
| 80 |
""" |
| 81 |
subscription = pubsub.Subscription( |
| 82 |
"test", JID("[email protected]/Home"), "pending" |
| 83 |
) |
| 84 |
element = subscription.toElement() |
| 85 |
self.assertEqual("subscription", element.name) |
| 86 |
self.assertEqual(None, element.uri) |
| 87 |
self.assertEqual("test", element.getAttribute("node")) |
| 88 |
self.assertEqual("[email protected]/Home", element.getAttribute("jid")) |
| 89 |
self.assertEqual("pending", element.getAttribute("subscription")) |
| 90 |
self.assertFalse(element.hasAttribute("subid")) |
| 91 |
|
| 92 |
def test_toElementEmptyNodeIdentifier(self): |
| 93 |
""" |
| 94 |
The empty node identifier should not yield a node attribute. |
| 95 |
""" |
| 96 |
subscription = pubsub.Subscription("", JID("[email protected]/Home"), "pending") |
| 97 |
element = subscription.toElement() |
| 98 |
self.assertFalse(element.hasAttribute("node")) |
| 99 |
|
| 100 |
def test_toElementWithSubscriptionIdentifier(self): |
| 101 |
""" |
| 102 |
The subscription identifier, if set, is in the subid attribute. |
| 103 |
""" |
| 104 |
subscription = pubsub.Subscription( |
| 105 |
"test", JID("[email protected]/Home"), "pending", subscriptionIdentifier="1234" |
| 106 |
) |
| 107 |
element = subscription.toElement() |
| 108 |
self.assertEqual("1234", element.getAttribute("subid")) |
| 109 |
|
| 110 |
|
| 111 |
class ItemTests(unittest.TestCase): |
| 112 |
""" |
| 113 |
Tests for L{pubsub.Item}. |
| 114 |
""" |
| 115 |
|
| 116 |
def test_payloadRaw(self): |
| 117 |
""" |
| 118 |
Adding a payload as a string assumes serialized XML. |
| 119 |
""" |
| 120 |
payload = "<test xmlns='foo'/>" |
| 121 |
item = pubsub.Item(payload=payload) |
| 122 |
self.assertEqual(payload, item.children[0]) |
| 123 |
|
| 124 |
def test_payloadElement(self): |
| 125 |
""" |
| 126 |
Adding a payload as an domish Element, just adds that element as child. |
| 127 |
""" |
| 128 |
payload = domish.Element(("foo", "test")) |
| 129 |
item = pubsub.Item(payload=payload) |
| 130 |
self.assertIs(payload, item.children[0]) |
| 131 |
|
| 132 |
|
| 133 |
class PubSubClientTest(unittest.TestCase): |
| 134 |
timeout = 2 |
| 135 |
|
| 136 |
def setUp(self): |
| 137 |
self.stub = XmlStreamStub() |
| 138 |
self.protocol = pubsub.PubSubClient() |
| 139 |
self.protocol.xmlstream = self.stub.xmlstream |
| 140 |
self.protocol.connectionInitialized() |
| 141 |
|
| 142 |
def test_interface(self): |
| 143 |
""" |
| 144 |
Do instances of L{pubsub.PubSubClient} provide L{itx_xmpp.IPubSubClient}? |
| 145 |
""" |
| 146 |
verify.verifyObject(itx_xmpp.IPubSubClient, self.protocol) |
| 147 |
|
| 148 |
def test_eventItems(self): |
| 149 |
""" |
| 150 |
Test receiving an items event resulting in a call to itemsReceived. |
| 151 |
""" |
| 152 |
message = domish.Element((None, "message")) |
| 153 |
message["from"] = "pubsub.example.org" |
| 154 |
message["to"] = "[email protected]/home" |
| 155 |
event = message.addElement((NS_PUBSUB_EVENT, "event")) |
| 156 |
items = event.addElement("items") |
| 157 |
items["node"] = "test" |
| 158 |
item1 = items.addElement("item") |
| 159 |
item1["id"] = "item1" |
| 160 |
item2 = items.addElement("retract") |
| 161 |
item2["id"] = "item2" |
| 162 |
item3 = items.addElement("item") |
| 163 |
item3["id"] = "item3" |
| 164 |
|
| 165 |
def itemsReceived(event): |
| 166 |
self.assertEquals(JID("[email protected]/home"), event.recipient) |
| 167 |
self.assertEquals(JID("pubsub.example.org"), event.sender) |
| 168 |
self.assertEquals("test", event.nodeIdentifier) |
| 169 |
self.assertEquals([item1, item2, item3], event.items) |
| 170 |
|
| 171 |
d, self.protocol.itemsReceived = calledAsync(itemsReceived) |
| 172 |
self.stub.send(message) |
| 173 |
return d |
| 174 |
|
| 175 |
def test_eventItemsCollection(self): |
| 176 |
""" |
| 177 |
Test receiving an items event resulting in a call to itemsReceived. |
| 178 |
""" |
| 179 |
message = domish.Element((None, "message")) |
| 180 |
message["from"] = "pubsub.example.org" |
| 181 |
message["to"] = "[email protected]/home" |
| 182 |
event = message.addElement((NS_PUBSUB_EVENT, "event")) |
| 183 |
items = event.addElement("items") |
| 184 |
items["node"] = "test" |
| 185 |
|
| 186 |
headers = shim.Headers([("Collection", "collection")]) |
| 187 |
message.addChild(headers) |
| 188 |
|
| 189 |
def itemsReceived(event): |
| 190 |
self.assertEquals(JID("[email protected]/home"), event.recipient) |
| 191 |
self.assertEquals(JID("pubsub.example.org"), event.sender) |
| 192 |
self.assertEquals("test", event.nodeIdentifier) |
| 193 |
self.assertEquals({"Collection": ["collection"]}, event.headers) |
| 194 |
|
| 195 |
d, self.protocol.itemsReceived = calledAsync(itemsReceived) |
| 196 |
self.stub.send(message) |
| 197 |
return d |
| 198 |
|
| 199 |
def test_eventItemsError(self): |
| 200 |
""" |
| 201 |
An error message with embedded event should not be handled. |
| 202 |
|
| 203 |
This test uses an items event, which should not result in itemsReceived |
| 204 |
being called. In general message.handled should be False. |
| 205 |
""" |
| 206 |
message = domish.Element((None, "message")) |
| 207 |
message["from"] = "pubsub.example.org" |
| 208 |
message["to"] = "[email protected]/home" |
| 209 |
message["type"] = "error" |
| 210 |
event = message.addElement((NS_PUBSUB_EVENT, "event")) |
| 211 |
items = event.addElement("items") |
| 212 |
items["node"] = "test" |
| 213 |
|
| 214 |
class UnexpectedCall(Exception): |
| 215 |
pass |
| 216 |
|
| 217 |
def itemsReceived(event): |
| 218 |
raise UnexpectedCall("Unexpected call to itemsReceived") |
| 219 |
|
| 220 |
self.protocol.itemsReceived = itemsReceived |
| 221 |
self.stub.send(message) |
| 222 |
self.assertFalse(message.handled) |
| 223 |
|
| 224 |
def test_eventDelete(self): |
| 225 |
""" |
| 226 |
Test receiving a delete event resulting in a call to deleteReceived. |
| 227 |
""" |
| 228 |
message = domish.Element((None, "message")) |
| 229 |
message["from"] = "pubsub.example.org" |
| 230 |
message["to"] = "[email protected]/home" |
| 231 |
event = message.addElement((NS_PUBSUB_EVENT, "event")) |
| 232 |
delete = event.addElement("delete") |
| 233 |
delete["node"] = "test" |
| 234 |
|
| 235 |
def deleteReceived(event): |
| 236 |
self.assertEquals(JID("[email protected]/home"), event.recipient) |
| 237 |
self.assertEquals(JID("pubsub.example.org"), event.sender) |
| 238 |
self.assertEquals("test", event.nodeIdentifier) |
| 239 |
|
| 240 |
d, self.protocol.deleteReceived = calledAsync(deleteReceived) |
| 241 |
self.stub.send(message) |
| 242 |
return d |
| 243 |
|
| 244 |
def test_eventDeleteRedirect(self): |
| 245 |
""" |
| 246 |
Test receiving a delete event with a redirect URI. |
| 247 |
""" |
| 248 |
message = domish.Element((None, "message")) |
| 249 |
message["from"] = "pubsub.example.org" |
| 250 |
message["to"] = "[email protected]/home" |
| 251 |
event = message.addElement((NS_PUBSUB_EVENT, "event")) |
| 252 |
delete = event.addElement("delete") |
| 253 |
delete["node"] = "test" |
| 254 |
uri = "xmpp:pubsub.example.org?;node=test2" |
| 255 |
delete.addElement("redirect")["uri"] = uri |
| 256 |
|
| 257 |
def deleteReceived(event): |
| 258 |
self.assertEquals(JID("[email protected]/home"), event.recipient) |
| 259 |
self.assertEquals(JID("pubsub.example.org"), event.sender) |
| 260 |
self.assertEquals("test", event.nodeIdentifier) |
| 261 |
self.assertEquals(uri, event.redirectURI) |
| 262 |
|
| 263 |
d, self.protocol.deleteReceived = calledAsync(deleteReceived) |
| 264 |
self.stub.send(message) |
| 265 |
return d |
| 266 |
|
| 267 |
def test_event_purge(self): |
| 268 |
""" |
| 269 |
Test receiving a purge event resulting in a call to purgeReceived. |
| 270 |
""" |
| 271 |
message = domish.Element((None, "message")) |
| 272 |
message["from"] = "pubsub.example.org" |
| 273 |
message["to"] = "[email protected]/home" |
| 274 |
event = message.addElement((NS_PUBSUB_EVENT, "event")) |
| 275 |
items = event.addElement("purge") |
| 276 |
items["node"] = "test" |
| 277 |
|
| 278 |
def purgeReceived(event): |
| 279 |
self.assertEquals(JID("[email protected]/home"), event.recipient) |
| 280 |
self.assertEquals(JID("pubsub.example.org"), event.sender) |
| 281 |
self.assertEquals("test", event.nodeIdentifier) |
| 282 |
|
| 283 |
d, self.protocol.purgeReceived = calledAsync(purgeReceived) |
| 284 |
self.stub.send(message) |
| 285 |
return d |
| 286 |
|
| 287 |
def test_createNode(self): |
| 288 |
""" |
| 289 |
Test sending create request. |
| 290 |
""" |
| 291 |
|
| 292 |
def cb(nodeIdentifier): |
| 293 |
self.assertEquals("test", nodeIdentifier) |
| 294 |
|
| 295 |
d = self.protocol.createNode(JID("pubsub.example.org"), "test") |
| 296 |
d.addCallback(cb) |
| 297 |
|
| 298 |
iq = self.stub.output[-1] |
| 299 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 300 |
self.assertEquals("set", iq.getAttribute("type")) |
| 301 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 302 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 303 |
children = list( |
| 304 |
domish.generateElementsQNamed(iq.pubsub.children, "create", NS_PUBSUB) |
| 305 |
) |
| 306 |
self.assertEquals(1, len(children)) |
| 307 |
child = children[0] |
| 308 |
self.assertEquals("test", child["node"]) |
| 309 |
|
| 310 |
response = toResponse(iq, "result") |
| 311 |
self.stub.send(response) |
| 312 |
return d |
| 313 |
|
| 314 |
def test_createNodeInstant(self): |
| 315 |
""" |
| 316 |
Test sending create request resulting in an instant node. |
| 317 |
""" |
| 318 |
|
| 319 |
def cb(nodeIdentifier): |
| 320 |
self.assertEquals("test", nodeIdentifier) |
| 321 |
|
| 322 |
d = self.protocol.createNode(JID("pubsub.example.org")) |
| 323 |
d.addCallback(cb) |
| 324 |
|
| 325 |
iq = self.stub.output[-1] |
| 326 |
children = list( |
| 327 |
domish.generateElementsQNamed(iq.pubsub.children, "create", NS_PUBSUB) |
| 328 |
) |
| 329 |
child = children[0] |
| 330 |
self.assertFalse(child.hasAttribute("node")) |
| 331 |
|
| 332 |
response = toResponse(iq, "result") |
| 333 |
command = response.addElement((NS_PUBSUB, "pubsub")) |
| 334 |
create = command.addElement("create") |
| 335 |
create["node"] = "test" |
| 336 |
self.stub.send(response) |
| 337 |
return d |
| 338 |
|
| 339 |
def test_createNodeRenamed(self): |
| 340 |
""" |
| 341 |
Test sending create request resulting in renamed node. |
| 342 |
""" |
| 343 |
|
| 344 |
def cb(nodeIdentifier): |
| 345 |
self.assertEquals("test2", nodeIdentifier) |
| 346 |
|
| 347 |
d = self.protocol.createNode(JID("pubsub.example.org"), "test") |
| 348 |
d.addCallback(cb) |
| 349 |
|
| 350 |
iq = self.stub.output[-1] |
| 351 |
children = list( |
| 352 |
domish.generateElementsQNamed(iq.pubsub.children, "create", NS_PUBSUB) |
| 353 |
) |
| 354 |
child = children[0] |
| 355 |
self.assertEquals("test", child["node"]) |
| 356 |
|
| 357 |
response = toResponse(iq, "result") |
| 358 |
command = response.addElement((NS_PUBSUB, "pubsub")) |
| 359 |
create = command.addElement("create") |
| 360 |
create["node"] = "test2" |
| 361 |
self.stub.send(response) |
| 362 |
return d |
| 363 |
|
| 364 |
def test_createNodeWithSender(self): |
| 365 |
""" |
| 366 |
Test sending create request from a specific JID. |
| 367 |
""" |
| 368 |
|
| 369 |
d = self.protocol.createNode( |
| 370 |
JID("pubsub.example.org"), "test", sender=JID("[email protected]") |
| 371 |
) |
| 372 |
|
| 373 |
iq = self.stub.output[-1] |
| 374 |
self.assertEquals("[email protected]", iq["from"]) |
| 375 |
|
| 376 |
response = toResponse(iq, "result") |
| 377 |
self.stub.send(response) |
| 378 |
return d |
| 379 |
|
| 380 |
def test_createNodeWithConfig(self): |
| 381 |
""" |
| 382 |
Test sending create request with configuration options |
| 383 |
""" |
| 384 |
|
| 385 |
options = { |
| 386 |
"pubsub#title": "Princely Musings (Atom)", |
| 387 |
"pubsub#deliver_payloads": True, |
| 388 |
"pubsub#persist_items": "1", |
| 389 |
"pubsub#max_items": "10", |
| 390 |
"pubsub#access_model": "open", |
| 391 |
"pubsub#type": "http://www.w3.org/2005/Atom", |
| 392 |
} |
| 393 |
|
| 394 |
d = self.protocol.createNode( |
| 395 |
JID("pubsub.example.org"), |
| 396 |
"test", |
| 397 |
sender=JID("[email protected]"), |
| 398 |
options=options, |
| 399 |
) |
| 400 |
|
| 401 |
iq = self.stub.output[-1] |
| 402 |
|
| 403 |
# check if there is exactly one configure element |
| 404 |
children = list( |
| 405 |
domish.generateElementsQNamed(iq.pubsub.children, "configure", NS_PUBSUB) |
| 406 |
) |
| 407 |
self.assertEqual(1, len(children)) |
| 408 |
|
| 409 |
# check that it has a configuration form |
| 410 |
form = data_form.findForm(children[0], NS_PUBSUB_NODE_CONFIG) |
| 411 |
self.assertEqual("submit", form.formType) |
| 412 |
|
| 413 |
response = toResponse(iq, "result") |
| 414 |
self.stub.send(response) |
| 415 |
return d |
| 416 |
|
| 417 |
def test_deleteNode(self): |
| 418 |
""" |
| 419 |
Test sending delete request. |
| 420 |
""" |
| 421 |
|
| 422 |
d = self.protocol.deleteNode(JID("pubsub.example.org"), "test") |
| 423 |
|
| 424 |
iq = self.stub.output[-1] |
| 425 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 426 |
self.assertEquals("set", iq.getAttribute("type")) |
| 427 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 428 |
self.assertEquals(NS_PUBSUB_OWNER, iq.pubsub.uri) |
| 429 |
children = list( |
| 430 |
domish.generateElementsQNamed(iq.pubsub.children, "delete", NS_PUBSUB_OWNER) |
| 431 |
) |
| 432 |
self.assertEquals(1, len(children)) |
| 433 |
child = children[0] |
| 434 |
self.assertEquals("test", child["node"]) |
| 435 |
|
| 436 |
response = toResponse(iq, "result") |
| 437 |
self.stub.send(response) |
| 438 |
return d |
| 439 |
|
| 440 |
def test_deleteNodeWithSender(self): |
| 441 |
""" |
| 442 |
Test sending delete request. |
| 443 |
""" |
| 444 |
|
| 445 |
d = self.protocol.deleteNode( |
| 446 |
JID("pubsub.example.org"), "test", sender=JID("[email protected]") |
| 447 |
) |
| 448 |
|
| 449 |
iq = self.stub.output[-1] |
| 450 |
self.assertEquals("[email protected]", iq["from"]) |
| 451 |
|
| 452 |
response = toResponse(iq, "result") |
| 453 |
self.stub.send(response) |
| 454 |
return d |
| 455 |
|
| 456 |
def test_publish(self): |
| 457 |
""" |
| 458 |
Test sending publish request. |
| 459 |
""" |
| 460 |
|
| 461 |
item = pubsub.Item() |
| 462 |
d = self.protocol.publish(JID("pubsub.example.org"), "test", [item]) |
| 463 |
|
| 464 |
iq = self.stub.output[-1] |
| 465 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 466 |
self.assertEquals("set", iq.getAttribute("type")) |
| 467 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 468 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 469 |
children = list( |
| 470 |
domish.generateElementsQNamed(iq.pubsub.children, "publish", NS_PUBSUB) |
| 471 |
) |
| 472 |
self.assertEquals(1, len(children)) |
| 473 |
child = children[0] |
| 474 |
self.assertEquals("test", child["node"]) |
| 475 |
items = list(domish.generateElementsQNamed(child.children, "item", NS_PUBSUB)) |
| 476 |
self.assertEquals(1, len(items)) |
| 477 |
self.assertIdentical(item, items[0]) |
| 478 |
|
| 479 |
response = toResponse(iq, "result") |
| 480 |
self.stub.send(response) |
| 481 |
return d |
| 482 |
|
| 483 |
def test_publishNoItems(self): |
| 484 |
""" |
| 485 |
Test sending publish request without items. |
| 486 |
""" |
| 487 |
|
| 488 |
d = self.protocol.publish(JID("pubsub.example.org"), "test") |
| 489 |
|
| 490 |
iq = self.stub.output[-1] |
| 491 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 492 |
self.assertEquals("set", iq.getAttribute("type")) |
| 493 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 494 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 495 |
children = list( |
| 496 |
domish.generateElementsQNamed(iq.pubsub.children, "publish", NS_PUBSUB) |
| 497 |
) |
| 498 |
self.assertEquals(1, len(children)) |
| 499 |
child = children[0] |
| 500 |
self.assertEquals("test", child["node"]) |
| 501 |
|
| 502 |
response = toResponse(iq, "result") |
| 503 |
self.stub.send(response) |
| 504 |
return d |
| 505 |
|
| 506 |
def test_publishWithSender(self): |
| 507 |
""" |
| 508 |
Test sending publish request from a specific JID. |
| 509 |
""" |
| 510 |
|
| 511 |
item = pubsub.Item() |
| 512 |
d = self.protocol.publish( |
| 513 |
JID("pubsub.example.org"), "test", [item], JID("[email protected]") |
| 514 |
) |
| 515 |
|
| 516 |
iq = self.stub.output[-1] |
| 517 |
self.assertEquals("[email protected]", iq["from"]) |
| 518 |
|
| 519 |
response = toResponse(iq, "result") |
| 520 |
self.stub.send(response) |
| 521 |
return d |
| 522 |
|
| 523 |
def test_subscribe(self): |
| 524 |
""" |
| 525 |
Test sending subscription request. |
| 526 |
""" |
| 527 |
d = self.protocol.subscribe( |
| 528 |
JID("pubsub.example.org"), "test", JID("[email protected]") |
| 529 |
) |
| 530 |
|
| 531 |
iq = self.stub.output[-1] |
| 532 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 533 |
self.assertEquals("set", iq.getAttribute("type")) |
| 534 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 535 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 536 |
children = list( |
| 537 |
domish.generateElementsQNamed(iq.pubsub.children, "subscribe", NS_PUBSUB) |
| 538 |
) |
| 539 |
self.assertEquals(1, len(children)) |
| 540 |
child = children[0] |
| 541 |
self.assertEquals("test", child["node"]) |
| 542 |
self.assertEquals("[email protected]", child["jid"]) |
| 543 |
|
| 544 |
response = toResponse(iq, "result") |
| 545 |
pubsub = response.addElement((NS_PUBSUB, "pubsub")) |
| 546 |
subscription = pubsub.addElement("subscription") |
| 547 |
subscription["node"] = "test" |
| 548 |
subscription["jid"] = "[email protected]" |
| 549 |
subscription["subscription"] = "subscribed" |
| 550 |
self.stub.send(response) |
| 551 |
return d |
| 552 |
|
| 553 |
def test_subscribeReturnsSubscription(self): |
| 554 |
""" |
| 555 |
A successful subscription should return a Subscription instance. |
| 556 |
""" |
| 557 |
|
| 558 |
def cb(subscription): |
| 559 |
self.assertEqual(JID("[email protected]"), subscription.subscriber) |
| 560 |
|
| 561 |
d = self.protocol.subscribe( |
| 562 |
JID("pubsub.example.org"), "test", JID("[email protected]") |
| 563 |
) |
| 564 |
d.addCallback(cb) |
| 565 |
|
| 566 |
iq = self.stub.output[-1] |
| 567 |
|
| 568 |
response = toResponse(iq, "result") |
| 569 |
pubsub = response.addElement((NS_PUBSUB, "pubsub")) |
| 570 |
subscription = pubsub.addElement("subscription") |
| 571 |
subscription["node"] = "test" |
| 572 |
subscription["jid"] = "[email protected]" |
| 573 |
subscription["subscription"] = "subscribed" |
| 574 |
self.stub.send(response) |
| 575 |
return d |
| 576 |
|
| 577 |
def test_subscribePending(self): |
| 578 |
""" |
| 579 |
Test sending subscription request that results in a pending |
| 580 |
subscription. |
| 581 |
""" |
| 582 |
d = self.protocol.subscribe( |
| 583 |
JID("pubsub.example.org"), "test", JID("[email protected]") |
| 584 |
) |
| 585 |
|
| 586 |
iq = self.stub.output[-1] |
| 587 |
response = toResponse(iq, "result") |
| 588 |
command = response.addElement((NS_PUBSUB, "pubsub")) |
| 589 |
subscription = command.addElement("subscription") |
| 590 |
subscription["node"] = "test" |
| 591 |
subscription["jid"] = "[email protected]" |
| 592 |
subscription["subscription"] = "pending" |
| 593 |
self.stub.send(response) |
| 594 |
self.assertFailure(d, pubsub.SubscriptionPending) |
| 595 |
return d |
| 596 |
|
| 597 |
def test_subscribeUnconfigured(self): |
| 598 |
""" |
| 599 |
Test sending subscription request that results in an unconfigured |
| 600 |
subscription. |
| 601 |
""" |
| 602 |
d = self.protocol.subscribe( |
| 603 |
JID("pubsub.example.org"), "test", JID("[email protected]") |
| 604 |
) |
| 605 |
|
| 606 |
iq = self.stub.output[-1] |
| 607 |
response = toResponse(iq, "result") |
| 608 |
command = response.addElement((NS_PUBSUB, "pubsub")) |
| 609 |
subscription = command.addElement("subscription") |
| 610 |
subscription["node"] = "test" |
| 611 |
subscription["jid"] = "[email protected]" |
| 612 |
subscription["subscription"] = "unconfigured" |
| 613 |
self.stub.send(response) |
| 614 |
self.assertFailure(d, pubsub.SubscriptionUnconfigured) |
| 615 |
return d |
| 616 |
|
| 617 |
def test_subscribeWithOptions(self): |
| 618 |
options = {"pubsub#deliver": False} |
| 619 |
|
| 620 |
d = self.protocol.subscribe( |
| 621 |
JID("pubsub.example.org"), "test", JID("[email protected]"), options=options |
| 622 |
) |
| 623 |
iq = self.stub.output[-1] |
| 624 |
|
| 625 |
# Check options present |
| 626 |
childNames = [] |
| 627 |
for element in iq.pubsub.elements(): |
| 628 |
if element.uri == NS_PUBSUB: |
| 629 |
childNames.append(element.name) |
| 630 |
|
| 631 |
self.assertEqual(["subscribe", "options"], childNames) |
| 632 |
form = data_form.findForm(iq.pubsub.options, NS_PUBSUB_SUBSCRIBE_OPTIONS) |
| 633 |
self.assertEqual("submit", form.formType) |
| 634 |
form.typeCheck({"pubsub#deliver": {"type": "boolean"}}) |
| 635 |
self.assertEqual(options, form.getValues()) |
| 636 |
|
| 637 |
# Send response |
| 638 |
response = toResponse(iq, "result") |
| 639 |
pubsub = response.addElement((NS_PUBSUB, "pubsub")) |
| 640 |
subscription = pubsub.addElement("subscription") |
| 641 |
subscription["node"] = "test" |
| 642 |
subscription["jid"] = "[email protected]" |
| 643 |
subscription["subscription"] = "subscribed" |
| 644 |
self.stub.send(response) |
| 645 |
|
| 646 |
return d |
| 647 |
|
| 648 |
def test_subscribeWithSender(self): |
| 649 |
""" |
| 650 |
Test sending subscription request from a specific JID. |
| 651 |
""" |
| 652 |
d = self.protocol.subscribe( |
| 653 |
JID("pubsub.example.org"), |
| 654 |
"test", |
| 655 |
JID("[email protected]"), |
| 656 |
sender=JID("[email protected]"), |
| 657 |
) |
| 658 |
|
| 659 |
iq = self.stub.output[-1] |
| 660 |
self.assertEquals("[email protected]", iq["from"]) |
| 661 |
|
| 662 |
response = toResponse(iq, "result") |
| 663 |
pubsub = response.addElement((NS_PUBSUB, "pubsub")) |
| 664 |
subscription = pubsub.addElement("subscription") |
| 665 |
subscription["node"] = "test" |
| 666 |
subscription["jid"] = "[email protected]" |
| 667 |
subscription["subscription"] = "subscribed" |
| 668 |
self.stub.send(response) |
| 669 |
return d |
| 670 |
|
| 671 |
def test_subscribeReturningSubscriptionIdentifier(self): |
| 672 |
""" |
| 673 |
Test sending subscription request with subscription identifier. |
| 674 |
""" |
| 675 |
|
| 676 |
def cb(subscription): |
| 677 |
self.assertEqual("1234", subscription.subscriptionIdentifier) |
| 678 |
|
| 679 |
d = self.protocol.subscribe( |
| 680 |
JID("pubsub.example.org"), "test", JID("[email protected]") |
| 681 |
) |
| 682 |
d.addCallback(cb) |
| 683 |
|
| 684 |
iq = self.stub.output[-1] |
| 685 |
|
| 686 |
response = toResponse(iq, "result") |
| 687 |
pubsub = response.addElement((NS_PUBSUB, "pubsub")) |
| 688 |
subscription = pubsub.addElement("subscription") |
| 689 |
subscription["node"] = "test" |
| 690 |
subscription["jid"] = "[email protected]" |
| 691 |
subscription["subscription"] = "subscribed" |
| 692 |
subscription["subid"] = "1234" |
| 693 |
self.stub.send(response) |
| 694 |
return d |
| 695 |
|
| 696 |
def test_unsubscribe(self): |
| 697 |
""" |
| 698 |
Test sending unsubscription request. |
| 699 |
""" |
| 700 |
d = self.protocol.unsubscribe( |
| 701 |
JID("pubsub.example.org"), "test", JID("[email protected]") |
| 702 |
) |
| 703 |
|
| 704 |
iq = self.stub.output[-1] |
| 705 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 706 |
self.assertEquals("set", iq.getAttribute("type")) |
| 707 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 708 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 709 |
children = list( |
| 710 |
domish.generateElementsQNamed(iq.pubsub.children, "unsubscribe", NS_PUBSUB) |
| 711 |
) |
| 712 |
self.assertEquals(1, len(children)) |
| 713 |
child = children[0] |
| 714 |
self.assertEquals("test", child["node"]) |
| 715 |
self.assertEquals("[email protected]", child["jid"]) |
| 716 |
|
| 717 |
self.stub.send(toResponse(iq, "result")) |
| 718 |
return d |
| 719 |
|
| 720 |
def test_unsubscribeWithSender(self): |
| 721 |
""" |
| 722 |
Test sending unsubscription request from a specific JID. |
| 723 |
""" |
| 724 |
d = self.protocol.unsubscribe( |
| 725 |
JID("pubsub.example.org"), |
| 726 |
"test", |
| 727 |
JID("[email protected]"), |
| 728 |
sender=JID("[email protected]"), |
| 729 |
) |
| 730 |
|
| 731 |
iq = self.stub.output[-1] |
| 732 |
self.assertEquals("[email protected]", iq["from"]) |
| 733 |
self.stub.send(toResponse(iq, "result")) |
| 734 |
return d |
| 735 |
|
| 736 |
def test_unsubscribeWithSubscriptionIdentifier(self): |
| 737 |
""" |
| 738 |
Test sending unsubscription request with subscription identifier. |
| 739 |
""" |
| 740 |
d = self.protocol.unsubscribe( |
| 741 |
JID("pubsub.example.org"), |
| 742 |
"test", |
| 743 |
JID("[email protected]"), |
| 744 |
subscriptionIdentifier="1234", |
| 745 |
) |
| 746 |
|
| 747 |
iq = self.stub.output[-1] |
| 748 |
child = iq.pubsub.unsubscribe |
| 749 |
self.assertEquals("1234", child["subid"]) |
| 750 |
|
| 751 |
self.stub.send(toResponse(iq, "result")) |
| 752 |
return d |
| 753 |
|
| 754 |
def test_items(self): |
| 755 |
""" |
| 756 |
Test sending items request. |
| 757 |
""" |
| 758 |
|
| 759 |
def cb(items): |
| 760 |
self.assertEquals([], items) |
| 761 |
|
| 762 |
d = self.protocol.items(JID("pubsub.example.org"), "test") |
| 763 |
d.addCallback(cb) |
| 764 |
|
| 765 |
iq = self.stub.output[-1] |
| 766 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 767 |
self.assertEquals("get", iq.getAttribute("type")) |
| 768 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 769 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 770 |
children = list( |
| 771 |
domish.generateElementsQNamed(iq.pubsub.children, "items", NS_PUBSUB) |
| 772 |
) |
| 773 |
self.assertEquals(1, len(children)) |
| 774 |
child = children[0] |
| 775 |
self.assertEquals("test", child["node"]) |
| 776 |
|
| 777 |
response = toResponse(iq, "result") |
| 778 |
items = response.addElement((NS_PUBSUB, "pubsub")).addElement("items") |
| 779 |
items["node"] = "test" |
| 780 |
|
| 781 |
self.stub.send(response) |
| 782 |
|
| 783 |
return d |
| 784 |
|
| 785 |
def test_itemsMaxItems(self): |
| 786 |
""" |
| 787 |
Test sending items request, with limit on the number of items. |
| 788 |
""" |
| 789 |
|
| 790 |
def cb(items): |
| 791 |
self.assertEquals(2, len(items)) |
| 792 |
self.assertEquals([item1, item2], items) |
| 793 |
|
| 794 |
d = self.protocol.items(JID("pubsub.example.org"), "test", maxItems=2) |
| 795 |
d.addCallback(cb) |
| 796 |
|
| 797 |
iq = self.stub.output[-1] |
| 798 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 799 |
self.assertEquals("get", iq.getAttribute("type")) |
| 800 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 801 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 802 |
children = list( |
| 803 |
domish.generateElementsQNamed(iq.pubsub.children, "items", NS_PUBSUB) |
| 804 |
) |
| 805 |
self.assertEquals(1, len(children)) |
| 806 |
child = children[0] |
| 807 |
self.assertEquals("test", child["node"]) |
| 808 |
self.assertEquals("2", child["max_items"]) |
| 809 |
|
| 810 |
response = toResponse(iq, "result") |
| 811 |
items = response.addElement((NS_PUBSUB, "pubsub")).addElement("items") |
| 812 |
items["node"] = "test" |
| 813 |
item1 = items.addElement("item") |
| 814 |
item1["id"] = "item1" |
| 815 |
item2 = items.addElement("item") |
| 816 |
item2["id"] = "item2" |
| 817 |
|
| 818 |
self.stub.send(response) |
| 819 |
|
| 820 |
return d |
| 821 |
|
| 822 |
def test_itemsWithItemIdentifiers(self): |
| 823 |
""" |
| 824 |
Test sending items request with item identifiers. |
| 825 |
""" |
| 826 |
|
| 827 |
def cb(items): |
| 828 |
self.assertEquals(2, len(items)) |
| 829 |
self.assertEquals([item1, item2], items) |
| 830 |
|
| 831 |
d = self.protocol.items( |
| 832 |
JID("pubsub.example.org"), "test", itemIdentifiers=["item1", "item2"] |
| 833 |
) |
| 834 |
d.addCallback(cb) |
| 835 |
|
| 836 |
iq = self.stub.output[-1] |
| 837 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 838 |
self.assertEquals("get", iq.getAttribute("type")) |
| 839 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 840 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 841 |
children = list( |
| 842 |
domish.generateElementsQNamed(iq.pubsub.children, "items", NS_PUBSUB) |
| 843 |
) |
| 844 |
self.assertEquals(1, len(children)) |
| 845 |
child = children[0] |
| 846 |
self.assertEquals("test", child["node"]) |
| 847 |
itemIdentifiers = [ |
| 848 |
item.getAttribute("id") |
| 849 |
for item in domish.generateElementsQNamed(child.children, "item", NS_PUBSUB) |
| 850 |
] |
| 851 |
self.assertEquals(["item1", "item2"], itemIdentifiers) |
| 852 |
|
| 853 |
response = toResponse(iq, "result") |
| 854 |
items = response.addElement((NS_PUBSUB, "pubsub")).addElement("items") |
| 855 |
items["node"] = "test" |
| 856 |
item1 = items.addElement("item") |
| 857 |
item1["id"] = "item1" |
| 858 |
item2 = items.addElement("item") |
| 859 |
item2["id"] = "item2" |
| 860 |
|
| 861 |
self.stub.send(response) |
| 862 |
|
| 863 |
return d |
| 864 |
|
| 865 |
def test_itemsWithSubscriptionIdentifier(self): |
| 866 |
""" |
| 867 |
Test sending items request with a subscription identifier. |
| 868 |
""" |
| 869 |
|
| 870 |
d = self.protocol.items( |
| 871 |
JID("pubsub.example.org"), "test", subscriptionIdentifier="1234" |
| 872 |
) |
| 873 |
|
| 874 |
iq = self.stub.output[-1] |
| 875 |
child = iq.pubsub.items |
| 876 |
self.assertEquals("1234", child["subid"]) |
| 877 |
|
| 878 |
response = toResponse(iq, "result") |
| 879 |
items = response.addElement((NS_PUBSUB, "pubsub")).addElement("items") |
| 880 |
items["node"] = "test" |
| 881 |
|
| 882 |
self.stub.send(response) |
| 883 |
return d |
| 884 |
|
| 885 |
def test_itemsWithSender(self): |
| 886 |
""" |
| 887 |
Test sending items request from a specific JID. |
| 888 |
""" |
| 889 |
|
| 890 |
d = self.protocol.items( |
| 891 |
JID("pubsub.example.org"), "test", sender=JID("[email protected]") |
| 892 |
) |
| 893 |
|
| 894 |
iq = self.stub.output[-1] |
| 895 |
self.assertEquals("[email protected]", iq["from"]) |
| 896 |
|
| 897 |
response = toResponse(iq, "result") |
| 898 |
items = response.addElement((NS_PUBSUB, "pubsub")).addElement("items") |
| 899 |
items["node"] = "test" |
| 900 |
|
| 901 |
self.stub.send(response) |
| 902 |
return d |
| 903 |
|
| 904 |
def test_retractItems(self): |
| 905 |
""" |
| 906 |
Test sending items retraction. |
| 907 |
""" |
| 908 |
d = self.protocol.retractItems( |
| 909 |
JID("pubsub.example.org"), "test", itemIdentifiers=["item1", "item2"] |
| 910 |
) |
| 911 |
|
| 912 |
iq = self.stub.output[-1] |
| 913 |
self.assertEquals("pubsub.example.org", iq.getAttribute("to")) |
| 914 |
self.assertEquals("set", iq.getAttribute("type")) |
| 915 |
self.assertEquals("pubsub", iq.pubsub.name) |
| 916 |
self.assertEquals(NS_PUBSUB, iq.pubsub.uri) |
| 917 |
children = list( |
| 918 |
domish.generateElementsQNamed(iq.pubsub.children, "retract", NS_PUBSUB) |
| 919 |
) |
| 920 |
self.assertEquals(1, len(children)) |
| 921 |
child = children[0] |
| 922 |
self.assertEquals("test", child["node"]) |
| 923 |
itemIdentifiers = [ |
| 924 |
item.getAttribute("id") |
| 925 |
for item in domish.generateElementsQNamed(child.children, "item", NS_PUBSUB) |
| 926 |
] |
| 927 |
self.assertEquals(["item1", "item2"], itemIdentifiers) |
| 928 |
|
| 929 |
self.stub.send(toResponse(iq, "result")) |
| 930 |
return d |
| 931 |
|
| 932 |
def test_retractItemsWithSender(self): |
| 933 |
""" |
| 934 |
Test retracting items request from a specific JID. |
| 935 |
""" |
| 936 |
d = self.protocol.retractItems( |
| 937 |
JID("pubsub.example.org"), |
| 938 |
"test", |
| 939 |
itemIdentifiers=["item1", "item2"], |
| 940 |
sender=JID("[email protected]"), |
| 941 |
) |
| 942 |
|
| 943 |
iq = self.stub.output[-1] |
| 944 |
self.assertEquals("[email protected]", iq["from"]) |
| 945 |
|
| 946 |
self.stub.send(toResponse(iq, "result")) |
| 947 |
return d |
| 948 |
|
| 949 |
def test_getOptions(self): |
| 950 |
def cb(form): |
| 951 |
self.assertEqual("form", form.formType) |
| 952 |
self.assertEqual(NS_PUBSUB_SUBSCRIBE_OPTIONS, form.formNamespace) |
| 953 |
field = form.fields["pubsub#deliver"] |
| 954 |
self.assertEqual("boolean", field.fieldType) |
| 955 |
self.assertIdentical(True, field.value) |
| 956 |
self.assertEqual("Enable delivery?", field.label) |
| 957 |
|
| 958 |
d = self.protocol.getOptions( |
| 959 |
JID("pubsub.example.org"), |
| 960 |
"test", |
| 961 |
JID("[email protected]"), |
| 962 |
sender=JID("[email protected]"), |
| 963 |
) |
| 964 |
d.addCallback(cb) |
| 965 |
|
| 966 |
iq = self.stub.output[-1] |
| 967 |
self.assertEqual("pubsub.example.org", iq.getAttribute("to")) |
| 968 |
self.assertEqual("get", iq.getAttribute("type")) |
| 969 |
self.assertEqual("pubsub", iq.pubsub.name) |
| 970 |
self.assertEqual(NS_PUBSUB, iq.pubsub.uri) |
| 971 |
children = list( |
| 972 |
domish.generateElementsQNamed(iq.pubsub.children, "options", NS_PUBSUB) |
| 973 |
) |
| 974 |
self.assertEqual(1, len(children)) |
| 975 |
child = children[0] |
| 976 |
self.assertEqual("test", child["node"]) |
| 977 |
|
| 978 |
self.assertEqual(0, len(child.children)) |
| 979 |
|
| 980 |
# Send response |
| 981 |
form = data_form.Form("form", formNamespace=NS_PUBSUB_SUBSCRIBE_OPTIONS) |
| 982 |
form.addField( |
| 983 |
data_form.Field( |
| 984 |
"boolean", var="pubsub#deliver", label="Enable delivery?", value=True |
| 985 |
) |
| 986 |
) |
| 987 |
response = toResponse(iq, "result") |
| 988 |
response.addElement((NS_PUBSUB, "pubsub")) |
| 989 |
response.pubsub.addElement("options") |
| 990 |
response.pubsub.options.addChild(form.toElement()) |
| 991 |
self.stub.send(response) |
| 992 |
|
| 993 |
return d |
| 994 |
|
| 995 |
def test_getOptionsWithSubscriptionIdentifier(self): |
| 996 |
""" |
| 997 |
Getting options with a subid should have the subid in the request. |
| 998 |
""" |
| 999 |
|
| 1000 |
d = self.protocol.getOptions( |
| 1001 |
JID("pubsub.example.org"), |
| 1002 |
"test", |
| 1003 |
JID("[email protected]"), |
| 1004 |
sender=JID("[email protected]"), |
| 1005 |
subscriptionIdentifier="1234", |
| 1006 |
) |
| 1007 |
|
| 1008 |
iq = self.stub.output[-1] |
| 1009 |
child = iq.pubsub.options |
| 1010 |
self.assertEqual("1234", child["subid"]) |
| 1011 |
|
| 1012 |
# Send response |
| 1013 |
form = data_form.Form("form", formNamespace=NS_PUBSUB_SUBSCRIBE_OPTIONS) |
| 1014 |
form.addField( |
| 1015 |
data_form.Field( |
| 1016 |
"boolean", var="pubsub#deliver", label="Enable delivery?", value=True |
| 1017 |
) |
| 1018 |
) |
| 1019 |
response = toResponse(iq, "result") |
| 1020 |
response.addElement((NS_PUBSUB, "pubsub")) |
| 1021 |
response.pubsub.addElement("options") |
| 1022 |
response.pubsub.options.addChild(form.toElement()) |
| 1023 |
self.stub.send(response) |
| 1024 |
|
| 1025 |
return d |
| 1026 |
|
| 1027 |
def test_setOptions(self): |
| 1028 |
""" |
| 1029 |
setOptions should send out a options-set request. |
| 1030 |
""" |
| 1031 |
options = {"pubsub#deliver": False} |
| 1032 |
|
| 1033 |
d = self.protocol.setOptions( |
| 1034 |
JID("pubsub.example.org"), |
| 1035 |
"test", |
| 1036 |
JID("[email protected]"), |
| 1037 |
options, |
| 1038 |
sender=JID("[email protected]"), |
| 1039 |
) |
| 1040 |
|
| 1041 |
iq = self.stub.output[-1] |
| 1042 |
self.assertEqual("pubsub.example.org", iq.getAttribute("to")) |
| 1043 |
self.assertEqual("set", iq.getAttribute("type")) |
| 1044 |
self.assertEqual("pubsub", iq.pubsub.name) |
| 1045 |
self.assertEqual(NS_PUBSUB, iq.pubsub.uri) |
| 1046 |
children = list( |
| 1047 |
domish.generateElementsQNamed(iq.pubsub.children, "options", NS_PUBSUB) |
| 1048 |
) |
| 1049 |
self.assertEqual(1, len(children)) |
| 1050 |
child = children[0] |
| 1051 |
self.assertEqual("test", child["node"]) |
| 1052 |
|
| 1053 |
form = data_form.findForm(child, NS_PUBSUB_SUBSCRIBE_OPTIONS) |
| 1054 |
self.assertEqual("submit", form.formType) |
| 1055 |
form.typeCheck({"pubsub#deliver": {"type": "boolean"}}) |
| 1056 |
self.assertEqual(options, form.getValues()) |
| 1057 |
|
| 1058 |
response = toResponse(iq, "result") |
| 1059 |
self.stub.send(response) |
| 1060 |
|
| 1061 |
return d |
| 1062 |
|
| 1063 |
def test_setOptionsWithSubscriptionIdentifier(self): |
| 1064 |
""" |
| 1065 |
setOptions should send out a options-set request with subid. |
| 1066 |
""" |
| 1067 |
options = {"pubsub#deliver": False} |
| 1068 |
|
| 1069 |
d = self.protocol.setOptions( |
| 1070 |
JID("pubsub.example.org"), |
| 1071 |
"test", |
| 1072 |
JID("[email protected]"), |
| 1073 |
options, |
| 1074 |
subscriptionIdentifier="1234", |
| 1075 |
sender=JID("[email protected]"), |
| 1076 |
) |
| 1077 |
|
| 1078 |
iq = self.stub.output[-1] |
| 1079 |
child = iq.pubsub.options |
| 1080 |
self.assertEqual("1234", child["subid"]) |
| 1081 |
|
| 1082 |
form = data_form.findForm(child, NS_PUBSUB_SUBSCRIBE_OPTIONS) |
| 1083 |
self.assertEqual("submit", form.formType) |
| 1084 |
form.typeCheck({"pubsub#deliver": {"type": "boolean"}}) |
| 1085 |
self.assertEqual(options, form.getValues()) |
| 1086 |
|
| 1087 |
response = toResponse(iq, "result") |
| 1088 |
self.stub.send(response) |
| 1089 |
|
| 1090 |
return d |
| 1091 |
|
| 1092 |
|
| 1093 |
class PubSubRequestTest(unittest.TestCase): |
| 1094 |
|
| 1095 |
def test_fromElementUnknown(self): |
| 1096 |
""" |
| 1097 |
An unknown verb raises NotImplementedError. |
| 1098 |
""" |
| 1099 |
|
| 1100 |
xml = """ |
| 1101 |
<iq type='set' to='pubsub.example.org' |
| 1102 |
from='[email protected]'> |
| 1103 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1104 |
<non-existing-verb/> |
| 1105 |
</pubsub> |
| 1106 |
</iq> |
| 1107 |
""" |
| 1108 |
|
| 1109 |
self.assertRaises( |
| 1110 |
NotImplementedError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1111 |
) |
| 1112 |
|
| 1113 |
def test_fromElementKnownBadCombination(self): |
| 1114 |
""" |
| 1115 |
Multiple verbs in an unknown configuration raises NotImplementedError. |
| 1116 |
""" |
| 1117 |
|
| 1118 |
xml = """ |
| 1119 |
<iq type='set' to='pubsub.example.org' |
| 1120 |
from='[email protected]'> |
| 1121 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1122 |
<publish/> |
| 1123 |
<create/> |
| 1124 |
</pubsub> |
| 1125 |
</iq> |
| 1126 |
""" |
| 1127 |
|
| 1128 |
self.assertRaises( |
| 1129 |
NotImplementedError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1130 |
) |
| 1131 |
|
| 1132 |
def test_fromElementPublish(self): |
| 1133 |
""" |
| 1134 |
Test parsing a publish request. |
| 1135 |
""" |
| 1136 |
|
| 1137 |
xml = """ |
| 1138 |
<iq type='set' to='pubsub.example.org' |
| 1139 |
from='[email protected]'> |
| 1140 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1141 |
<publish node='test'/> |
| 1142 |
</pubsub> |
| 1143 |
</iq> |
| 1144 |
""" |
| 1145 |
|
| 1146 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1147 |
self.assertEqual("publish", request.verb) |
| 1148 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1149 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1150 |
self.assertEqual("test", request.nodeIdentifier) |
| 1151 |
self.assertEqual([], request.items) |
| 1152 |
|
| 1153 |
def test_fromElementPublishItems(self): |
| 1154 |
""" |
| 1155 |
Test parsing a publish request with items. |
| 1156 |
""" |
| 1157 |
|
| 1158 |
xml = """ |
| 1159 |
<iq type='set' to='pubsub.example.org' |
| 1160 |
from='[email protected]'> |
| 1161 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1162 |
<publish node='test'> |
| 1163 |
<item id="item1"/> |
| 1164 |
<item id="item2"/> |
| 1165 |
</publish> |
| 1166 |
</pubsub> |
| 1167 |
</iq> |
| 1168 |
""" |
| 1169 |
|
| 1170 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1171 |
self.assertEqual(2, len(request.items)) |
| 1172 |
self.assertEqual("item1", request.items[0]["id"]) |
| 1173 |
self.assertEqual("item2", request.items[1]["id"]) |
| 1174 |
|
| 1175 |
def test_fromElementPublishItemsOptions(self): |
| 1176 |
""" |
| 1177 |
Test parsing a publish request with items and options. |
| 1178 |
|
| 1179 |
Note that publishing options are not supported, but passing them |
| 1180 |
shouldn't affect processing of the publish request itself. |
| 1181 |
""" |
| 1182 |
|
| 1183 |
xml = """ |
| 1184 |
<iq type='set' to='pubsub.example.org' |
| 1185 |
from='[email protected]'> |
| 1186 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1187 |
<publish node='test'> |
| 1188 |
<item id="item1"/> |
| 1189 |
<item id="item2"/> |
| 1190 |
</publish> |
| 1191 |
<publish-options/> |
| 1192 |
</pubsub> |
| 1193 |
</iq> |
| 1194 |
""" |
| 1195 |
|
| 1196 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1197 |
self.assertEqual(2, len(request.items)) |
| 1198 |
self.assertEqual("item1", request.items[0]["id"]) |
| 1199 |
self.assertEqual("item2", request.items[1]["id"]) |
| 1200 |
|
| 1201 |
def test_fromElementPublishNoNode(self): |
| 1202 |
""" |
| 1203 |
A publish request to the root node should raise an exception. |
| 1204 |
""" |
| 1205 |
xml = """ |
| 1206 |
<iq type='set' to='pubsub.example.org' |
| 1207 |
from='[email protected]'> |
| 1208 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1209 |
<publish/> |
| 1210 |
</pubsub> |
| 1211 |
</iq> |
| 1212 |
""" |
| 1213 |
|
| 1214 |
err = self.assertRaises( |
| 1215 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1216 |
) |
| 1217 |
self.assertEqual("bad-request", err.condition) |
| 1218 |
self.assertEqual(NS_PUBSUB_ERRORS, err.appCondition.uri) |
| 1219 |
self.assertEqual("nodeid-required", err.appCondition.name) |
| 1220 |
|
| 1221 |
def test_fromElementSubscribe(self): |
| 1222 |
""" |
| 1223 |
Test parsing a subscription request. |
| 1224 |
""" |
| 1225 |
|
| 1226 |
xml = """ |
| 1227 |
<iq type='set' to='pubsub.example.org' |
| 1228 |
from='[email protected]'> |
| 1229 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1230 |
<subscribe node='test' jid='[email protected]/Home'/> |
| 1231 |
</pubsub> |
| 1232 |
</iq> |
| 1233 |
""" |
| 1234 |
|
| 1235 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1236 |
self.assertEqual("subscribe", request.verb) |
| 1237 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1238 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1239 |
self.assertEqual("test", request.nodeIdentifier) |
| 1240 |
self.assertEqual(JID("[email protected]/Home"), request.subscriber) |
| 1241 |
|
| 1242 |
def test_fromElementSubscribeEmptyNode(self): |
| 1243 |
""" |
| 1244 |
Test parsing a subscription request to the root node. |
| 1245 |
""" |
| 1246 |
|
| 1247 |
xml = """ |
| 1248 |
<iq type='set' to='pubsub.example.org' |
| 1249 |
from='[email protected]'> |
| 1250 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1251 |
<subscribe jid='[email protected]/Home'/> |
| 1252 |
</pubsub> |
| 1253 |
</iq> |
| 1254 |
""" |
| 1255 |
|
| 1256 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1257 |
self.assertEqual("", request.nodeIdentifier) |
| 1258 |
|
| 1259 |
def test_fromElementSubscribeNoJID(self): |
| 1260 |
""" |
| 1261 |
Subscribe requests without a JID should raise a bad-request exception. |
| 1262 |
""" |
| 1263 |
xml = """ |
| 1264 |
<iq type='set' to='pubsub.example.org' |
| 1265 |
from='[email protected]'> |
| 1266 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1267 |
<subscribe node='test'/> |
| 1268 |
</pubsub> |
| 1269 |
</iq> |
| 1270 |
""" |
| 1271 |
err = self.assertRaises( |
| 1272 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1273 |
) |
| 1274 |
self.assertEqual("bad-request", err.condition) |
| 1275 |
self.assertEqual(NS_PUBSUB_ERRORS, err.appCondition.uri) |
| 1276 |
self.assertEqual("jid-required", err.appCondition.name) |
| 1277 |
|
| 1278 |
def test_fromElementSubscribeWithOptions(self): |
| 1279 |
""" |
| 1280 |
Test parsing a subscription request. |
| 1281 |
""" |
| 1282 |
|
| 1283 |
xml = """ |
| 1284 |
<iq type='set' to='pubsub.example.org' |
| 1285 |
from='[email protected]'> |
| 1286 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1287 |
<subscribe node='test' jid='[email protected]/Home'/> |
| 1288 |
<options> |
| 1289 |
<x xmlns="jabber:x:data" type='submit'> |
| 1290 |
<field var='FORM_TYPE' type='hidden'> |
| 1291 |
<value>http://jabber.org/protocol/pubsub#subscribe_options</value> |
| 1292 |
</field> |
| 1293 |
<field var='pubsub#deliver' type='boolean' |
| 1294 |
label='Enable delivery?'> |
| 1295 |
<value>1</value> |
| 1296 |
</field> |
| 1297 |
</x> |
| 1298 |
</options> |
| 1299 |
</pubsub> |
| 1300 |
</iq> |
| 1301 |
""" |
| 1302 |
|
| 1303 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1304 |
self.assertEqual("subscribe", request.verb) |
| 1305 |
request.options.typeCheck({"pubsub#deliver": {"type": "boolean"}}) |
| 1306 |
self.assertEqual({"pubsub#deliver": True}, request.options.getValues()) |
| 1307 |
|
| 1308 |
def test_fromElementSubscribeWithOptionsBadFormType(self): |
| 1309 |
""" |
| 1310 |
The options form should have the right type. |
| 1311 |
""" |
| 1312 |
|
| 1313 |
xml = """ |
| 1314 |
<iq type='set' to='pubsub.example.org' |
| 1315 |
from='[email protected]'> |
| 1316 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1317 |
<subscribe node='test' jid='[email protected]/Home'/> |
| 1318 |
<options> |
| 1319 |
<x xmlns="jabber:x:data" type='result'> |
| 1320 |
<field var='FORM_TYPE' type='hidden'> |
| 1321 |
<value>http://jabber.org/protocol/pubsub#subscribe_options</value> |
| 1322 |
</field> |
| 1323 |
<field var='pubsub#deliver' type='boolean' |
| 1324 |
label='Enable delivery?'> |
| 1325 |
<value>1</value> |
| 1326 |
</field> |
| 1327 |
</x> |
| 1328 |
</options> |
| 1329 |
</pubsub> |
| 1330 |
</iq> |
| 1331 |
""" |
| 1332 |
|
| 1333 |
err = self.assertRaises( |
| 1334 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1335 |
) |
| 1336 |
self.assertEqual("bad-request", err.condition) |
| 1337 |
self.assertEqual("Unexpected form type 'result'", err.text) |
| 1338 |
self.assertEqual(None, err.appCondition) |
| 1339 |
|
| 1340 |
def test_fromElementSubscribeWithOptionsEmpty(self): |
| 1341 |
""" |
| 1342 |
When no (suitable) form is found, the options are empty. |
| 1343 |
""" |
| 1344 |
|
| 1345 |
xml = """ |
| 1346 |
<iq type='set' to='pubsub.example.org' |
| 1347 |
from='[email protected]'> |
| 1348 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1349 |
<subscribe node='test' jid='[email protected]/Home'/> |
| 1350 |
<options/> |
| 1351 |
</pubsub> |
| 1352 |
</iq> |
| 1353 |
""" |
| 1354 |
|
| 1355 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1356 |
self.assertEqual("subscribe", request.verb) |
| 1357 |
self.assertEqual({}, request.options.getValues()) |
| 1358 |
|
| 1359 |
def test_fromElementUnsubscribe(self): |
| 1360 |
""" |
| 1361 |
Test parsing an unsubscription request. |
| 1362 |
""" |
| 1363 |
|
| 1364 |
xml = """ |
| 1365 |
<iq type='set' to='pubsub.example.org' |
| 1366 |
from='[email protected]'> |
| 1367 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1368 |
<unsubscribe node='test' jid='[email protected]/Home'/> |
| 1369 |
</pubsub> |
| 1370 |
</iq> |
| 1371 |
""" |
| 1372 |
|
| 1373 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1374 |
self.assertEqual("unsubscribe", request.verb) |
| 1375 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1376 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1377 |
self.assertEqual("test", request.nodeIdentifier) |
| 1378 |
self.assertEqual(JID("[email protected]/Home"), request.subscriber) |
| 1379 |
|
| 1380 |
def test_fromElementUnsubscribeWithSubscriptionIdentifier(self): |
| 1381 |
""" |
| 1382 |
Test parsing an unsubscription request with subscription identifier. |
| 1383 |
""" |
| 1384 |
|
| 1385 |
xml = """ |
| 1386 |
<iq type='set' to='pubsub.example.org' |
| 1387 |
from='[email protected]'> |
| 1388 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1389 |
<unsubscribe node='test' jid='[email protected]/Home' |
| 1390 |
subid='1234'/> |
| 1391 |
</pubsub> |
| 1392 |
</iq> |
| 1393 |
""" |
| 1394 |
|
| 1395 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1396 |
self.assertEqual("1234", request.subscriptionIdentifier) |
| 1397 |
|
| 1398 |
def test_fromElementUnsubscribeNoJID(self): |
| 1399 |
""" |
| 1400 |
Unsubscribe requests without a JID should raise a bad-request exception. |
| 1401 |
""" |
| 1402 |
xml = """ |
| 1403 |
<iq type='set' to='pubsub.example.org' |
| 1404 |
from='[email protected]'> |
| 1405 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1406 |
<unsubscribe node='test'/> |
| 1407 |
</pubsub> |
| 1408 |
</iq> |
| 1409 |
""" |
| 1410 |
err = self.assertRaises( |
| 1411 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1412 |
) |
| 1413 |
self.assertEqual("bad-request", err.condition) |
| 1414 |
self.assertEqual(NS_PUBSUB_ERRORS, err.appCondition.uri) |
| 1415 |
self.assertEqual("jid-required", err.appCondition.name) |
| 1416 |
|
| 1417 |
def test_fromElementOptionsGet(self): |
| 1418 |
""" |
| 1419 |
Test parsing a request for getting subscription options. |
| 1420 |
""" |
| 1421 |
|
| 1422 |
xml = """ |
| 1423 |
<iq type='get' to='pubsub.example.org' |
| 1424 |
from='[email protected]'> |
| 1425 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1426 |
<options node='test' jid='[email protected]/Home'/> |
| 1427 |
</pubsub> |
| 1428 |
</iq> |
| 1429 |
""" |
| 1430 |
|
| 1431 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1432 |
self.assertEqual("optionsGet", request.verb) |
| 1433 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1434 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1435 |
self.assertEqual("test", request.nodeIdentifier) |
| 1436 |
self.assertEqual(JID("[email protected]/Home"), request.subscriber) |
| 1437 |
|
| 1438 |
def test_fromElementOptionsGetWithSubscriptionIdentifier(self): |
| 1439 |
""" |
| 1440 |
Test parsing a request for getting subscription options with subid. |
| 1441 |
""" |
| 1442 |
|
| 1443 |
xml = """ |
| 1444 |
<iq type='get' to='pubsub.example.org' |
| 1445 |
from='[email protected]'> |
| 1446 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1447 |
<options node='test' jid='[email protected]/Home' |
| 1448 |
subid='1234'/> |
| 1449 |
</pubsub> |
| 1450 |
</iq> |
| 1451 |
""" |
| 1452 |
|
| 1453 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1454 |
self.assertEqual("1234", request.subscriptionIdentifier) |
| 1455 |
|
| 1456 |
def test_fromElementOptionsSet(self): |
| 1457 |
""" |
| 1458 |
Test parsing a request for setting subscription options. |
| 1459 |
""" |
| 1460 |
|
| 1461 |
xml = """ |
| 1462 |
<iq type='set' to='pubsub.example.org' |
| 1463 |
from='[email protected]'> |
| 1464 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1465 |
<options node='test' jid='[email protected]/Home'> |
| 1466 |
<x xmlns='jabber:x:data' type='submit'> |
| 1467 |
<field var='FORM_TYPE' type='hidden'> |
| 1468 |
<value>http://jabber.org/protocol/pubsub#subscribe_options</value> |
| 1469 |
</field> |
| 1470 |
<field var='pubsub#deliver'><value>1</value></field> |
| 1471 |
</x> |
| 1472 |
</options> |
| 1473 |
</pubsub> |
| 1474 |
</iq> |
| 1475 |
""" |
| 1476 |
|
| 1477 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1478 |
self.assertEqual("optionsSet", request.verb) |
| 1479 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1480 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1481 |
self.assertEqual("test", request.nodeIdentifier) |
| 1482 |
self.assertEqual(JID("[email protected]/Home"), request.subscriber) |
| 1483 |
self.assertEqual({"pubsub#deliver": "1"}, request.options.getValues()) |
| 1484 |
|
| 1485 |
def test_fromElementOptionsSetWithSubscriptionIdentifier(self): |
| 1486 |
""" |
| 1487 |
Test parsing a request for setting subscription options with subid. |
| 1488 |
""" |
| 1489 |
|
| 1490 |
xml = """ |
| 1491 |
<iq type='set' to='pubsub.example.org' |
| 1492 |
from='[email protected]'> |
| 1493 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1494 |
<options node='test' jid='[email protected]/Home' |
| 1495 |
subid='1234'> |
| 1496 |
<x xmlns='jabber:x:data' type='submit'> |
| 1497 |
<field var='FORM_TYPE' type='hidden'> |
| 1498 |
<value>http://jabber.org/protocol/pubsub#subscribe_options</value> |
| 1499 |
</field> |
| 1500 |
<field var='pubsub#deliver'><value>1</value></field> |
| 1501 |
</x> |
| 1502 |
</options> |
| 1503 |
</pubsub> |
| 1504 |
</iq> |
| 1505 |
""" |
| 1506 |
|
| 1507 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1508 |
self.assertEqual("1234", request.subscriptionIdentifier) |
| 1509 |
|
| 1510 |
def test_fromElementOptionsSetCancel(self): |
| 1511 |
""" |
| 1512 |
Test parsing a request for cancelling setting subscription options. |
| 1513 |
""" |
| 1514 |
|
| 1515 |
xml = """ |
| 1516 |
<iq type='set' to='pubsub.example.org' |
| 1517 |
from='[email protected]'> |
| 1518 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1519 |
<options node='test' jid='[email protected]/Home'> |
| 1520 |
<x xmlns='jabber:x:data' type='cancel'/> |
| 1521 |
</options> |
| 1522 |
</pubsub> |
| 1523 |
</iq> |
| 1524 |
""" |
| 1525 |
|
| 1526 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1527 |
self.assertEqual("cancel", request.options.formType) |
| 1528 |
|
| 1529 |
def test_fromElementOptionsSetBadFormType(self): |
| 1530 |
""" |
| 1531 |
On a options set request unknown fields should be ignored. |
| 1532 |
""" |
| 1533 |
|
| 1534 |
xml = """ |
| 1535 |
<iq type='set' to='pubsub.example.org' |
| 1536 |
from='[email protected]'> |
| 1537 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1538 |
<options node='test' jid='[email protected]/Home'> |
| 1539 |
<x xmlns='jabber:x:data' type='result'> |
| 1540 |
<field var='FORM_TYPE' type='hidden'> |
| 1541 |
<value>http://jabber.org/protocol/pubsub#subscribe_options</value> |
| 1542 |
</field> |
| 1543 |
<field var='pubsub#deliver'><value>1</value></field> |
| 1544 |
</x> |
| 1545 |
</options> |
| 1546 |
</pubsub> |
| 1547 |
</iq> |
| 1548 |
""" |
| 1549 |
|
| 1550 |
err = self.assertRaises( |
| 1551 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1552 |
) |
| 1553 |
self.assertEqual("bad-request", err.condition) |
| 1554 |
self.assertEqual("Unexpected form type 'result'", err.text) |
| 1555 |
self.assertEqual(None, err.appCondition) |
| 1556 |
|
| 1557 |
def test_fromElementOptionsSetNoForm(self): |
| 1558 |
""" |
| 1559 |
On a options set request a form is required. |
| 1560 |
""" |
| 1561 |
|
| 1562 |
xml = """ |
| 1563 |
<iq type='set' to='pubsub.example.org' |
| 1564 |
from='[email protected]'> |
| 1565 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1566 |
<options node='test' jid='[email protected]/Home'/> |
| 1567 |
</pubsub> |
| 1568 |
</iq> |
| 1569 |
""" |
| 1570 |
err = self.assertRaises( |
| 1571 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1572 |
) |
| 1573 |
self.assertEqual("bad-request", err.condition) |
| 1574 |
self.assertEqual(None, err.appCondition) |
| 1575 |
|
| 1576 |
def test_fromElementSubscriptions(self): |
| 1577 |
""" |
| 1578 |
Test parsing a request for all subscriptions. |
| 1579 |
""" |
| 1580 |
|
| 1581 |
xml = """ |
| 1582 |
<iq type='get' to='pubsub.example.org' |
| 1583 |
from='[email protected]'> |
| 1584 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1585 |
<subscriptions/> |
| 1586 |
</pubsub> |
| 1587 |
</iq> |
| 1588 |
""" |
| 1589 |
|
| 1590 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1591 |
self.assertEqual("subscriptions", request.verb) |
| 1592 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1593 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1594 |
|
| 1595 |
def test_fromElementAffiliations(self): |
| 1596 |
""" |
| 1597 |
Test parsing a request for all affiliations. |
| 1598 |
""" |
| 1599 |
|
| 1600 |
xml = """ |
| 1601 |
<iq type='get' to='pubsub.example.org' |
| 1602 |
from='[email protected]'> |
| 1603 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1604 |
<affiliations/> |
| 1605 |
</pubsub> |
| 1606 |
</iq> |
| 1607 |
""" |
| 1608 |
|
| 1609 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1610 |
self.assertEqual("affiliations", request.verb) |
| 1611 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1612 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1613 |
|
| 1614 |
def test_fromElementCreate(self): |
| 1615 |
""" |
| 1616 |
Test parsing a request to create a node. |
| 1617 |
""" |
| 1618 |
|
| 1619 |
xml = """ |
| 1620 |
<iq type='set' to='pubsub.example.org' |
| 1621 |
from='[email protected]'> |
| 1622 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1623 |
<create node='mynode'/> |
| 1624 |
</pubsub> |
| 1625 |
</iq> |
| 1626 |
""" |
| 1627 |
|
| 1628 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1629 |
self.assertEqual("create", request.verb) |
| 1630 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1631 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1632 |
self.assertEqual("mynode", request.nodeIdentifier) |
| 1633 |
self.assertIdentical(None, request.options) |
| 1634 |
|
| 1635 |
def test_fromElementCreateInstant(self): |
| 1636 |
""" |
| 1637 |
Test parsing a request to create an instant node. |
| 1638 |
""" |
| 1639 |
|
| 1640 |
xml = """ |
| 1641 |
<iq type='set' to='pubsub.example.org' |
| 1642 |
from='[email protected]'> |
| 1643 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1644 |
<create/> |
| 1645 |
</pubsub> |
| 1646 |
</iq> |
| 1647 |
""" |
| 1648 |
|
| 1649 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1650 |
self.assertIdentical(None, request.nodeIdentifier) |
| 1651 |
|
| 1652 |
def test_fromElementCreateConfigureEmpty(self): |
| 1653 |
""" |
| 1654 |
Test parsing a request to create a node with an empty configuration. |
| 1655 |
""" |
| 1656 |
|
| 1657 |
xml = """ |
| 1658 |
<iq type='set' to='pubsub.example.org' |
| 1659 |
from='[email protected]'> |
| 1660 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1661 |
<create node='mynode'/> |
| 1662 |
<configure/> |
| 1663 |
</pubsub> |
| 1664 |
</iq> |
| 1665 |
""" |
| 1666 |
|
| 1667 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1668 |
self.assertEqual({}, request.options.getValues()) |
| 1669 |
self.assertEqual("mynode", request.nodeIdentifier) |
| 1670 |
|
| 1671 |
def test_fromElementCreateConfigureEmptyWrongOrder(self): |
| 1672 |
""" |
| 1673 |
Test parsing a request to create a node and configure, wrong order. |
| 1674 |
|
| 1675 |
The C{configure} element should come after the C{create} request, |
| 1676 |
but we should accept both orders. |
| 1677 |
""" |
| 1678 |
|
| 1679 |
xml = """ |
| 1680 |
<iq type='set' to='pubsub.example.org' |
| 1681 |
from='[email protected]'> |
| 1682 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1683 |
<configure/> |
| 1684 |
<create node='mynode'/> |
| 1685 |
</pubsub> |
| 1686 |
</iq> |
| 1687 |
""" |
| 1688 |
|
| 1689 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1690 |
self.assertEqual({}, request.options.getValues()) |
| 1691 |
self.assertEqual("mynode", request.nodeIdentifier) |
| 1692 |
|
| 1693 |
def test_fromElementCreateConfigure(self): |
| 1694 |
""" |
| 1695 |
Test parsing a request to create a node. |
| 1696 |
""" |
| 1697 |
|
| 1698 |
xml = """ |
| 1699 |
<iq type='set' to='pubsub.example.org' |
| 1700 |
from='[email protected]'> |
| 1701 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1702 |
<create node='mynode'/> |
| 1703 |
<configure> |
| 1704 |
<x xmlns='jabber:x:data' type='submit'> |
| 1705 |
<field var='FORM_TYPE' type='hidden'> |
| 1706 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 1707 |
</field> |
| 1708 |
<field var='pubsub#access_model'><value>open</value></field> |
| 1709 |
<field var='pubsub#persist_items'><value>0</value></field> |
| 1710 |
</x> |
| 1711 |
</configure> |
| 1712 |
</pubsub> |
| 1713 |
</iq> |
| 1714 |
""" |
| 1715 |
|
| 1716 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1717 |
values = request.options |
| 1718 |
self.assertIn("pubsub#access_model", values) |
| 1719 |
self.assertEqual("open", values["pubsub#access_model"]) |
| 1720 |
self.assertIn("pubsub#persist_items", values) |
| 1721 |
self.assertEqual("0", values["pubsub#persist_items"]) |
| 1722 |
|
| 1723 |
def test_fromElementCreateConfigureBadFormType(self): |
| 1724 |
""" |
| 1725 |
The form of a node creation request should have the right type. |
| 1726 |
""" |
| 1727 |
|
| 1728 |
xml = """ |
| 1729 |
<iq type='set' to='pubsub.example.org' |
| 1730 |
from='[email protected]'> |
| 1731 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1732 |
<create node='mynode'/> |
| 1733 |
<configure> |
| 1734 |
<x xmlns='jabber:x:data' type='result'> |
| 1735 |
<field var='FORM_TYPE' type='hidden'> |
| 1736 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 1737 |
</field> |
| 1738 |
<field var='pubsub#access_model'><value>open</value></field> |
| 1739 |
<field var='pubsub#persist_items'><value>0</value></field> |
| 1740 |
</x> |
| 1741 |
</configure> |
| 1742 |
</pubsub> |
| 1743 |
</iq> |
| 1744 |
""" |
| 1745 |
|
| 1746 |
err = self.assertRaises( |
| 1747 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1748 |
) |
| 1749 |
self.assertEqual("bad-request", err.condition) |
| 1750 |
self.assertEqual("Unexpected form type 'result'", err.text) |
| 1751 |
self.assertEqual(None, err.appCondition) |
| 1752 |
|
| 1753 |
def test_fromElementDefault(self): |
| 1754 |
""" |
| 1755 |
Parsing default node configuration request sets required attributes. |
| 1756 |
|
| 1757 |
Besides C{verb}, C{sender} and C{recipient}, we expect C{nodeType} |
| 1758 |
to be set. If not passed it receives the default C{u'leaf'}. |
| 1759 |
""" |
| 1760 |
|
| 1761 |
xml = """ |
| 1762 |
<iq type='get' to='pubsub.example.org' |
| 1763 |
from='[email protected]'> |
| 1764 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 1765 |
<default/> |
| 1766 |
</pubsub> |
| 1767 |
</iq> |
| 1768 |
""" |
| 1769 |
|
| 1770 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1771 |
self.assertEquals("default", request.verb) |
| 1772 |
self.assertEquals(JID("[email protected]"), request.sender) |
| 1773 |
self.assertEquals(JID("pubsub.example.org"), request.recipient) |
| 1774 |
self.assertEquals("leaf", request.nodeType) |
| 1775 |
|
| 1776 |
def test_fromElementDefaultCollection(self): |
| 1777 |
""" |
| 1778 |
Parsing default request for collection sets nodeType to collection. |
| 1779 |
""" |
| 1780 |
|
| 1781 |
xml = """ |
| 1782 |
<iq type='get' to='pubsub.example.org' |
| 1783 |
from='[email protected]'> |
| 1784 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 1785 |
<default> |
| 1786 |
<x xmlns='jabber:x:data' type='submit'> |
| 1787 |
<field var='FORM_TYPE' type='hidden'> |
| 1788 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 1789 |
</field> |
| 1790 |
<field var='pubsub#node_type'> |
| 1791 |
<value>collection</value> |
| 1792 |
</field> |
| 1793 |
</x> |
| 1794 |
</default> |
| 1795 |
|
| 1796 |
</pubsub> |
| 1797 |
</iq> |
| 1798 |
""" |
| 1799 |
|
| 1800 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1801 |
self.assertEquals("collection", request.nodeType) |
| 1802 |
|
| 1803 |
def test_fromElementConfigureGet(self): |
| 1804 |
""" |
| 1805 |
Test parsing a node configuration get request. |
| 1806 |
""" |
| 1807 |
|
| 1808 |
xml = """ |
| 1809 |
<iq type='get' to='pubsub.example.org' |
| 1810 |
from='[email protected]'> |
| 1811 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 1812 |
<configure node='test'/> |
| 1813 |
</pubsub> |
| 1814 |
</iq> |
| 1815 |
""" |
| 1816 |
|
| 1817 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1818 |
self.assertEqual("configureGet", request.verb) |
| 1819 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1820 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1821 |
self.assertEqual("test", request.nodeIdentifier) |
| 1822 |
|
| 1823 |
def test_fromElementConfigureSet(self): |
| 1824 |
""" |
| 1825 |
On a node configuration set request the Data Form is parsed. |
| 1826 |
""" |
| 1827 |
|
| 1828 |
xml = """ |
| 1829 |
<iq type='set' to='pubsub.example.org' |
| 1830 |
from='[email protected]'> |
| 1831 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 1832 |
<configure node='test'> |
| 1833 |
<x xmlns='jabber:x:data' type='submit'> |
| 1834 |
<field var='FORM_TYPE' type='hidden'> |
| 1835 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 1836 |
</field> |
| 1837 |
<field var='pubsub#deliver_payloads'><value>0</value></field> |
| 1838 |
<field var='pubsub#persist_items'><value>1</value></field> |
| 1839 |
</x> |
| 1840 |
</configure> |
| 1841 |
</pubsub> |
| 1842 |
</iq> |
| 1843 |
""" |
| 1844 |
|
| 1845 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1846 |
self.assertEqual("configureSet", request.verb) |
| 1847 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1848 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1849 |
self.assertEqual("test", request.nodeIdentifier) |
| 1850 |
self.assertEqual( |
| 1851 |
{"pubsub#deliver_payloads": "0", "pubsub#persist_items": "1"}, |
| 1852 |
request.options.getValues(), |
| 1853 |
) |
| 1854 |
|
| 1855 |
def test_fromElementConfigureSetCancel(self): |
| 1856 |
""" |
| 1857 |
The node configuration is cancelled, so no options. |
| 1858 |
""" |
| 1859 |
|
| 1860 |
xml = """ |
| 1861 |
<iq type='set' to='pubsub.example.org' |
| 1862 |
from='[email protected]'> |
| 1863 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 1864 |
<configure node='test'> |
| 1865 |
<x xmlns='jabber:x:data' type='cancel'/> |
| 1866 |
</configure> |
| 1867 |
</pubsub> |
| 1868 |
</iq> |
| 1869 |
""" |
| 1870 |
|
| 1871 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1872 |
self.assertEqual("cancel", request.options.formType) |
| 1873 |
|
| 1874 |
def test_fromElementConfigureSetBadFormType(self): |
| 1875 |
""" |
| 1876 |
The form of a node configuraton set request should have the right type. |
| 1877 |
""" |
| 1878 |
|
| 1879 |
xml = """ |
| 1880 |
<iq type='set' to='pubsub.example.org' |
| 1881 |
from='[email protected]'> |
| 1882 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 1883 |
<configure node='test'> |
| 1884 |
<x xmlns='jabber:x:data' type='result'> |
| 1885 |
<field var='FORM_TYPE' type='hidden'> |
| 1886 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 1887 |
</field> |
| 1888 |
<field var='pubsub#deliver_payloads'><value>0</value></field> |
| 1889 |
<field var='x-myfield'><value>1</value></field> |
| 1890 |
</x> |
| 1891 |
</configure> |
| 1892 |
</pubsub> |
| 1893 |
</iq> |
| 1894 |
""" |
| 1895 |
|
| 1896 |
err = self.assertRaises( |
| 1897 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1898 |
) |
| 1899 |
self.assertEqual("bad-request", err.condition) |
| 1900 |
self.assertEqual("Unexpected form type 'result'", err.text) |
| 1901 |
self.assertEqual(None, err.appCondition) |
| 1902 |
|
| 1903 |
def test_fromElementConfigureSetNoForm(self): |
| 1904 |
""" |
| 1905 |
On a node configuration set request a form is required. |
| 1906 |
""" |
| 1907 |
|
| 1908 |
xml = """ |
| 1909 |
<iq type='set' to='pubsub.example.org' |
| 1910 |
from='[email protected]'> |
| 1911 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 1912 |
<configure node='test'/> |
| 1913 |
</pubsub> |
| 1914 |
</iq> |
| 1915 |
""" |
| 1916 |
err = self.assertRaises( |
| 1917 |
error.StanzaError, pubsub.PubSubRequest.fromElement, parseXml(xml) |
| 1918 |
) |
| 1919 |
self.assertEqual("bad-request", err.condition) |
| 1920 |
self.assertEqual(None, err.appCondition) |
| 1921 |
|
| 1922 |
def test_fromElementItems(self): |
| 1923 |
""" |
| 1924 |
Test parsing an items request. |
| 1925 |
""" |
| 1926 |
xml = """ |
| 1927 |
<iq type='get' to='pubsub.example.org' |
| 1928 |
from='[email protected]'> |
| 1929 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1930 |
<items node='test'/> |
| 1931 |
</pubsub> |
| 1932 |
</iq> |
| 1933 |
""" |
| 1934 |
|
| 1935 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1936 |
self.assertEqual("items", request.verb) |
| 1937 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1938 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1939 |
self.assertEqual("test", request.nodeIdentifier) |
| 1940 |
self.assertIdentical(None, request.maxItems) |
| 1941 |
self.assertIdentical(None, request.subscriptionIdentifier) |
| 1942 |
self.assertEqual([], request.itemIdentifiers) |
| 1943 |
|
| 1944 |
def test_fromElementItemsSubscriptionIdentifier(self): |
| 1945 |
""" |
| 1946 |
Test parsing an items request with subscription identifier. |
| 1947 |
""" |
| 1948 |
xml = """ |
| 1949 |
<iq type='get' to='pubsub.example.org' |
| 1950 |
from='[email protected]'> |
| 1951 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1952 |
<items node='test' subid='1234'/> |
| 1953 |
</pubsub> |
| 1954 |
</iq> |
| 1955 |
""" |
| 1956 |
|
| 1957 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1958 |
self.assertEqual("1234", request.subscriptionIdentifier) |
| 1959 |
|
| 1960 |
def test_fromElementRetract(self): |
| 1961 |
""" |
| 1962 |
Test parsing a retract request. |
| 1963 |
""" |
| 1964 |
|
| 1965 |
xml = """ |
| 1966 |
<iq type='set' to='pubsub.example.org' |
| 1967 |
from='[email protected]'> |
| 1968 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 1969 |
<retract node='test'> |
| 1970 |
<item id='item1'/> |
| 1971 |
<item id='item2'/> |
| 1972 |
</retract> |
| 1973 |
</pubsub> |
| 1974 |
</iq> |
| 1975 |
""" |
| 1976 |
|
| 1977 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1978 |
self.assertEqual("retract", request.verb) |
| 1979 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 1980 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 1981 |
self.assertEqual("test", request.nodeIdentifier) |
| 1982 |
self.assertEqual(["item1", "item2"], request.itemIdentifiers) |
| 1983 |
|
| 1984 |
def test_fromElementPurge(self): |
| 1985 |
""" |
| 1986 |
Test parsing a purge request. |
| 1987 |
""" |
| 1988 |
|
| 1989 |
xml = """ |
| 1990 |
<iq type='set' to='pubsub.example.org' |
| 1991 |
from='[email protected]'> |
| 1992 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 1993 |
<purge node='test'/> |
| 1994 |
</pubsub> |
| 1995 |
</iq> |
| 1996 |
""" |
| 1997 |
|
| 1998 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 1999 |
self.assertEqual("purge", request.verb) |
| 2000 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 2001 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 2002 |
self.assertEqual("test", request.nodeIdentifier) |
| 2003 |
|
| 2004 |
def test_fromElementDelete(self): |
| 2005 |
""" |
| 2006 |
Test parsing a delete request. |
| 2007 |
""" |
| 2008 |
|
| 2009 |
xml = """ |
| 2010 |
<iq type='set' to='pubsub.example.org' |
| 2011 |
from='[email protected]'> |
| 2012 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 2013 |
<delete node='test'/> |
| 2014 |
</pubsub> |
| 2015 |
</iq> |
| 2016 |
""" |
| 2017 |
|
| 2018 |
request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
| 2019 |
self.assertEqual("delete", request.verb) |
| 2020 |
self.assertEqual(JID("[email protected]"), request.sender) |
| 2021 |
self.assertEqual(JID("pubsub.example.org"), request.recipient) |
| 2022 |
self.assertEqual("test", request.nodeIdentifier) |
| 2023 |
|
| 2024 |
|
| 2025 |
class PubSubServiceTest(unittest.TestCase, TestableRequestHandlerMixin): |
| 2026 |
""" |
| 2027 |
Tests for L{pubsub.PubSubService}. |
| 2028 |
""" |
| 2029 |
|
| 2030 |
def setUp(self): |
| 2031 |
self.stub = XmlStreamStub() |
| 2032 |
self.resource = pubsub.PubSubResource() |
| 2033 |
self.service = pubsub.PubSubService(self.resource) |
| 2034 |
self.service.send = self.stub.xmlstream.send |
| 2035 |
|
| 2036 |
def test_interface(self): |
| 2037 |
""" |
| 2038 |
Do instances of L{pubsub.PubSubService} provide L{itx_xmpp.IPubSubService}? |
| 2039 |
""" |
| 2040 |
verify.verifyObject(itx_xmpp.IPubSubService, self.service) |
| 2041 |
|
| 2042 |
def test_interfaceIDisco(self): |
| 2043 |
""" |
| 2044 |
Do instances of L{pubsub.PubSubService} provide L{itx_xmpp.IDisco}? |
| 2045 |
""" |
| 2046 |
verify.verifyObject(itx_xmpp.IDisco, self.service) |
| 2047 |
|
| 2048 |
def test_connectionMade(self): |
| 2049 |
""" |
| 2050 |
Verify setup of observers in L{pubsub.connectionMade}. |
| 2051 |
""" |
| 2052 |
requests = [] |
| 2053 |
|
| 2054 |
def handleRequest(iq): |
| 2055 |
requests.append(iq) |
| 2056 |
|
| 2057 |
self.service.xmlstream = self.stub.xmlstream |
| 2058 |
self.service.handleRequest = handleRequest |
| 2059 |
self.service.connectionMade() |
| 2060 |
|
| 2061 |
for namespace in (NS_PUBSUB, NS_PUBSUB_OWNER): |
| 2062 |
for stanzaType in ("get", "set"): |
| 2063 |
iq = domish.Element((None, "iq")) |
| 2064 |
iq["type"] = stanzaType |
| 2065 |
iq.addElement((namespace, "pubsub")) |
| 2066 |
self.stub.xmlstream.dispatch(iq) |
| 2067 |
|
| 2068 |
self.assertEqual(4, len(requests)) |
| 2069 |
|
| 2070 |
def test_getDiscoInfo(self): |
| 2071 |
""" |
| 2072 |
Test getDiscoInfo calls getNodeInfo and returns some minimal info. |
| 2073 |
""" |
| 2074 |
|
| 2075 |
def cb(info): |
| 2076 |
discoInfo = disco.DiscoInfo() |
| 2077 |
for item in info: |
| 2078 |
discoInfo.append(item) |
| 2079 |
self.assertIn(("pubsub", "service"), discoInfo.identities) |
| 2080 |
self.assertIn(disco.NS_DISCO_ITEMS, discoInfo.features) |
| 2081 |
|
| 2082 |
d = self.service.getDiscoInfo( |
| 2083 |
JID("[email protected]/home"), JID("pubsub.example.org"), "" |
| 2084 |
) |
| 2085 |
d.addCallback(cb) |
| 2086 |
return d |
| 2087 |
|
| 2088 |
def test_getDiscoInfoNodeType(self): |
| 2089 |
""" |
| 2090 |
Test getDiscoInfo with node type. |
| 2091 |
""" |
| 2092 |
|
| 2093 |
def cb(info): |
| 2094 |
discoInfo = disco.DiscoInfo() |
| 2095 |
for item in info: |
| 2096 |
discoInfo.append(item) |
| 2097 |
self.assertIn(("pubsub", "collection"), discoInfo.identities) |
| 2098 |
|
| 2099 |
def getInfo(requestor, target, nodeIdentifier): |
| 2100 |
return defer.succeed({"type": "collection", "meta-data": {}}) |
| 2101 |
|
| 2102 |
self.resource.getInfo = getInfo |
| 2103 |
d = self.service.getDiscoInfo( |
| 2104 |
JID("[email protected]/home"), JID("pubsub.example.org"), "" |
| 2105 |
) |
| 2106 |
d.addCallback(cb) |
| 2107 |
return d |
| 2108 |
|
| 2109 |
def test_getDiscoInfoMetaData(self): |
| 2110 |
""" |
| 2111 |
Test getDiscoInfo with returned meta data. |
| 2112 |
""" |
| 2113 |
|
| 2114 |
def cb(info): |
| 2115 |
discoInfo = disco.DiscoInfo() |
| 2116 |
for item in info: |
| 2117 |
discoInfo.append(item) |
| 2118 |
|
| 2119 |
self.assertIn(("pubsub", "leaf"), discoInfo.identities) |
| 2120 |
self.assertIn(NS_PUBSUB_META_DATA, discoInfo.extensions) |
| 2121 |
form = discoInfo.extensions[NS_PUBSUB_META_DATA] |
| 2122 |
self.assertIn("pubsub#node_type", form.fields) |
| 2123 |
|
| 2124 |
def getInfo(requestor, target, nodeIdentifier): |
| 2125 |
metaData = [ |
| 2126 |
{ |
| 2127 |
"var": "pubsub#persist_items", |
| 2128 |
"label": "Persist items to storage", |
| 2129 |
"value": True, |
| 2130 |
} |
| 2131 |
] |
| 2132 |
return defer.succeed({"type": "leaf", "meta-data": metaData}) |
| 2133 |
|
| 2134 |
self.resource.getInfo = getInfo |
| 2135 |
d = self.service.getDiscoInfo( |
| 2136 |
JID("[email protected]/home"), JID("pubsub.example.org"), "" |
| 2137 |
) |
| 2138 |
d.addCallback(cb) |
| 2139 |
return d |
| 2140 |
|
| 2141 |
def test_getDiscoInfoResourceFeatures(self): |
| 2142 |
""" |
| 2143 |
Test getDiscoInfo with the resource features. |
| 2144 |
""" |
| 2145 |
|
| 2146 |
def cb(info): |
| 2147 |
discoInfo = disco.DiscoInfo() |
| 2148 |
for item in info: |
| 2149 |
discoInfo.append(item) |
| 2150 |
self.assertIn("http://jabber.org/protocol/pubsub#publish", discoInfo.features) |
| 2151 |
|
| 2152 |
self.resource.features = ["publish"] |
| 2153 |
d = self.service.getDiscoInfo( |
| 2154 |
JID("[email protected]/home"), JID("pubsub.example.org"), "" |
| 2155 |
) |
| 2156 |
d.addCallback(cb) |
| 2157 |
return d |
| 2158 |
|
| 2159 |
def test_getDiscoInfoBadResponse(self): |
| 2160 |
""" |
| 2161 |
If getInfo returns invalid response, it should be logged, then ignored. |
| 2162 |
""" |
| 2163 |
|
| 2164 |
def cb(info): |
| 2165 |
self.assertEquals([], info) |
| 2166 |
self.assertEqual(1, len(self.flushLoggedErrors(TypeError))) |
| 2167 |
|
| 2168 |
def getInfo(requestor, target, nodeIdentifier): |
| 2169 |
return defer.succeed("bad response") |
| 2170 |
|
| 2171 |
self.resource.getInfo = getInfo |
| 2172 |
d = self.service.getDiscoInfo( |
| 2173 |
JID("[email protected]/home"), JID("pubsub.example.org"), "test" |
| 2174 |
) |
| 2175 |
d.addCallback(cb) |
| 2176 |
return d |
| 2177 |
|
| 2178 |
def test_getDiscoInfoException(self): |
| 2179 |
""" |
| 2180 |
If getInfo returns invalid response, it should be logged, then ignored. |
| 2181 |
""" |
| 2182 |
|
| 2183 |
def cb(info): |
| 2184 |
self.assertEquals([], info) |
| 2185 |
self.assertEqual(1, len(self.flushLoggedErrors(NotImplementedError))) |
| 2186 |
|
| 2187 |
def getInfo(requestor, target, nodeIdentifier): |
| 2188 |
return defer.fail(NotImplementedError()) |
| 2189 |
|
| 2190 |
self.resource.getInfo = getInfo |
| 2191 |
d = self.service.getDiscoInfo( |
| 2192 |
JID("[email protected]/home"), JID("pubsub.example.org"), "test" |
| 2193 |
) |
| 2194 |
d.addCallback(cb) |
| 2195 |
return d |
| 2196 |
|
| 2197 |
def test_getDiscoItemsRoot(self): |
| 2198 |
""" |
| 2199 |
Test getDiscoItems on the root node. |
| 2200 |
""" |
| 2201 |
|
| 2202 |
def getNodes(requestor, service, nodeIdentifier): |
| 2203 |
return defer.succeed(["node1", "node2"]) |
| 2204 |
|
| 2205 |
def cb(items): |
| 2206 |
self.assertEqual(2, len(items)) |
| 2207 |
item1, item2 = items |
| 2208 |
|
| 2209 |
self.assertEqual(JID("pubsub.example.org"), item1.entity) |
| 2210 |
self.assertEqual("node1", item1.nodeIdentifier) |
| 2211 |
|
| 2212 |
self.assertEqual(JID("pubsub.example.org"), item2.entity) |
| 2213 |
self.assertEqual("node2", item2.nodeIdentifier) |
| 2214 |
|
| 2215 |
self.resource.getNodes = getNodes |
| 2216 |
d = self.service.getDiscoItems( |
| 2217 |
JID("[email protected]/home"), JID("pubsub.example.org"), "" |
| 2218 |
) |
| 2219 |
d.addCallback(cb) |
| 2220 |
return d |
| 2221 |
|
| 2222 |
def test_getDiscoItemsRootHideNodes(self): |
| 2223 |
""" |
| 2224 |
Test getDiscoItems on the root node. |
| 2225 |
""" |
| 2226 |
|
| 2227 |
def getNodes(requestor, service, nodeIdentifier): |
| 2228 |
raise Exception("Unexpected call to getNodes") |
| 2229 |
|
| 2230 |
def cb(items): |
| 2231 |
self.assertEqual([], items) |
| 2232 |
|
| 2233 |
self.service.hideNodes = True |
| 2234 |
self.resource.getNodes = getNodes |
| 2235 |
d = self.service.getDiscoItems( |
| 2236 |
JID("[email protected]/home"), JID("pubsub.example.org"), "" |
| 2237 |
) |
| 2238 |
d.addCallback(cb) |
| 2239 |
return d |
| 2240 |
|
| 2241 |
def test_getDiscoItemsNonRoot(self): |
| 2242 |
""" |
| 2243 |
Test getDiscoItems on a non-root node. |
| 2244 |
""" |
| 2245 |
|
| 2246 |
def getNodes(requestor, service, nodeIdentifier): |
| 2247 |
return defer.succeed(["node1", "node2"]) |
| 2248 |
|
| 2249 |
def cb(items): |
| 2250 |
self.assertEqual(2, len(items)) |
| 2251 |
|
| 2252 |
self.resource.getNodes = getNodes |
| 2253 |
d = self.service.getDiscoItems( |
| 2254 |
JID("[email protected]/home"), JID("pubsub.example.org"), "test" |
| 2255 |
) |
| 2256 |
d.addCallback(cb) |
| 2257 |
return d |
| 2258 |
|
| 2259 |
def test_on_publish(self): |
| 2260 |
""" |
| 2261 |
A publish request should result in L{PubSubService.publish} being |
| 2262 |
called. |
| 2263 |
""" |
| 2264 |
|
| 2265 |
xml = """ |
| 2266 |
<iq type='set' to='pubsub.example.org' |
| 2267 |
from='[email protected]'> |
| 2268 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2269 |
<publish node='test'/> |
| 2270 |
</pubsub> |
| 2271 |
</iq> |
| 2272 |
""" |
| 2273 |
|
| 2274 |
def publish(request): |
| 2275 |
return defer.succeed(None) |
| 2276 |
|
| 2277 |
self.resource.publish = publish |
| 2278 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2279 |
return self.handleRequest(xml) |
| 2280 |
|
| 2281 |
def test_on_subscribe(self): |
| 2282 |
""" |
| 2283 |
A successful subscription should return the current subscription. |
| 2284 |
""" |
| 2285 |
|
| 2286 |
xml = """ |
| 2287 |
<iq type='set' to='pubsub.example.org' |
| 2288 |
from='[email protected]'> |
| 2289 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2290 |
<subscribe node='test' jid='[email protected]/Home'/> |
| 2291 |
</pubsub> |
| 2292 |
</iq> |
| 2293 |
""" |
| 2294 |
|
| 2295 |
def subscribe(request): |
| 2296 |
return defer.succeed( |
| 2297 |
pubsub.Subscription( |
| 2298 |
request.nodeIdentifier, request.subscriber, "subscribed" |
| 2299 |
) |
| 2300 |
) |
| 2301 |
|
| 2302 |
def cb(element): |
| 2303 |
self.assertEqual("pubsub", element.name) |
| 2304 |
self.assertEqual(NS_PUBSUB, element.uri) |
| 2305 |
subscription = element.subscription |
| 2306 |
self.assertEqual(NS_PUBSUB, subscription.uri) |
| 2307 |
self.assertEqual("test", subscription["node"]) |
| 2308 |
self.assertEqual("[email protected]/Home", subscription["jid"]) |
| 2309 |
self.assertEqual("subscribed", subscription["subscription"]) |
| 2310 |
|
| 2311 |
self.resource.subscribe = subscribe |
| 2312 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2313 |
d = self.handleRequest(xml) |
| 2314 |
d.addCallback(cb) |
| 2315 |
return d |
| 2316 |
|
| 2317 |
def test_on_subscribeEmptyNode(self): |
| 2318 |
""" |
| 2319 |
A successful subscription on root node should return no node attribute. |
| 2320 |
""" |
| 2321 |
|
| 2322 |
xml = """ |
| 2323 |
<iq type='set' to='pubsub.example.org' |
| 2324 |
from='[email protected]'> |
| 2325 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2326 |
<subscribe jid='[email protected]/Home'/> |
| 2327 |
</pubsub> |
| 2328 |
</iq> |
| 2329 |
""" |
| 2330 |
|
| 2331 |
def subscribe(request): |
| 2332 |
return defer.succeed( |
| 2333 |
pubsub.Subscription( |
| 2334 |
request.nodeIdentifier, request.subscriber, "subscribed" |
| 2335 |
) |
| 2336 |
) |
| 2337 |
|
| 2338 |
def cb(element): |
| 2339 |
self.assertFalse(element.subscription.hasAttribute("node")) |
| 2340 |
|
| 2341 |
self.resource.subscribe = subscribe |
| 2342 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2343 |
d = self.handleRequest(xml) |
| 2344 |
d.addCallback(cb) |
| 2345 |
return d |
| 2346 |
|
| 2347 |
def test_on_subscribeSubscriptionIdentifier(self): |
| 2348 |
""" |
| 2349 |
If a subscription returns a subid, this should be available. |
| 2350 |
""" |
| 2351 |
|
| 2352 |
xml = """ |
| 2353 |
<iq type='set' to='pubsub.example.org' |
| 2354 |
from='[email protected]'> |
| 2355 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2356 |
<subscribe node='test' jid='[email protected]/Home'/> |
| 2357 |
</pubsub> |
| 2358 |
</iq> |
| 2359 |
""" |
| 2360 |
|
| 2361 |
def subscribe(request): |
| 2362 |
subscription = pubsub.Subscription( |
| 2363 |
request.nodeIdentifier, |
| 2364 |
request.subscriber, |
| 2365 |
"subscribed", |
| 2366 |
subscriptionIdentifier="1234", |
| 2367 |
) |
| 2368 |
return defer.succeed(subscription) |
| 2369 |
|
| 2370 |
def cb(element): |
| 2371 |
self.assertEqual("1234", element.subscription.getAttribute("subid")) |
| 2372 |
|
| 2373 |
self.resource.subscribe = subscribe |
| 2374 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2375 |
d = self.handleRequest(xml) |
| 2376 |
d.addCallback(cb) |
| 2377 |
return d |
| 2378 |
|
| 2379 |
def test_on_unsubscribe(self): |
| 2380 |
""" |
| 2381 |
A successful unsubscription should return a response with a subscription element. |
| 2382 |
""" |
| 2383 |
|
| 2384 |
xml = """ |
| 2385 |
<iq type='set' to='pubsub.example.org' |
| 2386 |
from='[email protected]'> |
| 2387 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2388 |
<unsubscribe node='test' jid='[email protected]/Home'/> |
| 2389 |
</pubsub> |
| 2390 |
</iq> |
| 2391 |
""" |
| 2392 |
|
| 2393 |
def unsubscribe(request): |
| 2394 |
return defer.succeed(None) |
| 2395 |
|
| 2396 |
def cb(element): |
| 2397 |
self.assertIsNotNone(element) |
| 2398 |
self.assertEqual("pubsub", element.name) |
| 2399 |
self.assertEqual(NS_PUBSUB, element.uri) |
| 2400 |
self.assertEqual(1, len(element.children)) |
| 2401 |
subscription = element.children[0] |
| 2402 |
self.assertEqual("subscription", subscription.name) |
| 2403 |
self.assertEqual("none", subscription["subscription"]) |
| 2404 |
|
| 2405 |
self.resource.unsubscribe = unsubscribe |
| 2406 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2407 |
d = self.handleRequest(xml) |
| 2408 |
d.addCallback(cb) |
| 2409 |
return d |
| 2410 |
|
| 2411 |
def test_on_unsubscribeSubscriptionIdentifier(self): |
| 2412 |
""" |
| 2413 |
A successful unsubscription with subid should return a response with a subscription element. |
| 2414 |
""" |
| 2415 |
|
| 2416 |
xml = """ |
| 2417 |
<iq type='set' to='pubsub.example.org' |
| 2418 |
from='[email protected]'> |
| 2419 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2420 |
<unsubscribe node='test' jid='[email protected]/Home' subid='1234'/> |
| 2421 |
</pubsub> |
| 2422 |
</iq> |
| 2423 |
""" |
| 2424 |
|
| 2425 |
def unsubscribe(request): |
| 2426 |
self.assertEqual("1234", request.subscriptionIdentifier) |
| 2427 |
return defer.succeed(None) |
| 2428 |
|
| 2429 |
def cb(element): |
| 2430 |
self.assertIsNotNone(element) |
| 2431 |
self.assertEqual("pubsub", element.name) |
| 2432 |
self.assertEqual(NS_PUBSUB, element.uri) |
| 2433 |
self.assertEqual(1, len(element.children)) |
| 2434 |
subscription = element.children[0] |
| 2435 |
self.assertEqual("subscription", subscription.name) |
| 2436 |
self.assertEqual("none", subscription["subscription"]) |
| 2437 |
|
| 2438 |
self.resource.unsubscribe = unsubscribe |
| 2439 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2440 |
d = self.handleRequest(xml) |
| 2441 |
d.addCallback(cb) |
| 2442 |
return d |
| 2443 |
|
| 2444 |
def test_on_optionsGet(self): |
| 2445 |
""" |
| 2446 |
Getting subscription options is not supported. |
| 2447 |
""" |
| 2448 |
|
| 2449 |
xml = """ |
| 2450 |
<iq type='get' to='pubsub.example.org' |
| 2451 |
from='[email protected]'> |
| 2452 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2453 |
<options node='test' jid='[email protected]/Home'/> |
| 2454 |
</pubsub> |
| 2455 |
</iq> |
| 2456 |
""" |
| 2457 |
|
| 2458 |
def cb(result): |
| 2459 |
self.assertEquals("feature-not-implemented", result.condition) |
| 2460 |
self.assertEquals("unsupported", result.appCondition.name) |
| 2461 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 2462 |
|
| 2463 |
d = self.handleRequest(xml) |
| 2464 |
self.assertFailure(d, error.StanzaError) |
| 2465 |
d.addCallback(cb) |
| 2466 |
return d |
| 2467 |
|
| 2468 |
def test_on_optionsSet(self): |
| 2469 |
""" |
| 2470 |
Setting subscription options is not supported. |
| 2471 |
""" |
| 2472 |
|
| 2473 |
xml = """ |
| 2474 |
<iq type='set' to='pubsub.example.org' |
| 2475 |
from='[email protected]'> |
| 2476 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2477 |
<options node='test' jid='[email protected]/Home'> |
| 2478 |
<x xmlns='jabber:x:data' type='submit'> |
| 2479 |
<field var='FORM_TYPE' type='hidden'> |
| 2480 |
<value>http://jabber.org/protocol/pubsub#subscribe_options</value> |
| 2481 |
</field> |
| 2482 |
<field var='pubsub#deliver'><value>1</value></field> |
| 2483 |
</x> |
| 2484 |
</options> |
| 2485 |
</pubsub> |
| 2486 |
</iq> |
| 2487 |
""" |
| 2488 |
|
| 2489 |
def cb(result): |
| 2490 |
self.assertEquals("feature-not-implemented", result.condition) |
| 2491 |
self.assertEquals("unsupported", result.appCondition.name) |
| 2492 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 2493 |
|
| 2494 |
d = self.handleRequest(xml) |
| 2495 |
self.assertFailure(d, error.StanzaError) |
| 2496 |
d.addCallback(cb) |
| 2497 |
return d |
| 2498 |
|
| 2499 |
def test_on_subscriptions(self): |
| 2500 |
""" |
| 2501 |
A subscriptions request should result in |
| 2502 |
L{PubSubService.subscriptions} being called and the result prepared |
| 2503 |
for the response. |
| 2504 |
""" |
| 2505 |
|
| 2506 |
xml = """ |
| 2507 |
<iq type='get' to='pubsub.example.org' |
| 2508 |
from='[email protected]'> |
| 2509 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2510 |
<subscriptions/> |
| 2511 |
</pubsub> |
| 2512 |
</iq> |
| 2513 |
""" |
| 2514 |
|
| 2515 |
def subscriptions(request): |
| 2516 |
subscription = pubsub.Subscription( |
| 2517 |
"test", JID("[email protected]"), "subscribed" |
| 2518 |
) |
| 2519 |
return defer.succeed([subscription]) |
| 2520 |
|
| 2521 |
def cb(element): |
| 2522 |
self.assertEqual("pubsub", element.name) |
| 2523 |
self.assertEqual(NS_PUBSUB, element.uri) |
| 2524 |
self.assertEqual(NS_PUBSUB, element.subscriptions.uri) |
| 2525 |
children = list(element.subscriptions.elements()) |
| 2526 |
self.assertEqual(1, len(children)) |
| 2527 |
subscription = children[0] |
| 2528 |
self.assertEqual("subscription", subscription.name) |
| 2529 |
self.assertEqual(NS_PUBSUB, subscription.uri, NS_PUBSUB) |
| 2530 |
self.assertEqual("[email protected]", subscription["jid"]) |
| 2531 |
self.assertEqual("test", subscription["node"]) |
| 2532 |
self.assertEqual("subscribed", subscription["subscription"]) |
| 2533 |
|
| 2534 |
self.resource.subscriptions = subscriptions |
| 2535 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2536 |
d = self.handleRequest(xml) |
| 2537 |
d.addCallback(cb) |
| 2538 |
return d |
| 2539 |
|
| 2540 |
def test_on_subscriptionsWithSubscriptionIdentifier(self): |
| 2541 |
""" |
| 2542 |
A subscriptions request response should include subids, if set. |
| 2543 |
""" |
| 2544 |
|
| 2545 |
xml = """ |
| 2546 |
<iq type='get' to='pubsub.example.org' |
| 2547 |
from='[email protected]'> |
| 2548 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2549 |
<subscriptions/> |
| 2550 |
</pubsub> |
| 2551 |
</iq> |
| 2552 |
""" |
| 2553 |
|
| 2554 |
def subscriptions(request): |
| 2555 |
subscription = pubsub.Subscription( |
| 2556 |
"test", |
| 2557 |
JID("[email protected]"), |
| 2558 |
"subscribed", |
| 2559 |
subscriptionIdentifier="1234", |
| 2560 |
) |
| 2561 |
return defer.succeed([subscription]) |
| 2562 |
|
| 2563 |
def cb(element): |
| 2564 |
subscription = element.subscriptions.subscription |
| 2565 |
self.assertEqual("1234", subscription["subid"]) |
| 2566 |
|
| 2567 |
self.resource.subscriptions = subscriptions |
| 2568 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2569 |
d = self.handleRequest(xml) |
| 2570 |
d.addCallback(cb) |
| 2571 |
return d |
| 2572 |
|
| 2573 |
def test_on_affiliations(self): |
| 2574 |
""" |
| 2575 |
A subscriptions request should result in |
| 2576 |
L{PubSubService.affiliations} being called and the result prepared |
| 2577 |
for the response. |
| 2578 |
""" |
| 2579 |
|
| 2580 |
xml = """ |
| 2581 |
<iq type='get' to='pubsub.example.org' |
| 2582 |
from='[email protected]'> |
| 2583 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2584 |
<affiliations/> |
| 2585 |
</pubsub> |
| 2586 |
</iq> |
| 2587 |
""" |
| 2588 |
|
| 2589 |
def affiliations(request): |
| 2590 |
affiliation = ("test", "owner") |
| 2591 |
return defer.succeed([affiliation]) |
| 2592 |
|
| 2593 |
def cb(element): |
| 2594 |
self.assertEqual("pubsub", element.name) |
| 2595 |
self.assertEqual(NS_PUBSUB, element.uri) |
| 2596 |
self.assertEqual(NS_PUBSUB, element.affiliations.uri) |
| 2597 |
children = list(element.affiliations.elements()) |
| 2598 |
self.assertEqual(1, len(children)) |
| 2599 |
affiliation = children[0] |
| 2600 |
self.assertEqual("affiliation", affiliation.name) |
| 2601 |
self.assertEqual(NS_PUBSUB, affiliation.uri) |
| 2602 |
self.assertEqual("test", affiliation["node"]) |
| 2603 |
self.assertEqual("owner", affiliation["affiliation"]) |
| 2604 |
|
| 2605 |
self.resource.affiliations = affiliations |
| 2606 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2607 |
d = self.handleRequest(xml) |
| 2608 |
d.addCallback(cb) |
| 2609 |
return d |
| 2610 |
|
| 2611 |
def test_on_create(self): |
| 2612 |
""" |
| 2613 |
Replies to create node requests don't return the created node. |
| 2614 |
""" |
| 2615 |
|
| 2616 |
xml = """ |
| 2617 |
<iq type='set' to='pubsub.example.org' |
| 2618 |
from='[email protected]'> |
| 2619 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2620 |
<create node='mynode'/> |
| 2621 |
</pubsub> |
| 2622 |
</iq> |
| 2623 |
""" |
| 2624 |
|
| 2625 |
def create(request): |
| 2626 |
return defer.succeed(request.nodeIdentifier) |
| 2627 |
|
| 2628 |
def cb(element): |
| 2629 |
self.assertIdentical(None, element) |
| 2630 |
|
| 2631 |
self.resource.create = create |
| 2632 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2633 |
d = self.handleRequest(xml) |
| 2634 |
d.addCallback(cb) |
| 2635 |
return d |
| 2636 |
|
| 2637 |
def test_on_createChanged(self): |
| 2638 |
""" |
| 2639 |
Replies to create node requests return the created node if changed. |
| 2640 |
""" |
| 2641 |
|
| 2642 |
xml = """ |
| 2643 |
<iq type='set' to='pubsub.example.org' |
| 2644 |
from='[email protected]'> |
| 2645 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2646 |
<create node='mynode'/> |
| 2647 |
</pubsub> |
| 2648 |
</iq> |
| 2649 |
""" |
| 2650 |
|
| 2651 |
def create(request): |
| 2652 |
return defer.succeed("myrenamednode") |
| 2653 |
|
| 2654 |
def cb(element): |
| 2655 |
self.assertEqual("pubsub", element.name) |
| 2656 |
self.assertEqual(NS_PUBSUB, element.uri) |
| 2657 |
self.assertEqual(NS_PUBSUB, element.create.uri) |
| 2658 |
self.assertEqual("myrenamednode", element.create.getAttribute("node")) |
| 2659 |
|
| 2660 |
self.resource.create = create |
| 2661 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2662 |
d = self.handleRequest(xml) |
| 2663 |
d.addCallback(cb) |
| 2664 |
return d |
| 2665 |
|
| 2666 |
def test_on_createInstant(self): |
| 2667 |
""" |
| 2668 |
Replies to create instant node requests return the created node. |
| 2669 |
""" |
| 2670 |
|
| 2671 |
xml = """ |
| 2672 |
<iq type='set' to='pubsub.example.org' |
| 2673 |
from='[email protected]'> |
| 2674 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2675 |
<create/> |
| 2676 |
</pubsub> |
| 2677 |
</iq> |
| 2678 |
""" |
| 2679 |
|
| 2680 |
def create(request): |
| 2681 |
return defer.succeed("random") |
| 2682 |
|
| 2683 |
def cb(element): |
| 2684 |
self.assertEqual("pubsub", element.name) |
| 2685 |
self.assertEqual(NS_PUBSUB, element.uri) |
| 2686 |
self.assertEqual(NS_PUBSUB, element.create.uri) |
| 2687 |
self.assertEqual("random", element.create.getAttribute("node")) |
| 2688 |
|
| 2689 |
self.resource.create = create |
| 2690 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2691 |
d = self.handleRequest(xml) |
| 2692 |
d.addCallback(cb) |
| 2693 |
return d |
| 2694 |
|
| 2695 |
def test_on_createWithConfig(self): |
| 2696 |
""" |
| 2697 |
On a node create with configuration request the Data Form is parsed and |
| 2698 |
L{PubSubResource.create} is called with the passed options. |
| 2699 |
""" |
| 2700 |
|
| 2701 |
xml = """ |
| 2702 |
<iq type='set' to='pubsub.example.org' |
| 2703 |
from='[email protected]'> |
| 2704 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 2705 |
<create node='mynode'/> |
| 2706 |
<configure> |
| 2707 |
<x xmlns='jabber:x:data' type='submit'> |
| 2708 |
<field var='FORM_TYPE' type='hidden'> |
| 2709 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 2710 |
</field> |
| 2711 |
<field var='pubsub#deliver_payloads'><value>0</value></field> |
| 2712 |
<field var='pubsub#persist_items'><value>1</value></field> |
| 2713 |
</x> |
| 2714 |
</configure> |
| 2715 |
</pubsub> |
| 2716 |
</iq> |
| 2717 |
""" |
| 2718 |
|
| 2719 |
def getConfigurationOptions(): |
| 2720 |
return { |
| 2721 |
"pubsub#persist_items": { |
| 2722 |
"type": "boolean", |
| 2723 |
"label": "Persist items to storage", |
| 2724 |
}, |
| 2725 |
"pubsub#deliver_payloads": { |
| 2726 |
"type": "boolean", |
| 2727 |
"label": "Deliver payloads with event notifications", |
| 2728 |
}, |
| 2729 |
} |
| 2730 |
|
| 2731 |
def create(request): |
| 2732 |
self.assertEqual( |
| 2733 |
{"pubsub#deliver_payloads": False, "pubsub#persist_items": True}, |
| 2734 |
request.options.getValues(), |
| 2735 |
) |
| 2736 |
return defer.succeed(None) |
| 2737 |
|
| 2738 |
self.resource.getConfigurationOptions = getConfigurationOptions |
| 2739 |
self.resource.create = create |
| 2740 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2741 |
return self.handleRequest(xml) |
| 2742 |
|
| 2743 |
def test_on_default(self): |
| 2744 |
""" |
| 2745 |
A default request returns default options filtered by available fields. |
| 2746 |
""" |
| 2747 |
|
| 2748 |
xml = """ |
| 2749 |
<iq type='get' to='pubsub.example.org' |
| 2750 |
from='[email protected]'> |
| 2751 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 2752 |
<default/> |
| 2753 |
</pubsub> |
| 2754 |
</iq> |
| 2755 |
""" |
| 2756 |
fieldDefs = { |
| 2757 |
"pubsub#persist_items": { |
| 2758 |
"type": "boolean", |
| 2759 |
"label": "Persist items to storage", |
| 2760 |
}, |
| 2761 |
"pubsub#deliver_payloads": { |
| 2762 |
"type": "boolean", |
| 2763 |
"label": "Deliver payloads with event notifications", |
| 2764 |
}, |
| 2765 |
} |
| 2766 |
|
| 2767 |
def getConfigurationOptions(): |
| 2768 |
return fieldDefs |
| 2769 |
|
| 2770 |
def default(request): |
| 2771 |
return defer.succeed({"pubsub#persist_items": "false", "x-myfield": "1"}) |
| 2772 |
|
| 2773 |
def cb(element): |
| 2774 |
self.assertEquals("pubsub", element.name) |
| 2775 |
self.assertEquals(NS_PUBSUB_OWNER, element.uri) |
| 2776 |
self.assertEquals(NS_PUBSUB_OWNER, element.default.uri) |
| 2777 |
form = data_form.Form.fromElement(element.default.x) |
| 2778 |
self.assertEquals(NS_PUBSUB_NODE_CONFIG, form.formNamespace) |
| 2779 |
form.typeCheck(fieldDefs) |
| 2780 |
self.assertIn("pubsub#persist_items", form.fields) |
| 2781 |
self.assertFalse(form.fields["pubsub#persist_items"].value) |
| 2782 |
self.assertNotIn("x-myfield", form.fields) |
| 2783 |
|
| 2784 |
self.resource.getConfigurationOptions = getConfigurationOptions |
| 2785 |
self.resource.default = default |
| 2786 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2787 |
d = self.handleRequest(xml) |
| 2788 |
d.addCallback(cb) |
| 2789 |
return d |
| 2790 |
|
| 2791 |
def test_on_defaultUnknownNodeType(self): |
| 2792 |
""" |
| 2793 |
Unknown node types yield non-acceptable. |
| 2794 |
|
| 2795 |
Both C{getConfigurationOptions} and C{default} must not be called. |
| 2796 |
""" |
| 2797 |
|
| 2798 |
xml = """ |
| 2799 |
<iq type='get' to='pubsub.example.org' |
| 2800 |
from='[email protected]'> |
| 2801 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 2802 |
<default> |
| 2803 |
<x xmlns='jabber:x:data' type='submit'> |
| 2804 |
<field var='FORM_TYPE' type='hidden'> |
| 2805 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 2806 |
</field> |
| 2807 |
<field var='pubsub#node_type'> |
| 2808 |
<value>unknown</value> |
| 2809 |
</field> |
| 2810 |
</x> |
| 2811 |
</default> |
| 2812 |
|
| 2813 |
</pubsub> |
| 2814 |
</iq> |
| 2815 |
""" |
| 2816 |
|
| 2817 |
def getConfigurationOptions(): |
| 2818 |
self.fail("Unexpected call to getConfigurationOptions") |
| 2819 |
|
| 2820 |
def default(request): |
| 2821 |
self.fail("Unexpected call to default") |
| 2822 |
|
| 2823 |
def cb(result): |
| 2824 |
self.assertEquals("not-acceptable", result.condition) |
| 2825 |
|
| 2826 |
self.resource.getConfigurationOptions = getConfigurationOptions |
| 2827 |
self.resource.default = default |
| 2828 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2829 |
d = self.handleRequest(xml) |
| 2830 |
self.assertFailure(d, error.StanzaError) |
| 2831 |
d.addCallback(cb) |
| 2832 |
return d |
| 2833 |
|
| 2834 |
def test_on_configureGet(self): |
| 2835 |
""" |
| 2836 |
On a node configuration get |
| 2837 |
requestL{PubSubResource.configureGet} is called and results in a |
| 2838 |
data form with the configuration. |
| 2839 |
""" |
| 2840 |
|
| 2841 |
xml = """ |
| 2842 |
<iq type='get' to='pubsub.example.org' |
| 2843 |
from='[email protected]'> |
| 2844 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 2845 |
<configure node='test'/> |
| 2846 |
</pubsub> |
| 2847 |
</iq> |
| 2848 |
""" |
| 2849 |
|
| 2850 |
def getConfigurationOptions(): |
| 2851 |
return { |
| 2852 |
"pubsub#persist_items": { |
| 2853 |
"type": "boolean", |
| 2854 |
"label": "Persist items to storage", |
| 2855 |
}, |
| 2856 |
"pubsub#deliver_payloads": { |
| 2857 |
"type": "boolean", |
| 2858 |
"label": "Deliver payloads with event notifications", |
| 2859 |
}, |
| 2860 |
"pubsub#owner": {"type": "jid-single", "label": "Owner of the node"}, |
| 2861 |
} |
| 2862 |
|
| 2863 |
def configureGet(request): |
| 2864 |
return defer.succeed( |
| 2865 |
{ |
| 2866 |
"pubsub#deliver_payloads": "0", |
| 2867 |
"pubsub#persist_items": "1", |
| 2868 |
"pubsub#owner": JID("[email protected]"), |
| 2869 |
"x-myfield": "a", |
| 2870 |
} |
| 2871 |
) |
| 2872 |
|
| 2873 |
def cb(element): |
| 2874 |
self.assertEqual("pubsub", element.name) |
| 2875 |
self.assertEqual(NS_PUBSUB_OWNER, element.uri) |
| 2876 |
self.assertEqual(NS_PUBSUB_OWNER, element.configure.uri) |
| 2877 |
form = data_form.Form.fromElement(element.configure.x) |
| 2878 |
self.assertEqual(NS_PUBSUB_NODE_CONFIG, form.formNamespace) |
| 2879 |
fields = form.fields |
| 2880 |
|
| 2881 |
self.assertIn("pubsub#deliver_payloads", fields) |
| 2882 |
field = fields["pubsub#deliver_payloads"] |
| 2883 |
self.assertEqual("boolean", field.fieldType) |
| 2884 |
field.typeCheck() |
| 2885 |
self.assertEqual(False, field.value) |
| 2886 |
|
| 2887 |
self.assertIn("pubsub#persist_items", fields) |
| 2888 |
field = fields["pubsub#persist_items"] |
| 2889 |
self.assertEqual("boolean", field.fieldType) |
| 2890 |
field.typeCheck() |
| 2891 |
self.assertEqual(True, field.value) |
| 2892 |
|
| 2893 |
self.assertIn("pubsub#owner", fields) |
| 2894 |
field = fields["pubsub#owner"] |
| 2895 |
self.assertEqual("jid-single", field.fieldType) |
| 2896 |
field.typeCheck() |
| 2897 |
self.assertEqual(JID("[email protected]"), field.value) |
| 2898 |
|
| 2899 |
self.assertNotIn("x-myfield", fields) |
| 2900 |
|
| 2901 |
self.resource.getConfigurationOptions = getConfigurationOptions |
| 2902 |
self.resource.configureGet = configureGet |
| 2903 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2904 |
d = self.handleRequest(xml) |
| 2905 |
d.addCallback(cb) |
| 2906 |
return d |
| 2907 |
|
| 2908 |
def test_on_configureSet(self): |
| 2909 |
""" |
| 2910 |
On a node configuration set request the Data Form is parsed and |
| 2911 |
L{PubSubResource.configureSet} is called with the passed options. |
| 2912 |
""" |
| 2913 |
|
| 2914 |
xml = """ |
| 2915 |
<iq type='set' to='pubsub.example.org' |
| 2916 |
from='[email protected]'> |
| 2917 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 2918 |
<configure node='test'> |
| 2919 |
<x xmlns='jabber:x:data' type='submit'> |
| 2920 |
<field var='FORM_TYPE' type='hidden'> |
| 2921 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 2922 |
</field> |
| 2923 |
<field var='pubsub#deliver_payloads'><value>0</value></field> |
| 2924 |
<field var='pubsub#persist_items'><value>1</value></field> |
| 2925 |
</x> |
| 2926 |
</configure> |
| 2927 |
</pubsub> |
| 2928 |
</iq> |
| 2929 |
""" |
| 2930 |
|
| 2931 |
def getConfigurationOptions(): |
| 2932 |
return { |
| 2933 |
"pubsub#persist_items": { |
| 2934 |
"type": "boolean", |
| 2935 |
"label": "Persist items to storage", |
| 2936 |
}, |
| 2937 |
"pubsub#deliver_payloads": { |
| 2938 |
"type": "boolean", |
| 2939 |
"label": "Deliver payloads with event notifications", |
| 2940 |
}, |
| 2941 |
} |
| 2942 |
|
| 2943 |
def configureSet(request): |
| 2944 |
self.assertEqual( |
| 2945 |
{"pubsub#deliver_payloads": False, "pubsub#persist_items": True}, |
| 2946 |
request.options.getValues(), |
| 2947 |
) |
| 2948 |
return defer.succeed(None) |
| 2949 |
|
| 2950 |
self.resource.getConfigurationOptions = getConfigurationOptions |
| 2951 |
self.resource.configureSet = configureSet |
| 2952 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2953 |
return self.handleRequest(xml) |
| 2954 |
|
| 2955 |
def test_on_configureSetCancel(self): |
| 2956 |
""" |
| 2957 |
The node configuration is cancelled, |
| 2958 |
L{PubSubResource.configureSet} not called. |
| 2959 |
""" |
| 2960 |
|
| 2961 |
xml = """ |
| 2962 |
<iq type='set' to='pubsub.example.org' |
| 2963 |
from='[email protected]'> |
| 2964 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 2965 |
<configure node='test'> |
| 2966 |
<x xmlns='jabber:x:data' type='cancel'> |
| 2967 |
<field var='FORM_TYPE' type='hidden'> |
| 2968 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 2969 |
</field> |
| 2970 |
</x> |
| 2971 |
</configure> |
| 2972 |
</pubsub> |
| 2973 |
</iq> |
| 2974 |
""" |
| 2975 |
|
| 2976 |
def configureSet(request): |
| 2977 |
self.fail("Unexpected call to setConfiguration") |
| 2978 |
|
| 2979 |
self.resource.configureSet = configureSet |
| 2980 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 2981 |
return self.handleRequest(xml) |
| 2982 |
|
| 2983 |
def test_on_configureSetIgnoreUnknown(self): |
| 2984 |
""" |
| 2985 |
On a node configuration set request unknown fields should be ignored. |
| 2986 |
""" |
| 2987 |
|
| 2988 |
xml = """ |
| 2989 |
<iq type='set' to='pubsub.example.org' |
| 2990 |
from='[email protected]'> |
| 2991 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 2992 |
<configure node='test'> |
| 2993 |
<x xmlns='jabber:x:data' type='submit'> |
| 2994 |
<field var='FORM_TYPE' type='hidden'> |
| 2995 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 2996 |
</field> |
| 2997 |
<field var='pubsub#deliver_payloads'><value>0</value></field> |
| 2998 |
<field var='x-myfield'><value>1</value></field> |
| 2999 |
</x> |
| 3000 |
</configure> |
| 3001 |
</pubsub> |
| 3002 |
</iq> |
| 3003 |
""" |
| 3004 |
|
| 3005 |
def getConfigurationOptions(): |
| 3006 |
return { |
| 3007 |
"pubsub#persist_items": { |
| 3008 |
"type": "boolean", |
| 3009 |
"label": "Persist items to storage", |
| 3010 |
}, |
| 3011 |
"pubsub#deliver_payloads": { |
| 3012 |
"type": "boolean", |
| 3013 |
"label": "Deliver payloads with event notifications", |
| 3014 |
}, |
| 3015 |
} |
| 3016 |
|
| 3017 |
def configureSet(request): |
| 3018 |
self.assertEquals(["pubsub#deliver_payloads"], list(request.options.keys())) |
| 3019 |
|
| 3020 |
self.resource.getConfigurationOptions = getConfigurationOptions |
| 3021 |
self.resource.configureSet = configureSet |
| 3022 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 3023 |
return self.handleRequest(xml) |
| 3024 |
|
| 3025 |
def test_on_configureSetBadFormType(self): |
| 3026 |
""" |
| 3027 |
On a node configuration set request unknown fields should be ignored. |
| 3028 |
""" |
| 3029 |
|
| 3030 |
xml = """ |
| 3031 |
<iq type='set' to='pubsub.example.org' |
| 3032 |
from='[email protected]'> |
| 3033 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3034 |
<configure node='test'> |
| 3035 |
<x xmlns='jabber:x:data' type='result'> |
| 3036 |
<field var='FORM_TYPE' type='hidden'> |
| 3037 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 3038 |
</field> |
| 3039 |
<field var='pubsub#deliver_payloads'><value>0</value></field> |
| 3040 |
<field var='x-myfield'><value>1</value></field> |
| 3041 |
</x> |
| 3042 |
</configure> |
| 3043 |
</pubsub> |
| 3044 |
</iq> |
| 3045 |
""" |
| 3046 |
|
| 3047 |
def cb(result): |
| 3048 |
self.assertEquals("bad-request", result.condition) |
| 3049 |
self.assertEqual("Unexpected form type 'result'", result.text) |
| 3050 |
|
| 3051 |
d = self.handleRequest(xml) |
| 3052 |
self.assertFailure(d, error.StanzaError) |
| 3053 |
d.addCallback(cb) |
| 3054 |
return d |
| 3055 |
|
| 3056 |
def test_on_items(self): |
| 3057 |
""" |
| 3058 |
On a items request, return all items for the given node. |
| 3059 |
""" |
| 3060 |
xml = """ |
| 3061 |
<iq type='get' to='pubsub.example.org' |
| 3062 |
from='[email protected]'> |
| 3063 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3064 |
<items node='test'/> |
| 3065 |
</pubsub> |
| 3066 |
</iq> |
| 3067 |
""" |
| 3068 |
|
| 3069 |
def items(request): |
| 3070 |
return defer.succeed([pubsub.Item("current")]) |
| 3071 |
|
| 3072 |
def cb(element): |
| 3073 |
self.assertEqual(NS_PUBSUB, element.uri) |
| 3074 |
self.assertEqual(NS_PUBSUB, element.items.uri) |
| 3075 |
self.assertEqual(1, len(element.items.children)) |
| 3076 |
item = element.items.children[-1] |
| 3077 |
self.assertTrue(domish.IElement.providedBy(item)) |
| 3078 |
self.assertEqual("item", item.name) |
| 3079 |
self.assertEqual(NS_PUBSUB, item.uri) |
| 3080 |
self.assertEqual("current", item["id"]) |
| 3081 |
|
| 3082 |
self.resource.items = items |
| 3083 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 3084 |
d = self.handleRequest(xml) |
| 3085 |
d.addCallback(cb) |
| 3086 |
return d |
| 3087 |
|
| 3088 |
def test_on_retract(self): |
| 3089 |
""" |
| 3090 |
A retract request should result in L{PubSubResource.retract} |
| 3091 |
being called. |
| 3092 |
""" |
| 3093 |
|
| 3094 |
xml = """ |
| 3095 |
<iq type='set' to='pubsub.example.org' |
| 3096 |
from='[email protected]'> |
| 3097 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3098 |
<retract node='test'> |
| 3099 |
<item id='item1'/> |
| 3100 |
<item id='item2'/> |
| 3101 |
</retract> |
| 3102 |
</pubsub> |
| 3103 |
</iq> |
| 3104 |
""" |
| 3105 |
|
| 3106 |
def retract(request): |
| 3107 |
return defer.succeed(None) |
| 3108 |
|
| 3109 |
self.resource.retract = retract |
| 3110 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 3111 |
return self.handleRequest(xml) |
| 3112 |
|
| 3113 |
def test_on_purge(self): |
| 3114 |
""" |
| 3115 |
A purge request should result in L{PubSubResource.purge} being |
| 3116 |
called. |
| 3117 |
""" |
| 3118 |
|
| 3119 |
xml = """ |
| 3120 |
<iq type='set' to='pubsub.example.org' |
| 3121 |
from='[email protected]'> |
| 3122 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3123 |
<purge node='test'/> |
| 3124 |
</pubsub> |
| 3125 |
</iq> |
| 3126 |
""" |
| 3127 |
|
| 3128 |
def purge(request): |
| 3129 |
return defer.succeed(None) |
| 3130 |
|
| 3131 |
self.resource.purge = purge |
| 3132 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 3133 |
return self.handleRequest(xml) |
| 3134 |
|
| 3135 |
def test_on_delete(self): |
| 3136 |
""" |
| 3137 |
A delete request should result in L{PubSubResource.delete} being |
| 3138 |
called. |
| 3139 |
""" |
| 3140 |
|
| 3141 |
xml = """ |
| 3142 |
<iq type='set' to='pubsub.example.org' |
| 3143 |
from='[email protected]'> |
| 3144 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3145 |
<delete node='test'/> |
| 3146 |
</pubsub> |
| 3147 |
</iq> |
| 3148 |
""" |
| 3149 |
|
| 3150 |
def delete(request): |
| 3151 |
return defer.succeed(None) |
| 3152 |
|
| 3153 |
self.resource.delete = delete |
| 3154 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 3155 |
return self.handleRequest(xml) |
| 3156 |
|
| 3157 |
def test_notifyPublish(self): |
| 3158 |
""" |
| 3159 |
Publish notifications are sent to the subscribers. |
| 3160 |
""" |
| 3161 |
subscriber = JID("[email protected]") |
| 3162 |
subscriptions = [pubsub.Subscription("test", subscriber, "subscribed")] |
| 3163 |
items = [pubsub.Item("current")] |
| 3164 |
notifications = [(subscriber, subscriptions, items)] |
| 3165 |
self.service.notifyPublish(JID("pubsub.example.org"), "test", notifications) |
| 3166 |
message = self.stub.output[-1] |
| 3167 |
|
| 3168 |
self.assertEquals("message", message.name) |
| 3169 |
self.assertIdentical(None, message.uri) |
| 3170 |
self.assertEquals("[email protected]", message["to"]) |
| 3171 |
self.assertEquals("pubsub.example.org", message["from"]) |
| 3172 |
self.assertTrue(message.event) |
| 3173 |
self.assertEquals(NS_PUBSUB_EVENT, message.event.uri) |
| 3174 |
self.assertTrue(message.event.items) |
| 3175 |
self.assertEquals(NS_PUBSUB_EVENT, message.event.items.uri) |
| 3176 |
self.assertTrue(message.event.items.hasAttribute("node")) |
| 3177 |
self.assertEquals("test", message.event.items["node"]) |
| 3178 |
itemElements = list( |
| 3179 |
domish.generateElementsQNamed( |
| 3180 |
message.event.items.children, "item", NS_PUBSUB_EVENT |
| 3181 |
) |
| 3182 |
) |
| 3183 |
self.assertEquals(1, len(itemElements)) |
| 3184 |
self.assertEquals("current", itemElements[0].getAttribute("id")) |
| 3185 |
|
| 3186 |
def test_notifyRetract(self): |
| 3187 |
""" |
| 3188 |
Items retraction notifications are sent to the subscribers. |
| 3189 |
""" |
| 3190 |
subscriber = JID("[email protected]") |
| 3191 |
subscriptions = [pubsub.Subscription("test", subscriber, "subscribed")] |
| 3192 |
items = [pubsub.Item("current")] |
| 3193 |
notifications = [(subscriber, subscriptions, items)] |
| 3194 |
self.service.notifyRetract(JID("pubsub.example.org"), "test", notifications) |
| 3195 |
message = self.stub.output[-1] |
| 3196 |
|
| 3197 |
self.assertEquals("message", message.name) |
| 3198 |
self.assertIdentical(None, message.uri) |
| 3199 |
self.assertEquals("[email protected]", message["to"]) |
| 3200 |
self.assertEquals("pubsub.example.org", message["from"]) |
| 3201 |
self.assertTrue(message.event) |
| 3202 |
self.assertEquals(NS_PUBSUB_EVENT, message.event.uri) |
| 3203 |
self.assertTrue(message.event.items) |
| 3204 |
self.assertEquals(NS_PUBSUB_EVENT, message.event.items.uri) |
| 3205 |
self.assertTrue(message.event.items.hasAttribute("node")) |
| 3206 |
self.assertEquals("test", message.event.items["node"]) |
| 3207 |
itemElements = list( |
| 3208 |
domish.generateElementsQNamed( |
| 3209 |
message.event.items.children, "retract", NS_PUBSUB_EVENT |
| 3210 |
) |
| 3211 |
) |
| 3212 |
self.assertEquals(1, len(itemElements)) |
| 3213 |
self.assertEquals("current", itemElements[0].getAttribute("id")) |
| 3214 |
|
| 3215 |
def test_notifyPublishCollection(self): |
| 3216 |
""" |
| 3217 |
Publish notifications are sent to the subscribers of collections. |
| 3218 |
|
| 3219 |
The node the item was published to is on the C{items} element, while |
| 3220 |
the subscribed-to node is in the C{'Collections'} SHIM header. |
| 3221 |
""" |
| 3222 |
subscriber = JID("[email protected]") |
| 3223 |
subscriptions = [pubsub.Subscription("", subscriber, "subscribed")] |
| 3224 |
items = [pubsub.Item("current")] |
| 3225 |
notifications = [(subscriber, subscriptions, items)] |
| 3226 |
self.service.notifyPublish(JID("pubsub.example.org"), "test", notifications) |
| 3227 |
message = self.stub.output[-1] |
| 3228 |
|
| 3229 |
self.assertTrue(message.event.items.hasAttribute("node")) |
| 3230 |
self.assertEquals("test", message.event.items["node"]) |
| 3231 |
headers = shim.extractHeaders(message) |
| 3232 |
self.assertIn("Collection", headers) |
| 3233 |
self.assertIn("", headers["Collection"]) |
| 3234 |
|
| 3235 |
def test_notifyRetractCollection(self): |
| 3236 |
""" |
| 3237 |
Retraction notifications are sent to the subscribers of collections. |
| 3238 |
|
| 3239 |
The node the item was retracted from is on the C{items} element, while |
| 3240 |
the subscribed-to node is in the C{'Collections'} SHIM header. |
| 3241 |
""" |
| 3242 |
subscriber = JID("[email protected]") |
| 3243 |
subscriptions = [pubsub.Subscription("", subscriber, "subscribed")] |
| 3244 |
items = [pubsub.Item("current")] |
| 3245 |
notifications = [(subscriber, subscriptions, items)] |
| 3246 |
self.service.notifyRetract(JID("pubsub.example.org"), "test", notifications) |
| 3247 |
message = self.stub.output[-1] |
| 3248 |
|
| 3249 |
self.assertTrue(message.event.items.hasAttribute("node")) |
| 3250 |
self.assertEquals("test", message.event.items["node"]) |
| 3251 |
headers = shim.extractHeaders(message) |
| 3252 |
self.assertIn("Collection", headers) |
| 3253 |
self.assertIn("", headers["Collection"]) |
| 3254 |
|
| 3255 |
def test_notifyDelete(self): |
| 3256 |
""" |
| 3257 |
Subscribers should be sent a delete notification. |
| 3258 |
""" |
| 3259 |
subscriptions = [JID("[email protected]")] |
| 3260 |
self.service.notifyDelete(JID("pubsub.example.org"), "test", subscriptions) |
| 3261 |
message = self.stub.output[-1] |
| 3262 |
|
| 3263 |
self.assertEquals("message", message.name) |
| 3264 |
self.assertIdentical(None, message.uri) |
| 3265 |
self.assertEquals("[email protected]", message["to"]) |
| 3266 |
self.assertEquals("pubsub.example.org", message["from"]) |
| 3267 |
self.assertTrue(message.event) |
| 3268 |
self.assertEqual(NS_PUBSUB_EVENT, message.event.uri) |
| 3269 |
self.assertTrue(message.event.delete) |
| 3270 |
self.assertEqual(NS_PUBSUB_EVENT, message.event.delete.uri) |
| 3271 |
self.assertTrue(message.event.delete.hasAttribute("node")) |
| 3272 |
self.assertEqual("test", message.event.delete["node"]) |
| 3273 |
|
| 3274 |
def test_notifyDeleteRedirect(self): |
| 3275 |
""" |
| 3276 |
Subscribers should be sent a delete notification with redirect. |
| 3277 |
""" |
| 3278 |
redirectURI = "xmpp:pubsub.example.org?;node=test2" |
| 3279 |
subscriptions = [JID("[email protected]")] |
| 3280 |
self.service.notifyDelete( |
| 3281 |
JID("pubsub.example.org"), "test", subscriptions, redirectURI |
| 3282 |
) |
| 3283 |
message = self.stub.output[-1] |
| 3284 |
|
| 3285 |
self.assertEquals("message", message.name) |
| 3286 |
self.assertIdentical(None, message.uri) |
| 3287 |
self.assertEquals("[email protected]", message["to"]) |
| 3288 |
self.assertEquals("pubsub.example.org", message["from"]) |
| 3289 |
self.assertTrue(message.event) |
| 3290 |
self.assertEqual(NS_PUBSUB_EVENT, message.event.uri) |
| 3291 |
self.assertTrue(message.event.delete) |
| 3292 |
self.assertEqual(NS_PUBSUB_EVENT, message.event.delete.uri) |
| 3293 |
self.assertTrue(message.event.delete.hasAttribute("node")) |
| 3294 |
self.assertEqual("test", message.event.delete["node"]) |
| 3295 |
self.assertTrue(message.event.delete.redirect) |
| 3296 |
self.assertEqual(NS_PUBSUB_EVENT, message.event.delete.redirect.uri) |
| 3297 |
self.assertTrue(message.event.delete.redirect.hasAttribute("uri")) |
| 3298 |
self.assertEqual(redirectURI, message.event.delete.redirect["uri"]) |
| 3299 |
|
| 3300 |
def test_on_subscriptionsGet(self): |
| 3301 |
""" |
| 3302 |
Getting subscription options is not supported. |
| 3303 |
""" |
| 3304 |
|
| 3305 |
xml = """ |
| 3306 |
<iq type='get' to='pubsub.example.org' |
| 3307 |
from='[email protected]'> |
| 3308 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3309 |
<subscriptions/> |
| 3310 |
</pubsub> |
| 3311 |
</iq> |
| 3312 |
""" |
| 3313 |
|
| 3314 |
def cb(result): |
| 3315 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3316 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3317 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3318 |
self.assertEquals("manage-subscriptions", result.appCondition["feature"]) |
| 3319 |
|
| 3320 |
d = self.handleRequest(xml) |
| 3321 |
self.assertFailure(d, error.StanzaError) |
| 3322 |
d.addCallback(cb) |
| 3323 |
return d |
| 3324 |
|
| 3325 |
def test_on_subscriptionsSet(self): |
| 3326 |
""" |
| 3327 |
Setting subscription options is not supported. |
| 3328 |
""" |
| 3329 |
|
| 3330 |
xml = """ |
| 3331 |
<iq type='set' to='pubsub.example.org' |
| 3332 |
from='[email protected]'> |
| 3333 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3334 |
<subscriptions node='test'/> |
| 3335 |
</pubsub> |
| 3336 |
</iq> |
| 3337 |
""" |
| 3338 |
|
| 3339 |
def cb(result): |
| 3340 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3341 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3342 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3343 |
self.assertEquals("manage-subscriptions", result.appCondition["feature"]) |
| 3344 |
|
| 3345 |
d = self.handleRequest(xml) |
| 3346 |
self.assertFailure(d, error.StanzaError) |
| 3347 |
d.addCallback(cb) |
| 3348 |
return d |
| 3349 |
|
| 3350 |
def test_on_affiliationsGet(self): |
| 3351 |
""" |
| 3352 |
Getting node affiliations should have. |
| 3353 |
""" |
| 3354 |
|
| 3355 |
xml = """ |
| 3356 |
<iq type='get' to='pubsub.example.org' |
| 3357 |
from='[email protected]'> |
| 3358 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3359 |
<affiliations node='test'/> |
| 3360 |
</pubsub> |
| 3361 |
</iq> |
| 3362 |
""" |
| 3363 |
|
| 3364 |
def affiliationsGet(request): |
| 3365 |
self.assertEquals("test", request.nodeIdentifier) |
| 3366 |
return defer.succeed({JID("[email protected]"): "owner"}) |
| 3367 |
|
| 3368 |
def cb(element): |
| 3369 |
self.assertEquals("pubsub", element.name) |
| 3370 |
self.assertEquals(NS_PUBSUB_OWNER, element.uri) |
| 3371 |
self.assertEquals(NS_PUBSUB_OWNER, element.affiliations.uri) |
| 3372 |
self.assertEquals("test", element.affiliations["node"]) |
| 3373 |
children = list(element.affiliations.elements()) |
| 3374 |
self.assertEquals(1, len(children)) |
| 3375 |
affiliation = children[0] |
| 3376 |
self.assertEquals("affiliation", affiliation.name) |
| 3377 |
self.assertEquals(NS_PUBSUB_OWNER, affiliation.uri) |
| 3378 |
self.assertEquals("[email protected]", affiliation["jid"]) |
| 3379 |
self.assertEquals("owner", affiliation["affiliation"]) |
| 3380 |
|
| 3381 |
self.resource.affiliationsGet = affiliationsGet |
| 3382 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 3383 |
d = self.handleRequest(xml) |
| 3384 |
d.addCallback(cb) |
| 3385 |
return d |
| 3386 |
|
| 3387 |
def test_on_affiliationsGetEmptyNode(self): |
| 3388 |
""" |
| 3389 |
Getting node affiliations without node should be None (all affiliations). |
| 3390 |
""" |
| 3391 |
|
| 3392 |
xml = """ |
| 3393 |
<iq type='get' to='pubsub.example.org' |
| 3394 |
from='[email protected]'> |
| 3395 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3396 |
<affiliations/> |
| 3397 |
</pubsub> |
| 3398 |
</iq> |
| 3399 |
""" |
| 3400 |
|
| 3401 |
def affiliationsGet(request): |
| 3402 |
self.assertIsNone(request.nodeIdentifier) |
| 3403 |
return defer.succeed({}) |
| 3404 |
|
| 3405 |
def cb(element): |
| 3406 |
self.assertFalse(element.affiliations.hasAttribute("node")) |
| 3407 |
|
| 3408 |
self.resource.affiliationsGet = affiliationsGet |
| 3409 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 3410 |
d = self.handleRequest(xml) |
| 3411 |
d.addCallback(cb) |
| 3412 |
return d |
| 3413 |
|
| 3414 |
def test_on_affiliationsSet(self): |
| 3415 |
""" |
| 3416 |
Setting node affiliations has the affiliations to be modified. |
| 3417 |
""" |
| 3418 |
|
| 3419 |
xml = """ |
| 3420 |
<iq type='set' to='pubsub.example.org' |
| 3421 |
from='[email protected]'> |
| 3422 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3423 |
<affiliations node='test'> |
| 3424 |
<affiliation jid='[email protected]' affiliation='publisher'/> |
| 3425 |
</affiliations> |
| 3426 |
</pubsub> |
| 3427 |
</iq> |
| 3428 |
""" |
| 3429 |
|
| 3430 |
def affiliationsSet(request): |
| 3431 |
self.assertEquals("test", request.nodeIdentifier) |
| 3432 |
otherJID = JID("[email protected]") |
| 3433 |
self.assertIn(otherJID, request.affiliations) |
| 3434 |
self.assertEquals("publisher", request.affiliations[otherJID]) |
| 3435 |
|
| 3436 |
self.resource.affiliationsSet = affiliationsSet |
| 3437 |
return self.handleRequest(xml) |
| 3438 |
|
| 3439 |
def test_on_affiliationsSetBareJID(self): |
| 3440 |
""" |
| 3441 |
Affiliations are always on the bare JID. |
| 3442 |
""" |
| 3443 |
|
| 3444 |
xml = """ |
| 3445 |
<iq type='set' to='pubsub.example.org' |
| 3446 |
from='[email protected]'> |
| 3447 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3448 |
<affiliations node='test'> |
| 3449 |
<affiliation jid='[email protected]/Home' |
| 3450 |
affiliation='publisher'/> |
| 3451 |
</affiliations> |
| 3452 |
</pubsub> |
| 3453 |
</iq> |
| 3454 |
""" |
| 3455 |
|
| 3456 |
def affiliationsSet(request): |
| 3457 |
otherJID = JID("[email protected]") |
| 3458 |
self.assertIn(otherJID, request.affiliations) |
| 3459 |
|
| 3460 |
self.resource.affiliationsSet = affiliationsSet |
| 3461 |
return self.handleRequest(xml) |
| 3462 |
|
| 3463 |
def test_on_affiliationsSetMultipleForSameEntity(self): |
| 3464 |
""" |
| 3465 |
Setting node affiliations can only have one item per entity. |
| 3466 |
""" |
| 3467 |
|
| 3468 |
xml = """ |
| 3469 |
<iq type='set' to='pubsub.example.org' |
| 3470 |
from='[email protected]'> |
| 3471 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3472 |
<affiliations node='test'> |
| 3473 |
<affiliation jid='[email protected]' affiliation='publisher'/> |
| 3474 |
<affiliation jid='[email protected]' affiliation='owner'/> |
| 3475 |
</affiliations> |
| 3476 |
</pubsub> |
| 3477 |
</iq> |
| 3478 |
""" |
| 3479 |
|
| 3480 |
def cb(result): |
| 3481 |
self.assertEquals("bad-request", result.condition) |
| 3482 |
|
| 3483 |
d = self.handleRequest(xml) |
| 3484 |
self.assertFailure(d, error.StanzaError) |
| 3485 |
d.addCallback(cb) |
| 3486 |
return d |
| 3487 |
|
| 3488 |
def test_on_affiliationsSetMissingJID(self): |
| 3489 |
""" |
| 3490 |
Setting node affiliations must include a JID per affiliation. |
| 3491 |
""" |
| 3492 |
|
| 3493 |
xml = """ |
| 3494 |
<iq type='set' to='pubsub.example.org' |
| 3495 |
from='[email protected]'> |
| 3496 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3497 |
<affiliations node='test'> |
| 3498 |
<affiliation affiliation='publisher'/> |
| 3499 |
</affiliations> |
| 3500 |
</pubsub> |
| 3501 |
</iq> |
| 3502 |
""" |
| 3503 |
|
| 3504 |
def cb(result): |
| 3505 |
self.assertEquals("bad-request", result.condition) |
| 3506 |
|
| 3507 |
d = self.handleRequest(xml) |
| 3508 |
self.assertFailure(d, error.StanzaError) |
| 3509 |
d.addCallback(cb) |
| 3510 |
return d |
| 3511 |
|
| 3512 |
def test_on_affiliationsSetMissingAffiliation(self): |
| 3513 |
""" |
| 3514 |
Setting node affiliations must include an affiliation. |
| 3515 |
""" |
| 3516 |
|
| 3517 |
xml = """ |
| 3518 |
<iq type='set' to='pubsub.example.org' |
| 3519 |
from='[email protected]'> |
| 3520 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3521 |
<affiliations node='test'> |
| 3522 |
<affiliation jid='[email protected]'/> |
| 3523 |
</affiliations> |
| 3524 |
</pubsub> |
| 3525 |
</iq> |
| 3526 |
""" |
| 3527 |
|
| 3528 |
def cb(result): |
| 3529 |
self.assertEquals("bad-request", result.condition) |
| 3530 |
|
| 3531 |
d = self.handleRequest(xml) |
| 3532 |
self.assertFailure(d, error.StanzaError) |
| 3533 |
d.addCallback(cb) |
| 3534 |
return d |
| 3535 |
|
| 3536 |
|
| 3537 |
class PubSubServiceWithoutResourceTest(unittest.TestCase, TestableRequestHandlerMixin): |
| 3538 |
|
| 3539 |
def setUp(self): |
| 3540 |
self.stub = XmlStreamStub() |
| 3541 |
self.service = pubsub.PubSubService() |
| 3542 |
self.service.send = self.stub.xmlstream.send |
| 3543 |
|
| 3544 |
def test_getDiscoInfo(self): |
| 3545 |
""" |
| 3546 |
Test getDiscoInfo calls getNodeInfo and returns some minimal info. |
| 3547 |
""" |
| 3548 |
|
| 3549 |
def cb(info): |
| 3550 |
discoInfo = disco.DiscoInfo() |
| 3551 |
for item in info: |
| 3552 |
discoInfo.append(item) |
| 3553 |
self.assertIn(("pubsub", "service"), discoInfo.identities) |
| 3554 |
self.assertIn(disco.NS_DISCO_ITEMS, discoInfo.features) |
| 3555 |
|
| 3556 |
d = self.service.getDiscoInfo( |
| 3557 |
JID("[email protected]/home"), JID("pubsub.example.org"), "" |
| 3558 |
) |
| 3559 |
d.addCallback(cb) |
| 3560 |
return d |
| 3561 |
|
| 3562 |
def test_publish(self): |
| 3563 |
""" |
| 3564 |
Non-overridden L{PubSubService.publish} yields unsupported error. |
| 3565 |
""" |
| 3566 |
|
| 3567 |
xml = """ |
| 3568 |
<iq type='set' to='pubsub.example.org' |
| 3569 |
from='[email protected]'> |
| 3570 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3571 |
<publish node='mynode'/> |
| 3572 |
</pubsub> |
| 3573 |
</iq> |
| 3574 |
""" |
| 3575 |
|
| 3576 |
def cb(result): |
| 3577 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3578 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3579 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3580 |
self.assertEquals("publish", result.appCondition["feature"]) |
| 3581 |
|
| 3582 |
d = self.handleRequest(xml) |
| 3583 |
self.assertFailure(d, error.StanzaError) |
| 3584 |
d.addCallback(cb) |
| 3585 |
return d |
| 3586 |
|
| 3587 |
def test_subscribe(self): |
| 3588 |
""" |
| 3589 |
Non-overridden L{PubSubService.subscribe} yields unsupported error. |
| 3590 |
""" |
| 3591 |
|
| 3592 |
xml = """ |
| 3593 |
<iq type='set' to='pubsub.example.org' |
| 3594 |
from='[email protected]'> |
| 3595 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3596 |
<subscribe node='test' jid='[email protected]/Home'/> |
| 3597 |
</pubsub> |
| 3598 |
</iq> |
| 3599 |
""" |
| 3600 |
|
| 3601 |
def cb(result): |
| 3602 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3603 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3604 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3605 |
self.assertEquals("subscribe", result.appCondition["feature"]) |
| 3606 |
|
| 3607 |
d = self.handleRequest(xml) |
| 3608 |
self.assertFailure(d, error.StanzaError) |
| 3609 |
d.addCallback(cb) |
| 3610 |
return d |
| 3611 |
|
| 3612 |
def test_unsubscribe(self): |
| 3613 |
""" |
| 3614 |
Non-overridden L{PubSubService.unsubscribe} yields unsupported error. |
| 3615 |
""" |
| 3616 |
|
| 3617 |
xml = """ |
| 3618 |
<iq type='set' to='pubsub.example.org' |
| 3619 |
from='[email protected]'> |
| 3620 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3621 |
<unsubscribe node='test' jid='[email protected]/Home'/> |
| 3622 |
</pubsub> |
| 3623 |
</iq> |
| 3624 |
""" |
| 3625 |
|
| 3626 |
def cb(result): |
| 3627 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3628 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3629 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3630 |
self.assertEquals("subscribe", result.appCondition["feature"]) |
| 3631 |
|
| 3632 |
d = self.handleRequest(xml) |
| 3633 |
self.assertFailure(d, error.StanzaError) |
| 3634 |
d.addCallback(cb) |
| 3635 |
return d |
| 3636 |
|
| 3637 |
def test_subscriptions(self): |
| 3638 |
""" |
| 3639 |
Non-overridden L{PubSubService.subscriptions} yields unsupported error. |
| 3640 |
""" |
| 3641 |
|
| 3642 |
xml = """ |
| 3643 |
<iq type='get' to='pubsub.example.org' |
| 3644 |
from='[email protected]'> |
| 3645 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3646 |
<subscriptions/> |
| 3647 |
</pubsub> |
| 3648 |
</iq> |
| 3649 |
""" |
| 3650 |
|
| 3651 |
def cb(result): |
| 3652 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3653 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3654 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3655 |
self.assertEquals("retrieve-subscriptions", result.appCondition["feature"]) |
| 3656 |
|
| 3657 |
d = self.handleRequest(xml) |
| 3658 |
self.assertFailure(d, error.StanzaError) |
| 3659 |
d.addCallback(cb) |
| 3660 |
return d |
| 3661 |
|
| 3662 |
def test_affiliations(self): |
| 3663 |
""" |
| 3664 |
Non-overridden L{PubSubService.affiliations} yields unsupported error. |
| 3665 |
""" |
| 3666 |
|
| 3667 |
xml = """ |
| 3668 |
<iq type='get' to='pubsub.example.org' |
| 3669 |
from='[email protected]'> |
| 3670 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3671 |
<affiliations/> |
| 3672 |
</pubsub> |
| 3673 |
</iq> |
| 3674 |
""" |
| 3675 |
|
| 3676 |
def cb(result): |
| 3677 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3678 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3679 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3680 |
self.assertEquals("retrieve-affiliations", result.appCondition["feature"]) |
| 3681 |
|
| 3682 |
d = self.handleRequest(xml) |
| 3683 |
self.assertFailure(d, error.StanzaError) |
| 3684 |
d.addCallback(cb) |
| 3685 |
return d |
| 3686 |
|
| 3687 |
def test_create(self): |
| 3688 |
""" |
| 3689 |
Non-overridden L{PubSubService.create} yields unsupported error. |
| 3690 |
""" |
| 3691 |
|
| 3692 |
xml = """ |
| 3693 |
<iq type='set' to='pubsub.example.org' |
| 3694 |
from='[email protected]'> |
| 3695 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3696 |
<create node='mynode'/> |
| 3697 |
</pubsub> |
| 3698 |
</iq> |
| 3699 |
""" |
| 3700 |
|
| 3701 |
def cb(result): |
| 3702 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3703 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3704 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3705 |
self.assertEquals("create-nodes", result.appCondition["feature"]) |
| 3706 |
|
| 3707 |
d = self.handleRequest(xml) |
| 3708 |
self.assertFailure(d, error.StanzaError) |
| 3709 |
d.addCallback(cb) |
| 3710 |
return d |
| 3711 |
|
| 3712 |
def test_getDefaultConfiguration(self): |
| 3713 |
""" |
| 3714 |
Non-overridden L{PubSubService.getDefaultConfiguration} yields |
| 3715 |
unsupported error. |
| 3716 |
""" |
| 3717 |
|
| 3718 |
xml = """ |
| 3719 |
<iq type='get' to='pubsub.example.org' |
| 3720 |
from='[email protected]'> |
| 3721 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3722 |
<default/> |
| 3723 |
</pubsub> |
| 3724 |
</iq> |
| 3725 |
""" |
| 3726 |
|
| 3727 |
def cb(result): |
| 3728 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3729 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3730 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3731 |
self.assertEquals("retrieve-default", result.appCondition["feature"]) |
| 3732 |
|
| 3733 |
d = self.handleRequest(xml) |
| 3734 |
self.assertFailure(d, error.StanzaError) |
| 3735 |
d.addCallback(cb) |
| 3736 |
return d |
| 3737 |
|
| 3738 |
def test_getConfiguration(self): |
| 3739 |
""" |
| 3740 |
Non-overridden L{PubSubService.getConfiguration} yields unsupported |
| 3741 |
error. |
| 3742 |
""" |
| 3743 |
|
| 3744 |
xml = """ |
| 3745 |
<iq type='get' to='pubsub.example.org' |
| 3746 |
from='[email protected]'> |
| 3747 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3748 |
<configure/> |
| 3749 |
</pubsub> |
| 3750 |
</iq> |
| 3751 |
""" |
| 3752 |
|
| 3753 |
def cb(result): |
| 3754 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3755 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3756 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3757 |
self.assertEquals("config-node", result.appCondition["feature"]) |
| 3758 |
|
| 3759 |
d = self.handleRequest(xml) |
| 3760 |
self.assertFailure(d, error.StanzaError) |
| 3761 |
d.addCallback(cb) |
| 3762 |
return d |
| 3763 |
|
| 3764 |
def test_setConfiguration(self): |
| 3765 |
""" |
| 3766 |
Non-overridden L{PubSubService.setConfiguration} yields unsupported |
| 3767 |
error. |
| 3768 |
""" |
| 3769 |
|
| 3770 |
xml = """ |
| 3771 |
<iq type='set' to='pubsub.example.org' |
| 3772 |
from='[email protected]'> |
| 3773 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3774 |
<configure node='test'> |
| 3775 |
<x xmlns='jabber:x:data' type='submit'> |
| 3776 |
<field var='FORM_TYPE' type='hidden'> |
| 3777 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 3778 |
</field> |
| 3779 |
<field var='pubsub#deliver_payloads'><value>0</value></field> |
| 3780 |
<field var='pubsub#persist_items'><value>1</value></field> |
| 3781 |
</x> |
| 3782 |
</configure> |
| 3783 |
</pubsub> |
| 3784 |
</iq> |
| 3785 |
""" |
| 3786 |
|
| 3787 |
def cb(result): |
| 3788 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3789 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3790 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3791 |
self.assertEquals("config-node", result.appCondition["feature"]) |
| 3792 |
|
| 3793 |
d = self.handleRequest(xml) |
| 3794 |
self.assertFailure(d, error.StanzaError) |
| 3795 |
d.addCallback(cb) |
| 3796 |
return d |
| 3797 |
|
| 3798 |
def test_setConfigurationOptionsDict(self): |
| 3799 |
""" |
| 3800 |
Options should be passed as a dictionary, not a form. |
| 3801 |
""" |
| 3802 |
|
| 3803 |
xml = """ |
| 3804 |
<iq type='set' to='pubsub.example.org' |
| 3805 |
from='[email protected]'> |
| 3806 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3807 |
<configure node='test'> |
| 3808 |
<x xmlns='jabber:x:data' type='submit'> |
| 3809 |
<field var='FORM_TYPE' type='hidden'> |
| 3810 |
<value>http://jabber.org/protocol/pubsub#node_config</value> |
| 3811 |
</field> |
| 3812 |
<field var='pubsub#deliver_payloads'><value>0</value></field> |
| 3813 |
<field var='pubsub#persist_items'><value>1</value></field> |
| 3814 |
</x> |
| 3815 |
</configure> |
| 3816 |
</pubsub> |
| 3817 |
</iq> |
| 3818 |
""" |
| 3819 |
|
| 3820 |
def getConfigurationOptions(): |
| 3821 |
return { |
| 3822 |
"pubsub#persist_items": { |
| 3823 |
"type": "boolean", |
| 3824 |
"label": "Persist items to storage", |
| 3825 |
}, |
| 3826 |
"pubsub#deliver_payloads": { |
| 3827 |
"type": "boolean", |
| 3828 |
"label": "Deliver payloads with event notifications", |
| 3829 |
}, |
| 3830 |
} |
| 3831 |
|
| 3832 |
def setConfiguration(requestor, service, nodeIdentifier, options): |
| 3833 |
self.assertIn("pubsub#deliver_payloads", options) |
| 3834 |
self.assertFalse(options["pubsub#deliver_payloads"]) |
| 3835 |
self.assertIn("pubsub#persist_items", options) |
| 3836 |
self.assertTrue(options["pubsub#persist_items"]) |
| 3837 |
|
| 3838 |
self.service.getConfigurationOptions = getConfigurationOptions |
| 3839 |
self.service.setConfiguration = setConfiguration |
| 3840 |
return self.handleRequest(xml) |
| 3841 |
|
| 3842 |
def test_items(self): |
| 3843 |
""" |
| 3844 |
Non-overridden L{PubSubService.items} yields unsupported error. |
| 3845 |
""" |
| 3846 |
xml = """ |
| 3847 |
<iq type='get' to='pubsub.example.org' |
| 3848 |
from='[email protected]'> |
| 3849 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3850 |
<items node='test'/> |
| 3851 |
</pubsub> |
| 3852 |
</iq> |
| 3853 |
""" |
| 3854 |
|
| 3855 |
def cb(result): |
| 3856 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3857 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3858 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3859 |
self.assertEquals("retrieve-items", result.appCondition["feature"]) |
| 3860 |
|
| 3861 |
d = self.handleRequest(xml) |
| 3862 |
self.assertFailure(d, error.StanzaError) |
| 3863 |
d.addCallback(cb) |
| 3864 |
return d |
| 3865 |
|
| 3866 |
def test_retract(self): |
| 3867 |
""" |
| 3868 |
Non-overridden L{PubSubService.retract} yields unsupported error. |
| 3869 |
""" |
| 3870 |
xml = """ |
| 3871 |
<iq type='set' to='pubsub.example.org' |
| 3872 |
from='[email protected]'> |
| 3873 |
<pubsub xmlns='http://jabber.org/protocol/pubsub'> |
| 3874 |
<retract node='test'> |
| 3875 |
<item id='item1'/> |
| 3876 |
<item id='item2'/> |
| 3877 |
</retract> |
| 3878 |
</pubsub> |
| 3879 |
</iq> |
| 3880 |
""" |
| 3881 |
|
| 3882 |
def cb(result): |
| 3883 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3884 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3885 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3886 |
self.assertEquals("retract-items", result.appCondition["feature"]) |
| 3887 |
|
| 3888 |
d = self.handleRequest(xml) |
| 3889 |
self.assertFailure(d, error.StanzaError) |
| 3890 |
d.addCallback(cb) |
| 3891 |
return d |
| 3892 |
|
| 3893 |
def test_purge(self): |
| 3894 |
""" |
| 3895 |
Non-overridden L{PubSubService.purge} yields unsupported error. |
| 3896 |
""" |
| 3897 |
xml = """ |
| 3898 |
<iq type='set' to='pubsub.example.org' |
| 3899 |
from='[email protected]'> |
| 3900 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3901 |
<purge node='test'/> |
| 3902 |
</pubsub> |
| 3903 |
</iq> |
| 3904 |
""" |
| 3905 |
|
| 3906 |
def cb(result): |
| 3907 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3908 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3909 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3910 |
self.assertEquals("purge-nodes", result.appCondition["feature"]) |
| 3911 |
|
| 3912 |
d = self.handleRequest(xml) |
| 3913 |
self.assertFailure(d, error.StanzaError) |
| 3914 |
d.addCallback(cb) |
| 3915 |
return d |
| 3916 |
|
| 3917 |
def test_delete(self): |
| 3918 |
""" |
| 3919 |
Non-overridden L{PubSubService.delete} yields unsupported error. |
| 3920 |
""" |
| 3921 |
xml = """ |
| 3922 |
<iq type='set' to='pubsub.example.org' |
| 3923 |
from='[email protected]'> |
| 3924 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3925 |
<delete node='test'/> |
| 3926 |
</pubsub> |
| 3927 |
</iq> |
| 3928 |
""" |
| 3929 |
|
| 3930 |
def cb(result): |
| 3931 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3932 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3933 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3934 |
self.assertEquals("delete-nodes", result.appCondition["feature"]) |
| 3935 |
|
| 3936 |
d = self.handleRequest(xml) |
| 3937 |
self.assertFailure(d, error.StanzaError) |
| 3938 |
d.addCallback(cb) |
| 3939 |
return d |
| 3940 |
|
| 3941 |
def test_unknown(self): |
| 3942 |
""" |
| 3943 |
Unknown verb yields unsupported error. |
| 3944 |
""" |
| 3945 |
xml = """ |
| 3946 |
<iq type='get' to='pubsub.example.org' |
| 3947 |
from='[email protected]'> |
| 3948 |
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'> |
| 3949 |
<affiliations node='test'/> |
| 3950 |
</pubsub> |
| 3951 |
</iq> |
| 3952 |
""" |
| 3953 |
|
| 3954 |
def cb(result): |
| 3955 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3956 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3957 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 3958 |
|
| 3959 |
d = self.handleRequest(xml) |
| 3960 |
self.assertFailure(d, error.StanzaError) |
| 3961 |
d.addCallback(cb) |
| 3962 |
return d |
| 3963 |
|
| 3964 |
|
| 3965 |
class PubSubResourceTest(unittest.TestCase): |
| 3966 |
|
| 3967 |
def setUp(self): |
| 3968 |
self.resource = pubsub.PubSubResource() |
| 3969 |
|
| 3970 |
def test_interface(self): |
| 3971 |
""" |
| 3972 |
Do instances of L{pubsub.PubSubResource} provide L{itx_xmpp.IPubSubResource}? |
| 3973 |
""" |
| 3974 |
verify.verifyObject(itx_xmpp.IPubSubResource, self.resource) |
| 3975 |
|
| 3976 |
def test_getNodes(self): |
| 3977 |
""" |
| 3978 |
Default getNodes returns an empty list. |
| 3979 |
""" |
| 3980 |
|
| 3981 |
def cb(nodes): |
| 3982 |
self.assertEquals([], nodes) |
| 3983 |
|
| 3984 |
d = self.resource.getNodes( |
| 3985 |
JID("[email protected]/home"), JID("pubsub.example.org"), "" |
| 3986 |
) |
| 3987 |
d.addCallback(cb) |
| 3988 |
return d |
| 3989 |
|
| 3990 |
def test_publish(self): |
| 3991 |
""" |
| 3992 |
Non-overridden L{PubSubResource.publish} yields unsupported |
| 3993 |
error. |
| 3994 |
""" |
| 3995 |
|
| 3996 |
def cb(result): |
| 3997 |
self.assertEquals("feature-not-implemented", result.condition) |
| 3998 |
self.assertEquals("unsupported", result.appCondition.name) |
| 3999 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4000 |
self.assertEquals("publish", result.appCondition["feature"]) |
| 4001 |
|
| 4002 |
d = self.resource.publish(pubsub.PubSubRequest()) |
| 4003 |
self.assertFailure(d, error.StanzaError) |
| 4004 |
d.addCallback(cb) |
| 4005 |
return d |
| 4006 |
|
| 4007 |
def test_subscribe(self): |
| 4008 |
""" |
| 4009 |
Non-overridden subscriptions yields unsupported error. |
| 4010 |
""" |
| 4011 |
|
| 4012 |
def cb(result): |
| 4013 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4014 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4015 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4016 |
self.assertEquals("subscribe", result.appCondition["feature"]) |
| 4017 |
|
| 4018 |
d = self.resource.subscribe(pubsub.PubSubRequest()) |
| 4019 |
self.assertFailure(d, error.StanzaError) |
| 4020 |
d.addCallback(cb) |
| 4021 |
return d |
| 4022 |
|
| 4023 |
def test_unsubscribe(self): |
| 4024 |
""" |
| 4025 |
Non-overridden unsubscribe yields unsupported error. |
| 4026 |
""" |
| 4027 |
|
| 4028 |
def cb(result): |
| 4029 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4030 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4031 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4032 |
self.assertEquals("subscribe", result.appCondition["feature"]) |
| 4033 |
|
| 4034 |
d = self.resource.unsubscribe(pubsub.PubSubRequest()) |
| 4035 |
self.assertFailure(d, error.StanzaError) |
| 4036 |
d.addCallback(cb) |
| 4037 |
return d |
| 4038 |
|
| 4039 |
def test_subscriptions(self): |
| 4040 |
""" |
| 4041 |
Non-overridden subscriptions yields unsupported error. |
| 4042 |
""" |
| 4043 |
|
| 4044 |
def cb(result): |
| 4045 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4046 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4047 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4048 |
self.assertEquals("retrieve-subscriptions", result.appCondition["feature"]) |
| 4049 |
|
| 4050 |
d = self.resource.subscriptions(pubsub.PubSubRequest()) |
| 4051 |
self.assertFailure(d, error.StanzaError) |
| 4052 |
d.addCallback(cb) |
| 4053 |
return d |
| 4054 |
|
| 4055 |
def test_affiliations(self): |
| 4056 |
""" |
| 4057 |
Non-overridden affiliations yields unsupported error. |
| 4058 |
""" |
| 4059 |
|
| 4060 |
def cb(result): |
| 4061 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4062 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4063 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4064 |
self.assertEquals("retrieve-affiliations", result.appCondition["feature"]) |
| 4065 |
|
| 4066 |
d = self.resource.affiliations(pubsub.PubSubRequest()) |
| 4067 |
self.assertFailure(d, error.StanzaError) |
| 4068 |
d.addCallback(cb) |
| 4069 |
return d |
| 4070 |
|
| 4071 |
def test_create(self): |
| 4072 |
""" |
| 4073 |
Non-overridden create yields unsupported error. |
| 4074 |
""" |
| 4075 |
|
| 4076 |
def cb(result): |
| 4077 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4078 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4079 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4080 |
self.assertEquals("create-nodes", result.appCondition["feature"]) |
| 4081 |
|
| 4082 |
d = self.resource.create(pubsub.PubSubRequest()) |
| 4083 |
self.assertFailure(d, error.StanzaError) |
| 4084 |
d.addCallback(cb) |
| 4085 |
return d |
| 4086 |
|
| 4087 |
def test_default(self): |
| 4088 |
""" |
| 4089 |
Non-overridden default yields unsupported error. |
| 4090 |
""" |
| 4091 |
|
| 4092 |
def cb(result): |
| 4093 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4094 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4095 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4096 |
self.assertEquals("retrieve-default", result.appCondition["feature"]) |
| 4097 |
|
| 4098 |
d = self.resource.default(pubsub.PubSubRequest()) |
| 4099 |
self.assertFailure(d, error.StanzaError) |
| 4100 |
d.addCallback(cb) |
| 4101 |
return d |
| 4102 |
|
| 4103 |
def test_configureGet(self): |
| 4104 |
""" |
| 4105 |
Non-overridden configureGet yields unsupported |
| 4106 |
error. |
| 4107 |
""" |
| 4108 |
|
| 4109 |
def cb(result): |
| 4110 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4111 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4112 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4113 |
self.assertEquals("config-node", result.appCondition["feature"]) |
| 4114 |
|
| 4115 |
d = self.resource.configureGet(pubsub.PubSubRequest()) |
| 4116 |
self.assertFailure(d, error.StanzaError) |
| 4117 |
d.addCallback(cb) |
| 4118 |
return d |
| 4119 |
|
| 4120 |
def test_configureSet(self): |
| 4121 |
""" |
| 4122 |
Non-overridden configureSet yields unsupported error. |
| 4123 |
""" |
| 4124 |
|
| 4125 |
def cb(result): |
| 4126 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4127 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4128 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4129 |
self.assertEquals("config-node", result.appCondition["feature"]) |
| 4130 |
|
| 4131 |
d = self.resource.configureSet(pubsub.PubSubRequest()) |
| 4132 |
self.assertFailure(d, error.StanzaError) |
| 4133 |
d.addCallback(cb) |
| 4134 |
return d |
| 4135 |
|
| 4136 |
def test_items(self): |
| 4137 |
""" |
| 4138 |
Non-overridden items yields unsupported error. |
| 4139 |
""" |
| 4140 |
|
| 4141 |
def cb(result): |
| 4142 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4143 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4144 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4145 |
self.assertEquals("retrieve-items", result.appCondition["feature"]) |
| 4146 |
|
| 4147 |
d = self.resource.items(pubsub.PubSubRequest()) |
| 4148 |
self.assertFailure(d, error.StanzaError) |
| 4149 |
d.addCallback(cb) |
| 4150 |
return d |
| 4151 |
|
| 4152 |
def test_retract(self): |
| 4153 |
""" |
| 4154 |
Non-overridden retract yields unsupported error. |
| 4155 |
""" |
| 4156 |
|
| 4157 |
def cb(result): |
| 4158 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4159 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4160 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4161 |
self.assertEquals("retract-items", result.appCondition["feature"]) |
| 4162 |
|
| 4163 |
d = self.resource.retract(pubsub.PubSubRequest()) |
| 4164 |
self.assertFailure(d, error.StanzaError) |
| 4165 |
d.addCallback(cb) |
| 4166 |
return d |
| 4167 |
|
| 4168 |
def test_purge(self): |
| 4169 |
""" |
| 4170 |
Non-overridden purge yields unsupported error. |
| 4171 |
""" |
| 4172 |
|
| 4173 |
def cb(result): |
| 4174 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4175 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4176 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4177 |
self.assertEquals("purge-nodes", result.appCondition["feature"]) |
| 4178 |
|
| 4179 |
d = self.resource.purge(pubsub.PubSubRequest()) |
| 4180 |
self.assertFailure(d, error.StanzaError) |
| 4181 |
d.addCallback(cb) |
| 4182 |
return d |
| 4183 |
|
| 4184 |
def test_delete(self): |
| 4185 |
""" |
| 4186 |
Non-overridden delete yields unsupported error. |
| 4187 |
""" |
| 4188 |
|
| 4189 |
def cb(result): |
| 4190 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4191 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4192 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4193 |
self.assertEquals("delete-nodes", result.appCondition["feature"]) |
| 4194 |
|
| 4195 |
d = self.resource.delete(pubsub.PubSubRequest()) |
| 4196 |
self.assertFailure(d, error.StanzaError) |
| 4197 |
d.addCallback(cb) |
| 4198 |
return d |
| 4199 |
|
| 4200 |
def test_affiliationsGet(self): |
| 4201 |
""" |
| 4202 |
Non-overridden owner affiliations get yields unsupported error. |
| 4203 |
""" |
| 4204 |
|
| 4205 |
def cb(result): |
| 4206 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4207 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4208 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4209 |
self.assertEquals("modify-affiliations", result.appCondition["feature"]) |
| 4210 |
|
| 4211 |
d = self.resource.affiliationsGet(pubsub.PubSubRequest()) |
| 4212 |
self.assertFailure(d, error.StanzaError) |
| 4213 |
d.addCallback(cb) |
| 4214 |
return d |
| 4215 |
|
| 4216 |
def test_affiliationsSet(self): |
| 4217 |
""" |
| 4218 |
Non-overridden owner affiliations set yields unsupported error. |
| 4219 |
""" |
| 4220 |
|
| 4221 |
def cb(result): |
| 4222 |
self.assertEquals("feature-not-implemented", result.condition) |
| 4223 |
self.assertEquals("unsupported", result.appCondition.name) |
| 4224 |
self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri) |
| 4225 |
self.assertEquals("modify-affiliations", result.appCondition["feature"]) |
| 4226 |
|
| 4227 |
d = self.resource.affiliationsSet(pubsub.PubSubRequest()) |
| 4228 |
self.assertFailure(d, error.StanzaError) |
| 4229 |
d.addCallback(cb) |
| 4230 |
return d |