Changeset 28:4692e23155a3 in ralphm-patches


Ignore:
Timestamp:
Jan 2, 2010, 10:50:14 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Add PubSubClient?.getOptions, allow form type checking without field defs.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pubsub-forms.patch

    r27 r28  
    33diff -r ba58db23e8b9 wokkel/data_form.py
    44--- a/wokkel/data_form.py       Fri Jan 01 15:54:26 2010 +0100
    5 +++ b/wokkel/data_form.py       Sat Jan 02 13:53:24 2010 +0100
     5+++ b/wokkel/data_form.py       Sat Jan 02 22:49:40 2010 +0100
    66@@ -76,6 +76,7 @@
    77             option['label'] = self.label
     
    155155         form['type'] = self.formType
    156156 
    157 @@ -516,3 +604,58 @@
     157@@ -516,3 +604,65 @@
    158158             values[name] = value
    159159 
     
    161161+
    162162+
    163 +    def typeCheck(self, fieldDefs, filterUnknown=False):
     163+    def typeCheck(self, fieldDefs=None, filterUnknown=False):
    164164+        """
    165165+        Check values of fields according to the field definition.
     
    176176+        that is not set.
    177177+
     178+        If C{fieldDefs} is None, an empty dictionary is assumed. This is
     179+        useful for coercing boolean and JID values on forms with type
     180+        C{'form'}.
     181+
    178182+        @param fieldDefs: Field definitions as a dictionary. See
    179183+            L{wokkel.iwokkel.IPubSubService.getConfigurationOptions}
     
    184188+        @type filterUnknown: C{bool}
    185189+        """
     190+
     191+        if fieldDefs is None:
     192+            fieldDefs = {}
    186193+
    187194+        filtered = []
     
    216223diff -r ba58db23e8b9 wokkel/pubsub.py
    217224--- a/wokkel/pubsub.py  Fri Jan 01 15:54:26 2010 +0100
    218 +++ b/wokkel/pubsub.py  Sat Jan 02 13:53:24 2010 +0100
     225+++ b/wokkel/pubsub.py  Sat Jan 02 22:49:40 2010 +0100
    219226@@ -1,6 +1,6 @@
    220227 # -*- test-case-name: wokkel.test.test_pubsub -*-
     
    260267diff -r ba58db23e8b9 wokkel/test/test_data_form.py
    261268--- a/wokkel/test/test_data_form.py     Fri Jan 01 15:54:26 2010 +0100
    262 +++ b/wokkel/test/test_data_form.py     Sat Jan 02 13:53:24 2010 +0100
     269+++ b/wokkel/test/test_data_form.py     Sat Jan 02 22:49:40 2010 +0100
    263270@@ -787,6 +787,128 @@
    264271         self.assertRaises(data_form.Error, form.addField, field2)
     
    390397         """
    391398         Each named field is represented in the values, keyed by name.
    392 @@ -834,3 +956,126 @@
     399@@ -834,3 +956,142 @@
    393400         form = data_form.Form('submit', fields=fields)
    394401         values = form.getValues()
     
    517524+        self.assertNotIn('pubsub#description', form.fields)
    518525+        self.assertEqual([], checked)
     526+
     527+
     528+    def test_typeCheckNoFieldDefs(self):
     529+        """
     530+        If there are no field defs, an empty dictionary is assumed.
     531+        """
     532+        checked = []
     533+        form = data_form.Form('submit')
     534+        form.addField(data_form.Field('list-single', var='pubsub#description',
     535+                                                     value='a node'))
     536+        field = form.fields['pubsub#description']
     537+        field.typeCheck = lambda : checked.append(None)
     538+        form.typeCheck()
     539+
     540+        self.assertIn('pubsub#description', form.fields)
     541+        self.assertEqual([None], checked)
  • pubsub-subscription-options.patch

    r27 r28  
    11Add support for subscription options in subscribe requests
    22
    3 diff -r 0555c117c086 wokkel/pubsub.py
    4 --- a/wokkel/pubsub.py  Sat Jan 02 14:44:23 2010 +0100
    5 +++ b/wokkel/pubsub.py  Sat Jan 02 15:25:34 2010 +0100
     3diff -r 803662712cbe wokkel/pubsub.py
     4--- a/wokkel/pubsub.py  Sat Jan 02 15:27:24 2010 +0100
     5+++ b/wokkel/pubsub.py  Sat Jan 02 22:43:45 2010 +0100
    66@@ -228,7 +228,7 @@
    77     # Map request verb to parameter handler names
     
    136136             subscription = iq.pubsub.subscription["subscription"]
    137137 
    138 @@ -790,6 +835,38 @@
     138@@ -789,6 +834,69 @@
     139         d.addCallback(cb)
    139140         return d
    140141 
    141  
     142+    def getOptions(self, service, nodeIdentifier, subscriber, sender=None):
     143+        """
     144+        Get subscription options.
     145+
     146+        @param service: The publish subscribe service that keeps the node.
     147+        @type service: L{JID}
     148+
     149+        @param nodeIdentifier: The identifier of the node.
     150+        @type nodeIdentifier: C{unicode}
     151+
     152+        @param subscriber: The entity subscribed to the node.
     153+        @type subscriber: L{JID}
     154+
     155+        @rtype: L{data_form.Form}
     156+        """
     157+        request = PubSubRequest('optionsGet')
     158+        request.recipient = service
     159+        request.nodeIdentifier = nodeIdentifier
     160+        request.subscriber = subscriber
     161+        request.sender = sender
     162+
     163+        def cb(iq):
     164+            form = data_form.findForm(iq.pubsub.options,
     165+                                      NS_PUBSUB_SUBSCRIBE_OPTIONS)
     166+            form.typeCheck({})
     167+            return form
     168+
     169+        d = request.send(self.xmlstream)
     170+        d.addCallback(cb)
     171+        return d
     172+
     173+
    142174+    def setOptions(self, service, nodeIdentifier, subscriber,
    143175+                         options, sender=None):
     
    171203+        return d
    172204+
    173 +
     205 
    174206 
    175207 class PubSubService(XMPPHandler, IQHandlerMixin):
    176      """
    177 diff -r 0555c117c086 wokkel/test/test_pubsub.py
    178 --- a/wokkel/test/test_pubsub.py        Sat Jan 02 14:44:23 2010 +0100
    179 +++ b/wokkel/test/test_pubsub.py        Sat Jan 02 15:25:34 2010 +0100
     208diff -r 803662712cbe wokkel/test/test_pubsub.py
     209--- a/wokkel/test/test_pubsub.py        Sat Jan 02 15:27:24 2010 +0100
     210+++ b/wokkel/test/test_pubsub.py        Sat Jan 02 22:43:45 2010 +0100
    180211@@ -24,6 +24,7 @@
    181212 NS_PUBSUB_EVENT = 'http://jabber.org/protocol/pubsub#event'
     
    186217 def calledAsync(fn):
    187218     """
    188 @@ -481,6 +482,39 @@
     219@@ -482,6 +483,39 @@
    189220         return d
    190221 
     
    226257         """
    227258         Test sending subscription request from a specific JID.
    228 @@ -624,9 +658,74 @@
     259@@ -625,9 +659,118 @@
    229260         return d
    230261 
    231262 
     263+    def test_getOptions(self):
     264+        def cb(form):
     265+            self.assertEqual('form', form.formType)
     266+            self.assertEqual(NS_PUBSUB_SUBSCRIBE_OPTIONS, form.formNamespace)
     267+            field = form.fields['pubsub#deliver']
     268+            self.assertEqual('boolean', field.fieldType)
     269+            self.assertIdentical(True, field.value)
     270+            self.assertEqual('Enable delivery?', field.label)
     271+
     272+        d = self.protocol.getOptions(JID('pubsub.example.org'), 'test',
     273+                                     JID('user@example.org'),
     274+                                     sender=JID('user@example.org'))
     275+        d.addCallback(cb)
     276+
     277+        iq = self.stub.output[-1]
     278+        self.assertEqual('pubsub.example.org', iq.getAttribute('to'))
     279+        self.assertEqual('get', iq.getAttribute('type'))
     280+        self.assertEqual('pubsub', iq.pubsub.name)
     281+        self.assertEqual(NS_PUBSUB, iq.pubsub.uri)
     282+        children = list(domish.generateElementsQNamed(iq.pubsub.children,
     283+                                                      'options', NS_PUBSUB))
     284+        self.assertEqual(1, len(children))
     285+        child = children[0]
     286+        self.assertEqual('test', child['node'])
     287+
     288+        self.assertEqual(0, len(child.children))
     289+
     290+        # Send response
     291+        form = data_form.Form('form', formNamespace=NS_PUBSUB_SUBSCRIBE_OPTIONS)
     292+        form.addField(data_form.Field('boolean', var='pubsub#deliver',
     293+                                                 label='Enable delivery?',
     294+                                                 value=True))
     295+        response = toResponse(iq, 'result')
     296+        response.addElement((NS_PUBSUB, 'pubsub'))
     297+        response.pubsub.addElement('options')
     298+        response.pubsub.options.addChild(form.toElement())
     299+        self.stub.send(response)
     300+
     301+        return d
     302+
     303+
    232304+    def test_setOptions(self):
     305+        """
     306+        setOptions should send out a options-set request.
     307+        """
    233308+        options = {'pubsub#deliver': False}
    234309+
     
    301376         """
    302377         Test parsing a publish request.
    303 @@ -752,6 +851,91 @@
     378@@ -753,6 +896,91 @@
    304379         self.assertEqual(NS_PUBSUB_ERRORS, err.appCondition.uri)
    305380         self.assertEqual('jid-required', err.appCondition.name)
Note: See TracChangeset for help on using the changeset viewer.