Projet

Général

Profil

0001-wscalls-don-t-crash-ezt-substitution-on-errors-in-we.patch

Frédéric Péters, 22 juillet 2016 11:42

Télécharger (3,42 ko)

Voir les différences:

Subject: [PATCH] wscalls: don't crash ezt substitution on errors in webservice
 call (#12701)

 tests/test_admin_pages.py | 26 ++++++++++++++++++++++++++
 tests/utilities.py        |  6 +++++-
 wcs/wscalls.py            |  6 ++++--
 3 files changed, 35 insertions(+), 3 deletions(-)
tests/test_admin_pages.py
1353 1353
    assert FormDef.get(formdef_id).url_name == 'form-test'
1354 1354
    assert FormDef.get(formdef_id).table_name == 'xxx'
1355 1355

  
1356
def test_form_comment_with_error_in_wscall(pub):
1357
    create_superuser(pub)
1358
    NamedWsCall.wipe()
1359

  
1360
    wscall = NamedWsCall(name='xxx')
1361
    wscall.description = 'description'
1362
    wscall.request = {
1363
            'url': 'http://remote.example.net/404',
1364
            'request_signature_key': 'xxx',
1365
            'qs_data': {'a': 'b'},
1366
            'method': 'POST',
1367
            'post_data': {'c': 'd'},
1368
    }
1369
    wscall.store()
1370

  
1371
    FormDef.wipe()
1372
    formdef = FormDef()
1373
    formdef.name = 'form title'
1374
    formdef.fields = [fields.CommentField(id='1',
1375
        label='x [webservice.xxx.foobar] x', type='comment')]
1376
    formdef.store()
1377

  
1378
    app = login(get_app(pub))
1379
    resp = app.get('/backoffice/forms/%s/' % formdef.id)
1380
    assert 'x [webservice.xxx.foobar] x' in resp.body
1381

  
1356 1382
def test_workflows(pub):
1357 1383
    app = login(get_app(pub))
1358 1384
    app.get('/backoffice/workflows/')
tests/utilities.py
8 8
import pytest
9 9
import shutil
10 10
import threading
11
import urlparse
11 12

  
12 13
from wcs import sql
13 14

  
......
230 231
                 'headers': headers,
231 232
                 'timeout': timeout})
232 233

  
234
        scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
235
        base_url = urlparse.urlunparse((scheme, netloc, path, '', '', ''))
236

  
233 237
        status, data, headers = {
234 238
            'http://remote.example.net/204': (204, None, None),
235 239
            'http://remote.example.net/400-json': (400, '{"err": 1, "err_desc": ":("}', None),
......
239 243
            'http://remote.example.net/json': (200, '{"foo": "bar"}', None),
240 244
            'http://remote.example.net/xml': (200, '<?xml version="1.0"><foo/>',
241 245
                                              {'content-type': 'text/xml'}),
242
            }.get(url, (200, '', {}))
246
            }.get(base_url, (200, '', {}))
243 247

  
244 248
        class FakeResponse(object):
245 249
            def __init__(self, status, data, headers):
wcs/wscalls.py
193 193
        (response, status, data) = call_webservice(**self.request)
194 194
        return json_loads(data)
195 195

  
196

  
197 196
class WsCallsSubstitutionProxy(object):
198 197
    def __getattr__(self, attr):
199
        return NamedWsCall.get(attr).call()
198
        try:
199
            return NamedWsCall.get(attr).call()
200
        except ValueError:
201
            raise AttributeError()
200 202

  
201 203

  
202 204
class WsCallRequestWidget(CompositeWidget):
203
-