def _createNotification(self, eventType, service, nodeIdentifier, subscriber, subscriptions=None): headers = [] if subscriptions: for subscription in subscriptions: if nodeIdentifier != subscription.nodeIdentifier: headers.append(('Collection', subscription.nodeIdentifier)) message = domish.Element((None, "message")) message["from"] = service.full() message["to"] = subscriber.full() event = message.addElement((NS_PUBSUB_EVENT, "event")) element = event.addElement(eventType) element["node"] = nodeIdentifier if headers: message.addChild(shim.Headers(headers)) return message
def test_header(self): headers = shim.Headers([('Urgency', 'high')]) elements = list(headers.elements()) self.assertEquals(1, len(elements)) header = elements[0] self.assertEquals(NS_SHIM, header.uri) self.assertEquals('header', header.name) self.assertEquals('Urgency', header['name']) self.assertEquals('high', unicode(header))
def test_headerRepeated(self): """ Some headers can appear more than once with the same name. """ headers = shim.Headers([('Collection', 'node1'), ('Collection', 'node2')]) elements = list(headers.elements()) self.assertEquals(2, len(elements)) collections = set((unicode(element) for element in elements if element['name'] == 'Collection')) self.assertIn('node1', collections) self.assertIn('node2', collections)
def test_eventItemsCollection(self): """ Test receiving an items event resulting in a call to itemsReceived. """ message = domish.Element((None, 'message')) message['from'] = 'pubsub.example.org' message['to'] = '[email protected]/home' event = message.addElement((NS_PUBSUB_EVENT, 'event')) items = event.addElement('items') items['node'] = 'test' headers = shim.Headers([('Collection', 'collection')]) message.addChild(headers) def itemsReceived(event): self.assertEquals(JID('[email protected]/home'), event.recipient) self.assertEquals(JID('pubsub.example.org'), event.sender) self.assertEquals('test', event.nodeIdentifier) self.assertEquals({'Collection': ['collection']}, event.headers) d, self.protocol.itemsReceived = calledAsync(itemsReceived) self.stub.send(message) return d
def test_noHeaders(self): headers = shim.Headers([]) self.assertEquals(NS_SHIM, headers.uri) self.assertEquals('headers', headers.name) self.assertEquals([], headers.children)