Projet

Général

Profil

0001-misc-correctly-attach-cards-to-logged-errors-36635.patch

Frédéric Péters, 28 janvier 2020 16:51

Télécharger (5,63 ko)

Voir les différences:

Subject: [PATCH] misc: correctly attach cards to logged errors (#36635)

 tests/test_backoffice_pages.py | 61 ++++++++++++++++++++++++++++++++++
 wcs/formdef.py                 |  1 +
 wcs/logged_errors.py           | 16 ++++++---
 3 files changed, 74 insertions(+), 4 deletions(-)
tests/test_backoffice_pages.py
5532 5532
    resp = app.get('/backoffice/data/bar/1/')
5533 5533
    with pytest.raises(IndexError):
5534 5534
        resp.click('card plop')
5535

  
5536

  
5537
def test_backoffice_cards_wscall_failure_display(http_requests, pub, studio):
5538
    LoggedError.wipe()
5539
    user = create_user(pub)
5540

  
5541
    Workflow.wipe()
5542
    workflow = Workflow(name='wscall')
5543
    workflow.roles = {
5544
        '_viewer': 'Viewer',
5545
        '_editor': 'Editor',
5546
    }
5547
    st1 = workflow.add_status('Recorded', 'recorded')
5548

  
5549
    wscall = WebserviceCallStatusItem()
5550
    wscall.id = '_wscall'
5551
    wscall.varname = 'xxx'
5552
    wscall.url = 'http://remote.example.net/xml'
5553
    wscall.action_on_bad_data = ':stop'
5554
    wscall.record_errors = True
5555
    st1.items.append(wscall)
5556
    wscall.parent = st1
5557

  
5558
    again = ChoiceWorkflowStatusItem()
5559
    again.id = '_again'
5560
    again.label = 'Again'
5561
    again.by = ['_editor']
5562
    again.status = st1.id
5563
    st1.items.append(again)
5564
    again.parent = st1
5565

  
5566
    workflow.store()
5567

  
5568
    CardDef.wipe()
5569
    carddef = CardDef()
5570
    carddef.name = 'foo'
5571
    carddef.fields = [
5572
        fields.StringField(id='1', label='Test', type='string', varname='foo'),
5573
    ]
5574
    carddef.backoffice_submission_roles = user.roles
5575
    carddef.workflow_id = workflow.id
5576
    carddef.workflow_roles = {'_editor': user.roles[0]}
5577
    carddef.digest_template = 'card {{form_var_foo}}'
5578
    carddef.store()
5579
    carddef.data_class().wipe()
5580

  
5581
    carddata = carddef.data_class()()
5582
    carddata.data = {'1': 'plop'}
5583
    carddata.just_created()
5584
    carddata.store()
5585

  
5586
    app = login(get_app(pub))
5587

  
5588
    resp = app.get('/backoffice/data/foo/%s/' % carddata.id)
5589
    assert 'Again' in resp.text
5590
    resp = resp.forms[0].submit('button_again')
5591
    resp = resp.follow()
5592
    assert 'Error during webservice call' in resp.text
5593

  
5594
    assert LoggedError.count() == 1
5595
    assert LoggedError.select()[0].get_formdata().data == {'1': 'plop'}
wcs/formdef.py
1251 1251
        d = {
1252 1252
            'form_name': self.name,
1253 1253
            'form_slug': self.url_name,
1254
            'form_class_name': self.__class__.__name__,  # reserved for logged errors
1254 1255
        }
1255 1256
        if not minimal:
1256 1257
            from wcs.variables import LazyFormDef
wcs/logged_errors.py
18 18

  
19 19
from .qommon.misc import simplify
20 20
from .qommon.xml_storage import XmlStorableObject
21
from wcs.carddef import CardDef
21 22
from wcs.formdef import FormDef
22 23
from wcs.workflows import Workflow
23 24

  
......
29 30
    _hashed_indexes = ['formdef_id', 'workflow_id']
30 31

  
31 32
    summary = None
33
    formdef_class = 'FormDef'
32 34
    formdata_id = None
33 35
    formdef_id = None
34 36
    workflow_id = None
......
50 52
            ('exception_class', 'str'), ('exception_message', 'str'),
51 53
            ('expression', 'str'), ('expression_type', 'str'),
52 54
            ('formdata_id', 'str'), ('formdef_id', 'str'), ('workflow_id', 'str'),
55
            ('formdef_class', 'str'),
53 56
            ('status_id', 'str'), ('status_item_id', 'str'),
54 57
            ('occurences_count', 'int'),
55 58
            ('first_occurence_timestamp', 'datetime'),
......
72 75

  
73 76
        if formdata:
74 77
            error.formdata_id = str(formdata.id)
75
            error.formdef_id = formdata.formdef.id
76
            error.workflow_id = formdata.formdef.workflow.id
77
        elif formdef:
78
            formdef = formdata.formdef
79
        if formdef:
78 80
            error.formdef_id = formdef.id
79 81
            error.workflow_id = formdef.workflow.id
82
            error.formdef_class = formdef.__class__.__name__
80 83

  
81 84
        if not error.formdef_id:
82 85
            # cannot attach error to formdef, don't record in journal, it will
......
118 121
            # cannot attach error to formdef, don't record in journal, it will
119 122
            # still be sent by email to administrators.
120 123
            return
121
        formdef = FormDef.get_by_urlname(formdef_urlname)
124
        klass = FormDef
125
        if context.get('form_class_name') == 'CardDef':
126
            klass = CardDef
127
        formdef = klass.get_by_urlname(formdef_urlname)
122 128
        formdata = formdef.data_class().get(formdata_id, ignore_errors=True)
123 129
        return cls.record(error_summary, plain_error_msg, formdata=formdata,
124 130
                   formdef=formdef, workflow=formdef.workflow)
......
138 144
        return tech_id[:200]
139 145

  
140 146
    def get_formdef(self):
147
        if self.formdef_class == 'CardDef':
148
            return CardDef.get(self.formdef_id, ignore_errors=True)
141 149
        return FormDef.get(self.formdef_id, ignore_errors=True)
142 150

  
143 151
    def get_workflow(self):
144
-