Ignore:
Timestamp:
Mar 7, 2011, 7:40:16 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Make sure item and subscription elements get the correct namespace.

This complements the changes in [f4aa0d507bc8] and [3fe44cf07366] for item and
subscription elements that are used in different namespaces. These changesets
set the namespace to None, which works nicely when the elements are
serialized. However, in situations where the DOM representation is passed
around (in-process communication) these elements are no longer matched by
namespace. This change makes sure the elements get the proper namespace just
before they are sent out.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_pubsub.py

    r96 r97  
    463463        child = children[0]
    464464        self.assertEquals('test', child['node'])
    465 
    466         items = []
    467         for element in child.elements():
    468             if element.name == 'item' and element.uri in (NS_PUBSUB, None):
    469                 items.append(element)
    470 
     465        items = list(domish.generateElementsQNamed(child.children,
     466                                                   'item', NS_PUBSUB))
    471467        self.assertEquals(1, len(items))
    472468        self.assertIdentical(item, items[0])
     
    22182214            self.assertEqual(NS_PUBSUB, element.uri)
    22192215            subscription = element.subscription
    2220             self.assertIn(subscription.uri, (None, NS_PUBSUB))
     2216            self.assertEqual(NS_PUBSUB, subscription.uri)
    22212217            self.assertEqual('test', subscription['node'])
    22222218            self.assertEqual('user@example.org/Home', subscription['jid'])
     
    24312427            subscription = children[0]
    24322428            self.assertEqual('subscription', subscription.name)
    2433             self.assertIn(subscription.uri, (None, NS_PUBSUB))
     2429            self.assertEqual(NS_PUBSUB, subscription.uri, NS_PUBSUB)
    24342430            self.assertEqual('user@example.org', subscription['jid'])
    24352431            self.assertEqual('test', subscription['node'])
     
    29812977            self.assertTrue(domish.IElement.providedBy(item))
    29822978            self.assertEqual('item', item.name)
    2983             self.assertIn(item.uri, (NS_PUBSUB, None))
     2979            self.assertEqual(NS_PUBSUB, item.uri)
    29842980            self.assertEqual('current', item['id'])
    29852981
     
    30613057        verify.verifyObject(iwokkel.IPubSubResource, self.resource)
    30623058        return self.handleRequest(xml)
     3059
     3060
     3061    def test_notifyPublish(self):
     3062        """
     3063        Publish notifications are sent to the subscribers.
     3064        """
     3065        subscriber = JID('user@example.org')
     3066        subscriptions = [pubsub.Subscription('test', subscriber, 'subscribed')]
     3067        items = [pubsub.Item('current')]
     3068        notifications = [(subscriber, subscriptions, items)]
     3069        self.service.notifyPublish(JID('pubsub.example.org'), 'test',
     3070                                   notifications)
     3071        message = self.stub.output[-1]
     3072
     3073        self.assertEquals('message', message.name)
     3074        self.assertIdentical(None, message.uri)
     3075        self.assertEquals('user@example.org', message['to'])
     3076        self.assertEquals('pubsub.example.org', message['from'])
     3077        self.assertTrue(message.event)
     3078        self.assertEquals(NS_PUBSUB_EVENT, message.event.uri)
     3079        self.assertTrue(message.event.items)
     3080        self.assertEquals(NS_PUBSUB_EVENT, message.event.items.uri)
     3081        self.assertTrue(message.event.items.hasAttribute('node'))
     3082        self.assertEquals('test', message.event.items['node'])
     3083        itemElements = list(domish.generateElementsQNamed(
     3084            message.event.items.children, 'item', NS_PUBSUB_EVENT))
     3085        self.assertEquals(1, len(itemElements))
     3086        self.assertEquals('current', itemElements[0].getAttribute('id'))
     3087
     3088
     3089    def test_notifyPublishCollection(self):
     3090        """
     3091        Publish notifications are sent to the subscribers of collections.
     3092
     3093        The node the item was published to is on the C{items} element, while
     3094        the subscribed-to node is in the C{'Collections'} SHIM header.
     3095        """
     3096        subscriber = JID('user@example.org')
     3097        subscriptions = [pubsub.Subscription('', subscriber, 'subscribed')]
     3098        items = [pubsub.Item('current')]
     3099        notifications = [(subscriber, subscriptions, items)]
     3100        self.service.notifyPublish(JID('pubsub.example.org'), 'test',
     3101                                   notifications)
     3102        message = self.stub.output[-1]
     3103
     3104        self.assertTrue(message.event.items.hasAttribute('node'))
     3105        self.assertEquals('test', message.event.items['node'])
     3106        headers = shim.extractHeaders(message)
     3107        self.assertIn('Collection', headers)
     3108        self.assertIn('', headers['Collection'])
    30633109
    30643110
Note: See TracChangeset for help on using the changeset viewer.