0001-wscall-store-more-informations-after-the-call-9889.patch
tests/test_workflows.py | ||
---|---|---|
494 | 494 |
item.post = False |
495 | 495 |
item.varname = 'xxx' |
496 | 496 |
item.perform(formdata) |
497 |
assert formdata.workflow_data.get('xxx_status') == 200 |
|
498 |
assert formdata.workflow_data.get('xxx_response') == {'foo': 'bar'} |
|
497 |
assert formdata.workflow_data['xxx_status'] == 200 |
|
498 |
assert formdata.workflow_data['xxx_response'] == {'foo': 'bar'} |
|
499 |
assert isinstance(formdata.workflow_data['xxx_time'], time.struct_time) |
|
500 |
formdata.workflow_data = None |
|
499 | 501 | |
500 | 502 |
item = WebserviceCallStatusItem() |
501 | 503 |
item.url = 'http://remote.example.net' |
... | ... | |
522 | 524 |
item = WebserviceCallStatusItem() |
523 | 525 |
item.url = 'http://remote.example.net/404' |
524 | 526 |
item.post = False |
527 |
item.varname = 'xxx' |
|
528 |
with pytest.raises(AbortActionException): |
|
529 |
item.perform(formdata) |
|
530 |
assert formdata.workflow_data.get('xxx_status') == 404 |
|
531 |
assert isinstance(formdata.workflow_data['xxx_time'], time.struct_time) |
|
532 |
assert 'xxx_error_response' not in formdata.workflow_data |
|
533 |
formdata.workflow_data = None |
|
534 | ||
535 |
item = WebserviceCallStatusItem() |
|
536 |
item.url = 'http://remote.example.net/404-json' |
|
537 |
item.post = False |
|
538 |
item.varname = 'xxx' |
|
525 | 539 |
with pytest.raises(AbortActionException): |
526 | 540 |
item.perform(formdata) |
541 |
assert formdata.workflow_data.get('xxx_status') == 404 |
|
542 |
assert formdata.workflow_data.get('xxx_error_response') == {'err': 1} |
|
543 |
assert isinstance(formdata.workflow_data['xxx_time'], time.struct_time) |
|
544 |
assert 'xxx_response' not in formdata.workflow_data |
|
545 |
formdata.workflow_data = None |
|
527 | 546 | |
528 | 547 |
item = WebserviceCallStatusItem() |
529 | 548 |
item.url = 'http://remote.example.net/404' |
... | ... | |
563 | 582 |
item.action_on_bad_data = ':stop' |
564 | 583 |
with pytest.raises(AbortActionException): |
565 | 584 |
item.perform(formdata) |
585 |
assert formdata.workflow_data.get('xxx_status') == 200 |
|
586 |
assert 'xxx_response' not in formdata.workflow_data |
|
587 |
assert 'xxx_error_response' not in formdata.workflow_data |
|
588 |
formdata.workflow_data = None |
|
566 | 589 | |
567 | 590 |
item = WebserviceCallStatusItem() |
568 | 591 |
item.url = 'http://remote.example.net/404' |
... | ... | |
582 | 605 |
with pytest.raises(AbortActionException): |
583 | 606 |
item.perform(formdata) |
584 | 607 |
assert formdata.evolution[-1].parts[-1].summary == 'ValueError: No JSON object could be decoded\n' |
608 |
assert formdata.workflow_data.get('xxx_status') == 200 |
|
609 |
assert isinstance(formdata.workflow_data['xxx_time'], time.struct_time) |
|
610 |
assert 'xxx_error_response' not in formdata.workflow_data |
|
611 |
formdata.workflow_data = None |
|
585 | 612 | |
586 | 613 | |
587 | 614 |
def test_timeout(pub): |
tests/utilities.py | ||
---|---|---|
217 | 217 | |
218 | 218 |
status, data = { |
219 | 219 |
'http://remote.example.net/404': (404, 'page not found'), |
220 |
'http://remote.example.net/404-json': (404, '{"err": 1}'), |
|
220 | 221 |
'http://remote.example.net/500': (500, 'internal server error'), |
221 | 222 |
'http://remote.example.net/json': (200, '{"foo": "bar"}'), |
222 | 223 |
'http://remote.example.net/xml': (200, '<?xml version="1.0"><foo/>'), |
wcs/wf/wscall.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import time |
|
17 | 18 |
import json |
18 | 19 |
import sys |
19 | 20 |
import traceback |
... | ... | |
177 | 178 |
exc_info=sys.exc_info()) |
178 | 179 | |
179 | 180 |
if self.varname: |
180 |
workflow_data = {'%s_status' % self.varname: status} |
|
181 |
if status == 200: |
|
181 |
workflow_data = { |
|
182 |
'%s_status' % self.varname: status, |
|
183 |
'%s_time' % self.varname: time.localtime() |
|
184 |
} |
|
185 |
if (status // 100) == 2: |
|
182 | 186 |
try: |
183 | 187 |
d = json_loads(data) |
184 | 188 |
except (ValueError, TypeError) as e: |
189 |
formdata.update_workflow_data(workflow_data) |
|
190 |
formdata.store() |
|
185 | 191 |
self.action_on_error(self.action_on_bad_data, formdata, |
186 | 192 |
response, data=data, exc_info=sys.exc_info()) |
187 | 193 |
else: |
... | ... | |
190 | 196 |
formdata.id_display = d.get('data', {}).get('display_id') |
191 | 197 |
elif d.get('display_id'): |
192 | 198 |
formdata.id_display = d.get('display_id') |
199 |
else: # on error, if data is JSON, record it |
|
200 |
try: |
|
201 |
open('/tmp/data','w').write('%s' % data) |
|
202 |
d = json_loads(data) |
|
203 |
except (ValueError, TypeError) as e: |
|
204 |
pass |
|
205 |
else: |
|
206 |
workflow_data['%s_error_response' % self.varname] = d |
|
193 | 207 |
formdata.update_workflow_data(workflow_data) |
194 | 208 |
formdata.store() |
195 | 209 | |
196 |
- |