Projet

Général

Profil

0001-backoffice-add-JSON-output-in-inspect-tool-71937.patch

Thomas Noël, 16 décembre 2022 11:33

Télécharger (3,84 ko)

Voir les différences:

Subject: [PATCH] backoffice: add JSON output in inspect tool (#71937)

 tests/backoffice_pages/test_form_inspect.py |  8 ++++++++
 wcs/backoffice/management.py                | 11 +++++++++++
 2 files changed, 19 insertions(+)
tests/backoffice_pages/test_form_inspect.py
296 296
    assert '<div class="test-tool-result-plain">form title</div>' in resp.text
297 297
    assert 'HTML Source' not in resp.text
298 298
    assert 'rendered as an object' not in resp.text
299
    assert 'rendered in JSON format' not in resp.text
299 300

  
300 301
    resp.form['template'] = '<p>{{ form_name }}</p>'
301 302
    resp = resp.form.submit()
......
303 304
    assert '<p>form title</p>' in resp.text
304 305
    assert 'HTML Source' in resp.text
305 306
    assert 'rendered as an object' not in resp.text
307
    assert 'rendered in JSON format' not in resp.text
306 308

  
307 309
    resp.form['template'] = '{{ form_var_file }}'
308 310
    resp = resp.form.submit()
......
310 312
    assert '<div class="test-tool-result-plain">hello.txt</div>' in resp.text
311 313
    assert 'rendered as an object' in resp.text
312 314
    assert '<div class="test-tool-result-plain">hello.txt (file)</div>' in resp.text
315
    assert 'rendered in JSON format' in resp.text
316
    assert '&quot;filename&quot;: &quot;hello.txt&quot;' in resp.text
317
    assert '&quot;content_type&quot;: &quot;text/plain&quot;' in resp.text
318
    assert '&quot;content&quot;: &quot;aGVsbG8gd29ybGQ=&quot;' in resp.text
313 319
    assert 'HTML Source' not in resp.text
314 320

  
315 321
    resp.form['template'] = '{{ form_var_file_raw.get_content }}'  # will give bytes
......
825 831
    assert 'rendered as an object' in resp.text
826 832
    assert resp.pyquery('.test-tool-lazylist-details li:first-child').text() == 'Number of items: 3'
827 833
    assert resp.pyquery('.test-tool-lazylist-details li:last-child').text() == 'First items: bar, baz, foo'
834
    assert 'rendered in JSON format' in resp.text
835
    assert 'TypeError: Object of type LazyList is not JSON serializable' in resp.text
828 836

  
829 837

  
830 838
def test_inspect_page_idp_role(pub):
wcs/backoffice/management.py
3580 3580
                                r += ', '.join([str(x) for x in complex_result[:5]])
3581 3581
                                r += htmltext('</li>')
3582 3582
                            r += htmltext('</ul>')
3583
                        r += htmltext('<h3>%s</h3>') % _('Also rendered in JSON format (webservice call):')
3584
                        try:
3585
                            json_dump = json.dumps(complex_result, cls=misc.JSONEncoder, indent=2)
3586
                            # limit JSON output: 500 lines x 500 columns
3587
                            json_result = ''
3588
                            for line in json_dump.split('\n')[:500]:
3589
                                json_result += ellipsize(line, 500) + '\n'
3590
                            json_result = htmltext('<pre>%s</pre>') % json_result
3591
                        except Exception as exception:
3592
                            json_result = self.get_inspect_error_message(exception)
3593
                        r += htmltext('<div class="test-tool-result-plain">%s</div>') % json_result
3583 3594
                    r += htmltext('</div>')
3584 3595
            elif test_mode == 'html_template':
3585 3596
                try:
3586
-