Changeset 95:2d57501b5c68


Ignore:
Timestamp:
Feb 18, 2011, 8:38:19 PM (10 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Clean up some tests around retrieving default node configuration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_pubsub.py

    r94 r95  
    16621662    def test_fromElementDefault(self):
    16631663        """
    1664         Test parsing a request for the default node configuration.
     1664        Parsing default node configuration request sets required attributes.
     1665
     1666        Besides C{verb}, C{sender} and C{recipient}, we expect C{nodeType}
     1667        to be set. If not passed it receives the default C{u'leaf'}.
    16651668        """
    16661669
     
    16751678
    16761679        request = pubsub.PubSubRequest.fromElement(parseXml(xml))
    1677         self.assertEqual('default', request.verb)
    1678         self.assertEqual(JID('user@example.org'), request.sender)
    1679         self.assertEqual(JID('pubsub.example.org'), request.recipient)
    1680         self.assertEqual('leaf', request.nodeType)
     1680        self.assertEquals(u'default', request.verb)
     1681        self.assertEquals(JID('user@example.org'), request.sender)
     1682        self.assertEquals(JID('pubsub.example.org'), request.recipient)
     1683        self.assertEquals(u'leaf', request.nodeType)
    16811684
    16821685
    16831686    def test_fromElementDefaultCollection(self):
    16841687        """
    1685         Parsing a request for the default configuration extracts the node type.
     1688        Parsing default request for collection sets nodeType to collection.
    16861689        """
    16871690
     
    17061709
    17071710        request = pubsub.PubSubRequest.fromElement(parseXml(xml))
    1708         self.assertEqual('collection', request.nodeType)
     1711        self.assertEquals('collection', request.nodeType)
    17091712
    17101713
     
    26462649    def test_on_default(self):
    26472650        """
    2648         A default request should result in
    2649         L{PubSubService.getDefaultConfiguration} being called.
     2651        A default request returns default options filtered by available fields.
    26502652        """
    26512653
     
    26582660        </iq>
    26592661        """
    2660 
    2661         def getConfigurationOptions():
    2662             return {
     2662        fieldDefs = {
    26632663                "pubsub#persist_items":
    26642664                    {"type": "boolean",
     
    26692669                }
    26702670
     2671        def getConfigurationOptions():
     2672            return fieldDefs
     2673
    26712674        def default(request):
    2672             return defer.succeed({})
     2675            return defer.succeed({'pubsub#persist_items': 'false',
     2676                                  'x-myfield': '1'})
    26732677
    26742678        def cb(element):
    2675             self.assertEqual('pubsub', element.name)
    2676             self.assertEqual(NS_PUBSUB_OWNER, element.uri)
    2677             self.assertEqual(NS_PUBSUB_OWNER, element.default.uri)
     2679            self.assertEquals('pubsub', element.name)
     2680            self.assertEquals(NS_PUBSUB_OWNER, element.uri)
     2681            self.assertEquals(NS_PUBSUB_OWNER, element.default.uri)
    26782682            form = data_form.Form.fromElement(element.default.x)
    2679             self.assertEqual(NS_PUBSUB_NODE_CONFIG, form.formNamespace)
     2683            self.assertEquals(NS_PUBSUB_NODE_CONFIG, form.formNamespace)
     2684            form.typeCheck(fieldDefs)
     2685            self.assertIn('pubsub#persist_items', form.fields)
     2686            self.assertFalse(form.fields['pubsub#persist_items'].value)
     2687            self.assertNotIn('x-myfield', form.fields)
    26802688
    26812689        self.resource.getConfigurationOptions = getConfigurationOptions
     
    26872695
    26882696
    2689     def test_on_defaultCollection(self):
    2690         """
    2691         Responses to default requests should depend on passed node type.
    2692         """
    2693 
    2694         xml = """
    2695         <iq type='get' to='pubsub.example.org'
    2696                        from='user@example.org'>
    2697           <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
    2698             <default>
    2699               <x xmlns='jabber:x:data' type='submit'>
    2700                 <field var='FORM_TYPE' type='hidden'>
    2701                   <value>http://jabber.org/protocol/pubsub#node_config</value>
    2702                 </field>
    2703                 <field var='pubsub#node_type'>
    2704                   <value>collection</value>
    2705                 </field>
    2706               </x>
    2707             </default>
    2708 
    2709           </pubsub>
    2710         </iq>
    2711         """
    2712 
    2713         def getConfigurationOptions():
    2714             return {
    2715                 "pubsub#deliver_payloads":
    2716                     {"type": "boolean",
    2717                      "label": "Deliver payloads with event notifications"}
    2718                 }
    2719 
    2720         def default(request):
    2721             return defer.succeed({})
    2722 
    2723         self.resource.getConfigurationOptions = getConfigurationOptions
    2724         self.resource.default = default
    2725         verify.verifyObject(iwokkel.IPubSubResource, self.resource)
    2726         return self.handleRequest(xml)
    2727 
    2728 
    27292697    def test_on_defaultUnknownNodeType(self):
    27302698        """
    2731         A default request should result in
    2732         L{PubSubResource.default} being called.
     2699        Unknown node types yield non-acceptable.
     2700
     2701        Both C{getConfigurationOptions} and C{default} must not be called.
    27332702        """
    27342703
     
    27522721        """
    27532722
     2723        def getConfigurationOptions():
     2724            self.fail("Unexpected call to getConfigurationOptions")
     2725
    27542726        def default(request):
    2755             self.fail("Unexpected call to getConfiguration")
     2727            self.fail("Unexpected call to default")
    27562728
    27572729        def cb(result):
    27582730            self.assertEquals('not-acceptable', result.condition)
    27592731
     2732        self.resource.getConfigurationOptions = getConfigurationOptions
    27602733        self.resource.default = default
    27612734        verify.verifyObject(iwokkel.IPubSubResource, self.resource)
Note: See TracChangeset for help on using the changeset viewer.