Changeset 27:a9704141033a in ralphm-patches for pubsub-create-configure.patch
- Timestamp:
- Jan 2, 2010, 3:32:52 PM (11 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pubsub-create-configure.patch
r21 r27 1 diff -r d64e96596c50 -r 8425a88d49f5 wokkel/pubsub.py 2 --- a/wokkel/pubsub.py Wed Dec 30 21:41:55 2009 +0100 3 +++ b/wokkel/pubsub.py Wed Dec 30 21:42:27 2009 +0100 1 Add support for configuration options in node creation requests 2 3 diff -r 259252e5664b wokkel/pubsub.py 4 --- a/wokkel/pubsub.py Sat Jan 02 14:28:16 2010 +0100 5 +++ b/wokkel/pubsub.py Sat Jan 02 15:27:24 2010 +0100 4 6 @@ -234,7 +234,7 @@ 5 7 'optionsSet': ['nodeOrEmpty', 'jid', 'options'], … … 26 28 + self.options = form 27 29 + else: 28 + raise BadRequest(text= "Unexpected form type %r" %30 + raise BadRequest(text=u"Unexpected form type '%s'" % 29 31 + form.formType) 30 32 + else: … … 45 47 def _parse_itemIdentifiers(self, verbElement): 46 48 """ 47 @@ -60 2,7 +629,8 @@49 @@ -607,7 +634,8 @@ 48 50 pass 49 51 … … 55 57 Create a publish subscribe node. 56 58 57 @@ -61 0,12 +638,20 @@59 @@ -615,12 +643,20 @@ 58 60 @type service: L{JID} 59 61 @param nodeIdentifier: Optional suggestion for the id of the node. … … 68 70 69 71 + if options: 70 + form = data_form.Form(formType=' result',72 + form = data_form.Form(formType='submit', 71 73 + formNamespace=NS_PUBSUB_NODE_CONFIG) 72 74 + form.makeFields(options) … … 76 78 try: 77 79 new_node = iq.pubsub.create["node"] 78 @@ -887,8 +923,6 @@ 79 d = self.getNodes(requestor, target) 80 else: 81 d = defer.succeed([]) 82 - 83 - 84 85 d.addCallback(lambda nodes: [disco.DiscoItem(target, node) 86 for node in nodes]) 87 @@ -998,6 +1032,12 @@ 80 @@ -1001,6 +1037,12 @@ 88 81 form.typeCheck(fieldDefs, filterUnknown=True) 89 82 … … 98 91 if request.nodeType not in ('leaf', 'collection'): 99 92 raise error.StanzaError('not-acceptable') 100 diff -r d64e96596c50 -r 8425a88d49f5wokkel/test/test_pubsub.py101 --- a/wokkel/test/test_pubsub.py Wed Dec 30 21:41:55 2009+0100102 +++ b/wokkel/test/test_pubsub.py Wed Dec 30 21:42:27 2009+010093 diff -r 259252e5664b wokkel/test/test_pubsub.py 94 --- a/wokkel/test/test_pubsub.py Sat Jan 02 14:28:16 2010 +0100 95 +++ b/wokkel/test/test_pubsub.py Sat Jan 02 15:27:24 2010 +0100 103 96 @@ -19,7 +19,7 @@ 104 97 from wokkel.test.helpers import TestableRequestHandlerMixin, XmlStreamStub … … 110 103 NS_PUBSUB_EVENT = 'http://jabber.org/protocol/pubsub#event' 111 104 NS_PUBSUB_OWNER = 'http://jabber.org/protocol/pubsub#owner' 112 @@ -271,6 +271,4 0@@105 @@ -271,6 +271,41 @@ 113 106 return d 114 107 … … 141 134 + # check that it has a configuration form 142 135 + form = data_form.findForm(children[0], NS_PUBSUB_NODE_CONFIG) 143 + self.assertNotIdentical(None, form) 136 + self.assertEqual('submit', form.formType) 137 + 144 138 + 145 139 + response = toResponse(iq, 'result') … … 151 145 """ 152 146 Test sending delete request. 153 @@ -93 5,6 +969,7 @@147 @@ -936,6 +971,7 @@ 154 148 self.assertEqual(JID('user@example.org'), request.sender) 155 149 self.assertEqual(JID('pubsub.example.org'), request.recipient) … … 159 153 160 154 def test_fromElementCreateInstant(self): 161 @@ -95 5,6 +990,78@@155 @@ -956,6 +992,109 @@ 162 156 self.assertIdentical(None, request.nodeIdentifier) 163 157 … … 235 229 + 236 230 + 231 + def test_fromElementCreateConfigureBadFormType(self): 232 + """ 233 + The form of a node creation request should have the right type. 234 + """ 235 + 236 + xml = """ 237 + <iq type='set' to='pubsub.example.org' 238 + from='user@example.org'> 239 + <pubsub xmlns='http://jabber.org/protocol/pubsub'> 240 + <create node='mynode'/> 241 + <configure> 242 + <x xmlns='jabber:x:data' type='result'> 243 + <field var='FORM_TYPE' type='hidden'> 244 + <value>http://jabber.org/protocol/pubsub#node_config</value> 245 + </field> 246 + <field var='pubsub#access_model'><value>open</value></field> 247 + <field var='pubsub#persist_items'><value>0</value></field> 248 + </x> 249 + </configure> 250 + </pubsub> 251 + </iq> 252 + """ 253 + 254 + err = self.assertRaises(error.StanzaError, 255 + pubsub.PubSubRequest.fromElement, 256 + parseXml(xml)) 257 + self.assertEqual('bad-request', err.condition) 258 + self.assertEqual("Unexpected form type 'result'", err.text) 259 + self.assertEqual(None, err.appCondition) 260 + 261 + 237 262 def test_fromElementDefault(self): 238 263 """ 239 264 Test parsing a request for the default node configuration. 240 @@ -1741,6 +1848,52 @@ 265 @@ -1080,7 +1219,7 @@ 266 267 def test_fromElementConfigureSetBadFormType(self): 268 """ 269 - On a node configuration set request unknown fields should be ignored. 270 + The form of a node configuraton set request should have the right type. 271 """ 272 273 xml = """ 274 @@ -1743,6 +1882,52 @@ 241 275 return d 242 276 … … 291 325 """ 292 326 A default request should result in 293 @@ -177 4,7 +1927,7 @@327 @@ -1776,7 +1961,7 @@ 294 328 self.assertEqual(NS_PUBSUB_OWNER, element.uri) 295 329 self.assertEqual(NS_PUBSUB_OWNER, element.default.uri) … … 300 334 self.resource.getConfigurationOptions = getConfigurationOptions 301 335 self.resource.default = default 302 @@ -190 3,7 +2056,7 @@336 @@ -1905,7 +2090,7 @@ 303 337 self.assertEqual(NS_PUBSUB_OWNER, element.uri) 304 338 self.assertEqual(NS_PUBSUB_OWNER, element.configure.uri)
Note: See TracChangeset
for help on using the changeset viewer.