[54] | 1 | # HG changeset patch |
---|
| 2 | # Parent 7de2ae0a6a884cf594ba232ee5d909c6d10e1906 |
---|
| 3 | Address incompatible change concerning PubSubRequest.options. |
---|
| 4 | |
---|
| 5 | In changeset [1334124db2fd], `PubSubRequest.options` was changed to hold the |
---|
| 6 | `wokkel.data_form.Form` that represents the data form sent in the original |
---|
| 7 | request. This makes it easier to type check the form in a step separate from |
---|
| 8 | parsing the request. However, this is an incompatible change. |
---|
| 9 | |
---|
| 10 | To remedy this, we move the form to `optionsForm` and make options a property |
---|
| 11 | that returns the values of the form. |
---|
| 12 | |
---|
| 13 | diff -r 7de2ae0a6a88 wokkel/pubsub.py |
---|
| 14 | --- a/wokkel/pubsub.py Wed Aug 03 20:44:36 2011 +0200 |
---|
| 15 | +++ b/wokkel/pubsub.py Wed Nov 02 09:32:12 2011 +0100 |
---|
| 16 | @@ -210,9 +210,13 @@ |
---|
| 17 | @ivar nodeType: The type of node that should be created, or for which the |
---|
| 18 | configuration is retrieved. C{'leaf'} or C{'collection'}. |
---|
| 19 | @type nodeType: C{str} |
---|
| 20 | - @ivar options: Configurations options for nodes, subscriptions and publish |
---|
| 21 | - requests. |
---|
| 22 | - @type options: L{data_form.Form} |
---|
| 23 | + @ivar optionsForm: Configurations options for nodes, subscriptions and |
---|
| 24 | + publish requests. |
---|
| 25 | + @type optionsForm: L{data_form.Form} |
---|
| 26 | + @ivar options: Read-only property reflecting the values of the data form in |
---|
| 27 | + C{optionsForm}. When C{optionsForm} is set, this is equal to |
---|
| 28 | + the result of C{optionsForm.getValues()}. |
---|
| 29 | + @type options: C{dict} |
---|
| 30 | @ivar subscriber: The subscribing entity. |
---|
| 31 | @type subscriber: L{JID} |
---|
| 32 | @ivar subscriptionIdentifier: Identifier for a specific subscription. |
---|
| 33 | @@ -233,7 +237,7 @@ |
---|
| 34 | maxItems = None |
---|
| 35 | nodeIdentifier = None |
---|
| 36 | nodeType = None |
---|
| 37 | - options = None |
---|
| 38 | + optionsForm = None |
---|
| 39 | subscriber = None |
---|
| 40 | subscriptionIdentifier = None |
---|
| 41 | subscriptions = None |
---|
| 42 | @@ -292,6 +296,15 @@ |
---|
| 43 | self.verb = verb |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | + def _getOptions(self): |
---|
| 47 | + if (self.optionsForm is not None and |
---|
| 48 | + self.optionsForm.formType != 'cancel'): |
---|
| 49 | + return self.optionsForm.getValues() |
---|
| 50 | + else: |
---|
| 51 | + return None |
---|
| 52 | + |
---|
| 53 | + options = property(_getOptions) |
---|
| 54 | + |
---|
| 55 | def _parse_node(self, verbElement): |
---|
| 56 | """ |
---|
| 57 | Parse the required node identifier out of the verbElement. |
---|
| 58 | @@ -398,7 +411,7 @@ |
---|
| 59 | form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG) |
---|
| 60 | if form: |
---|
| 61 | if form.formType in ('submit', 'cancel'): |
---|
| 62 | - self.options = form |
---|
| 63 | + self.optionsForm = form |
---|
| 64 | else: |
---|
| 65 | raise BadRequest(text=u"Unexpected form type '%s'" % form.formType) |
---|
| 66 | else: |
---|
| 67 | @@ -419,16 +432,16 @@ |
---|
| 68 | else: |
---|
| 69 | form = data_form.Form('submit', |
---|
| 70 | formNamespace=NS_PUBSUB_NODE_CONFIG) |
---|
| 71 | - self.options = form |
---|
| 72 | + self.optionsForm = form |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | def _render_configureOrNone(self, verbElement): |
---|
| 76 | """ |
---|
| 77 | Render optional node configuration form in create request. |
---|
| 78 | """ |
---|
| 79 | - if self.options is not None: |
---|
| 80 | + if self.optionsForm is not None: |
---|
| 81 | configure = verbElement.parent.addElement('configure') |
---|
| 82 | - configure.addChild(self.options.toElement()) |
---|
| 83 | + configure.addChild(self.optionsForm.toElement()) |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | def _parse_itemIdentifiers(self, verbElement): |
---|
| 87 | @@ -498,7 +511,7 @@ |
---|
| 88 | form = data_form.findForm(verbElement, NS_PUBSUB_SUBSCRIBE_OPTIONS) |
---|
| 89 | if form: |
---|
| 90 | if form.formType in ('submit', 'cancel'): |
---|
| 91 | - self.options = form |
---|
| 92 | + self.optionsForm = form |
---|
| 93 | else: |
---|
| 94 | raise BadRequest(text=u"Unexpected form type '%s'" % form.formType) |
---|
| 95 | else: |
---|
| 96 | @@ -507,7 +520,7 @@ |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | def _render_options(self, verbElement): |
---|
| 100 | - verbElement.addChild(self.options.toElement()) |
---|
| 101 | + verbElement.addChild(self.optionsForm.toElement()) |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | def _parse_optionsWithSubscribe(self, verbElement): |
---|
| 105 | @@ -522,11 +535,11 @@ |
---|
| 106 | else: |
---|
| 107 | form = data_form.Form('submit', |
---|
| 108 | formNamespace=NS_PUBSUB_SUBSCRIBE_OPTIONS) |
---|
| 109 | - self.options = form |
---|
| 110 | + self.optionsForm = form |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | def _render_optionsWithSubscribe(self, verbElement): |
---|
| 114 | - if self.options: |
---|
| 115 | + if self.optionsForm is not None: |
---|
| 116 | optionsElement = verbElement.parent.addElement('options') |
---|
| 117 | self._render_options(optionsElement) |
---|
| 118 | |
---|
| 119 | @@ -772,7 +785,7 @@ |
---|
| 120 | form = data_form.Form(formType='submit', |
---|
| 121 | formNamespace=NS_PUBSUB_NODE_CONFIG) |
---|
| 122 | form.makeFields(options) |
---|
| 123 | - request.options = form |
---|
| 124 | + request.optionsForm = form |
---|
| 125 | |
---|
| 126 | def cb(iq): |
---|
| 127 | try: |
---|
| 128 | @@ -835,7 +848,7 @@ |
---|
| 129 | form = data_form.Form(formType='submit', |
---|
| 130 | formNamespace=NS_PUBSUB_SUBSCRIBE_OPTIONS) |
---|
| 131 | form.makeFields(options) |
---|
| 132 | - request.options = form |
---|
| 133 | + request.optionsForm = form |
---|
| 134 | |
---|
| 135 | def cb(iq): |
---|
| 136 | subscription = Subscription.fromElement(iq.pubsub.subscription) |
---|
| 137 | @@ -1006,7 +1019,7 @@ |
---|
| 138 | form = data_form.Form(formType='submit', |
---|
| 139 | formNamespace=NS_PUBSUB_SUBSCRIBE_OPTIONS) |
---|
| 140 | form.makeFields(options) |
---|
| 141 | - request.options = form |
---|
| 142 | + request.optionsForm = form |
---|
| 143 | |
---|
| 144 | d = request.send(self.xmlstream) |
---|
| 145 | return d |
---|
| 146 | @@ -1194,11 +1207,7 @@ |
---|
| 147 | return defer.fail(Unsupported('', text)) |
---|
| 148 | |
---|
| 149 | handler = getattr(self, handlerName) |
---|
| 150 | - |
---|
| 151 | args = [getattr(request, arg) for arg in argNames] |
---|
| 152 | - if 'options' in argNames: |
---|
| 153 | - args[argNames.index('options')] = request.options.getValues() |
---|
| 154 | - |
---|
| 155 | d = handler(*args) |
---|
| 156 | |
---|
| 157 | # If needed, translate the result into a response |
---|
| 158 | @@ -1262,8 +1271,8 @@ |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | def _preProcess_create(self, resource, request): |
---|
| 162 | - if request.options: |
---|
| 163 | - self._checkConfiguration(resource, request.options) |
---|
| 164 | + if request.optionsForm: |
---|
| 165 | + self._checkConfiguration(resource, request.optionsForm) |
---|
| 166 | return request |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | @@ -1295,10 +1304,10 @@ |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | def _preProcess_configureSet(self, resource, request): |
---|
| 173 | - if request.options.formType == 'cancel': |
---|
| 174 | + if request.optionsForm.formType == 'cancel': |
---|
| 175 | return None |
---|
| 176 | else: |
---|
| 177 | - self._checkConfiguration(resource, request.options) |
---|
| 178 | + self._checkConfiguration(resource, request.optionsForm) |
---|
| 179 | return request |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | diff -r 7de2ae0a6a88 wokkel/test/test_pubsub.py |
---|
| 183 | --- a/wokkel/test/test_pubsub.py Wed Aug 03 20:44:36 2011 +0200 |
---|
| 184 | +++ b/wokkel/test/test_pubsub.py Wed Nov 02 09:32:12 2011 +0100 |
---|
| 185 | @@ -1186,8 +1186,8 @@ |
---|
| 186 | |
---|
| 187 | request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
---|
| 188 | self.assertEqual('subscribe', request.verb) |
---|
| 189 | - request.options.typeCheck({'pubsub#deliver': {'type': 'boolean'}}) |
---|
| 190 | - self.assertEqual({'pubsub#deliver': True}, request.options.getValues()) |
---|
| 191 | + request.optionsForm.typeCheck({'pubsub#deliver': {'type': 'boolean'}}) |
---|
| 192 | + self.assertEqual({'pubsub#deliver': True}, request.options) |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | def test_fromElementSubscribeWithOptionsBadFormType(self): |
---|
| 196 | @@ -1240,7 +1240,7 @@ |
---|
| 197 | |
---|
| 198 | request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
---|
| 199 | self.assertEqual('subscribe', request.verb) |
---|
| 200 | - self.assertEqual({}, request.options.getValues()) |
---|
| 201 | + self.assertEqual({}, request.options) |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | def test_fromElementUnsubscribe(self): |
---|
| 205 | @@ -1372,7 +1372,7 @@ |
---|
| 206 | self.assertEqual(JID('pubsub.example.org'), request.recipient) |
---|
| 207 | self.assertEqual('test', request.nodeIdentifier) |
---|
| 208 | self.assertEqual(JID('user@example.org/Home'), request.subscriber) |
---|
| 209 | - self.assertEqual({'pubsub#deliver': '1'}, request.options.getValues()) |
---|
| 210 | + self.assertEqual({'pubsub#deliver': '1'}, request.options) |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | def test_fromElementOptionsSetWithSubscriptionIdentifier(self): |
---|
| 214 | @@ -1418,7 +1418,8 @@ |
---|
| 215 | """ |
---|
| 216 | |
---|
| 217 | request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
---|
| 218 | - self.assertEqual('cancel', request.options.formType) |
---|
| 219 | + self.assertEqual('cancel', request.optionsForm.formType) |
---|
| 220 | + self.assertIdentical(None, request.options) |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | def test_fromElementOptionsSetBadFormType(self): |
---|
| 224 | @@ -1529,6 +1530,7 @@ |
---|
| 225 | self.assertEqual(JID('user@example.org'), request.sender) |
---|
| 226 | self.assertEqual(JID('pubsub.example.org'), request.recipient) |
---|
| 227 | self.assertEqual('mynode', request.nodeIdentifier) |
---|
| 228 | + self.assertIdentical(None, request.optionsForm) |
---|
| 229 | self.assertIdentical(None, request.options) |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | @@ -1566,7 +1568,7 @@ |
---|
| 233 | """ |
---|
| 234 | |
---|
| 235 | request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
---|
| 236 | - self.assertEqual({}, request.options.getValues()) |
---|
| 237 | + self.assertEqual({}, request.options) |
---|
| 238 | self.assertEqual(u'mynode', request.nodeIdentifier) |
---|
| 239 | |
---|
| 240 | |
---|
| 241 | @@ -1589,7 +1591,7 @@ |
---|
| 242 | """ |
---|
| 243 | |
---|
| 244 | request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
---|
| 245 | - self.assertEqual({}, request.options.getValues()) |
---|
| 246 | + self.assertEqual({}, request.options) |
---|
| 247 | self.assertEqual(u'mynode', request.nodeIdentifier) |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | @@ -1617,7 +1619,7 @@ |
---|
| 251 | """ |
---|
| 252 | |
---|
| 253 | request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
---|
| 254 | - values = request.options.getValues() |
---|
| 255 | + values = request.options |
---|
| 256 | self.assertIn('pubsub#access_model', values) |
---|
| 257 | self.assertEqual(u'open', values['pubsub#access_model']) |
---|
| 258 | self.assertIn('pubsub#persist_items', values) |
---|
| 259 | @@ -1757,7 +1759,7 @@ |
---|
| 260 | self.assertEqual('test', request.nodeIdentifier) |
---|
| 261 | self.assertEqual({'pubsub#deliver_payloads': '0', |
---|
| 262 | 'pubsub#persist_items': '1'}, |
---|
| 263 | - request.options.getValues()) |
---|
| 264 | + request.options) |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | def test_fromElementConfigureSetCancel(self): |
---|
| 268 | @@ -1777,7 +1779,8 @@ |
---|
| 269 | """ |
---|
| 270 | |
---|
| 271 | request = pubsub.PubSubRequest.fromElement(parseXml(xml)) |
---|
| 272 | - self.assertEqual('cancel', request.options.formType) |
---|
| 273 | + self.assertEqual('cancel', request.optionsForm.formType) |
---|
| 274 | + self.assertIdentical(None, request.options) |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | def test_fromElementConfigureSetBadFormType(self): |
---|
| 278 | @@ -2633,7 +2636,7 @@ |
---|
| 279 | def create(request): |
---|
| 280 | self.assertEqual({'pubsub#deliver_payloads': False, |
---|
| 281 | 'pubsub#persist_items': True}, |
---|
| 282 | - request.options.getValues()) |
---|
| 283 | + request.options) |
---|
| 284 | return defer.succeed(None) |
---|
| 285 | |
---|
| 286 | self.resource.getConfigurationOptions = getConfigurationOptions |
---|
| 287 | @@ -2841,7 +2844,7 @@ |
---|
| 288 | def configureSet(request): |
---|
| 289 | self.assertEqual({'pubsub#deliver_payloads': False, |
---|
| 290 | 'pubsub#persist_items': True}, |
---|
| 291 | - request.options.getValues()) |
---|
| 292 | + request.options) |
---|
| 293 | return defer.succeed(None) |
---|
| 294 | |
---|
| 295 | self.resource.getConfigurationOptions = getConfigurationOptions |
---|
| 296 | @@ -2913,7 +2916,7 @@ |
---|
| 297 | |
---|
| 298 | def configureSet(request): |
---|
| 299 | self.assertEquals(['pubsub#deliver_payloads'], |
---|
| 300 | - request.options.fields.keys()) |
---|
| 301 | + request.options.keys()) |
---|
| 302 | |
---|
| 303 | self.resource.getConfigurationOptions = getConfigurationOptions |
---|
| 304 | self.resource.configureSet = configureSet |
---|