Projet

Général

Profil

0002-misc-convert-formula-datasource-into-jsonvalue-in-so.patch

Lauréline Guérin, 16 décembre 2022 18:35

Télécharger (42,8 ko)

Voir les différences:

Subject: [PATCH 2/4] misc: convert formula datasource into jsonvalue in some
 tests (#72096)

 tests/admin_pages/test_datasource.py        | 50 +++++++++++---
 tests/api/test_carddef.py                   |  8 +--
 tests/api/test_formdata.py                  | 21 +++---
 tests/api/test_formdef.py                   | 10 +--
 tests/backoffice_pages/test_all.py          |  5 +-
 tests/backoffice_pages/test_carddata.py     | 12 ++--
 tests/backoffice_pages/test_columns.py      |  5 +-
 tests/backoffice_pages/test_custom_view.py  |  5 +-
 tests/backoffice_pages/test_export.py       |  5 +-
 tests/backoffice_pages/test_filters.py      |  9 ++-
 tests/backoffice_pages/test_form_inspect.py |  5 +-
 tests/backoffice_pages/test_submission.py   |  5 +-
 tests/form_pages/test_all.py                | 72 ++++++++++++---------
 tests/test_content_snapshots.py             | 32 +++++++--
 tests/test_fields.py                        | 46 ++++++++++---
 tests/test_formdata.py                      | 41 ++++++------
 tests/test_snapshots.py                     |  5 +-
 tests/workflow/test_all.py                  |  4 +-
 tests/workflow/test_backoffice_field.py     | 41 +++++++++---
 tests/workflow/test_carddata.py             |  5 +-
 20 files changed, 270 insertions(+), 116 deletions(-)
tests/admin_pages/test_datasource.py
1 1
import io
2
import json
2 3
import os
3 4
import re
4 5
import xml.etree.ElementTree as ET
......
427 428
    data_source = NamedDataSource(name='foobar')
428 429
    app = login(get_app(pub))
429 430

  
431
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
432
    data_source.store()
433
    resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
434
    assert 'This data source is readonly.' not in resp
435
    assert 'href="edit"' in resp
436
    assert 'href="delete"' in resp
437
    assert 'href="duplicate"' in resp
438
    assert 'Type of source: JSON Expression' in resp.text
439
    assert 'JSON Expression' in resp.text
440
    assert 'Preview' not in resp.text
441

  
442
    data_source.data_source = {
443
        'type': 'jsonvalue',
444
        'value': json.dumps(
445
            [
446
                {'id': 'AAA', 'text': 'AAA'},
447
                {'id': 'BBB', 'text': 'BBB'},
448
            ]
449
        ),
450
    }
451
    data_source.store()
452
    resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
453
    assert 'Preview' in resp.text
454
    assert resp.text.count('AAA') == 4  # expression (id, text) + preview (id, text)
455

  
456
    # check python
430 457
    data_source.data_source = {'type': 'formula', 'value': '[]'}
431 458
    data_source.store()
432 459
    resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
......
516 543
    assert 'bar' in resp.text
517 544
    assert 'Additional keys are available: geometry_coordinates, geometry_type, properties_label' in resp.text
518 545

  
519
    data_source.data_source = {'type': 'formula', 'value': '[str(x) for x in range(100)]'}
546
    data_source.data_source = {
547
        'type': 'jsonvalue',
548
        'value': json.dumps([{'id': x, 'text': x} for x in range(100)]),
549
    }
520 550
    data_source.store()
521 551
    resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
522 552
    assert 'Preview' in resp.text
......
524 554
    assert '<li>...</li>' in resp.text
525 555

  
526 556
    data_source.data_source = {
527
        'type': 'formula',
528
        'value': repr(
557
        'type': 'jsonvalue',
558
        'value': json.dumps(
529 559
            [
530 560
                {'id': 'a', 'text': 'BBB', 'foo': 'bar1'},
531 561
                {'id': 'b', 'text': 'BBB', 'foo': 'bar2'},
......
803 833
    create_superuser(pub)
804 834
    NamedDataSource.wipe()
805 835
    data_source = NamedDataSource(name='foobar')
806
    data_source.data_source = {'type': 'formula', 'value': '[]'}
836
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
807 837
    data_source.store()
808 838
    data_source = NamedDataSource(name='foobar2')
809
    data_source.data_source = {'type': 'formula', 'value': '[]'}
839
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
810 840
    data_source.store()
811 841

  
812 842
    app = login(get_app(pub))
......
895 925

  
896 926
    NamedDataSource.wipe()
897 927
    data_source = NamedDataSource(name='foobar')
898
    data_source.data_source = {'type': 'formula', 'value': '[]'}
928
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
899 929
    data_source.store()
900 930

  
901 931
    app = login(get_app(pub))
......
915 945
    NamedDataSource.wipe()
916 946
    data_source = NamedDataSource(name='foobar')
917 947
    data_source.slug = 'baaaz'
918
    data_source.data_source = {'type': 'formula', 'value': '[]'}
948
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
919 949
    data_source.store()
920 950
    data_source_xml = ET.tostring(data_source.export_to_xml(include_id=True))
921 951

  
......
959 989
    create_superuser(pub)
960 990
    NamedDataSource.wipe()
961 991
    data_source = NamedDataSource(name='foobar')
962
    data_source.data_source = {'type': 'formula', 'value': '[]'}
992
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
963 993
    data_source.store()
964 994
    assert NamedDataSource.get(1).slug == 'foobar'
965 995

  
......
975 1005
    assert NamedDataSource.get(1).slug == 'foo_bar'
976 1006

  
977 1007
    data_source = NamedDataSource(name='barfoo')
978
    data_source.data_source = {'type': 'formula', 'value': '[]'}
1008
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
979 1009
    data_source.store()
980 1010

  
981 1011
    resp = app.get('/backoffice/settings/data-sources/1/')
......
994 1024
    create_superuser(pub)
995 1025
    NamedDataSource.wipe()
996 1026
    data_source = NamedDataSource(name='foobar')
997
    data_source.data_source = {'type': 'formula', 'value': '[]'}
1027
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
998 1028
    data_source.store()
999 1029
    assert NamedDataSource.get(1).slug == 'foobar'
1000 1030

  
tests/api/test_carddef.py
1031 1031
    NamedDataSource.wipe()
1032 1032
    data_source = NamedDataSource(name='foobar')
1033 1033
    source = [{'id': '1', 'text': 'foo', 'more': 'XXX'}, {'id': '2', 'text': 'bar', 'more': 'YYY'}]
1034
    data_source.data_source = {'type': 'formula', 'value': repr(source)}
1034
    data_source.data_source = {'type': 'jsonvalue', 'value': json.dumps(source)}
1035 1035
    data_source.store()
1036 1036

  
1037 1037
    data_source = NamedDataSource(name='foobar_jsonp')
......
1123 1123
    NamedDataSource.wipe()
1124 1124
    data_source = NamedDataSource(name='foobar')
1125 1125
    source = [{'id': '1', 'text': 'foo', 'more': 'XXX'}, {'id': '2', 'text': 'bar', 'more': 'YYY'}]
1126
    data_source.data_source = {'type': 'formula', 'value': repr(source)}
1126
    data_source.data_source = {'type': 'jsonvalue', 'value': json.dumps(source)}
1127 1127
    data_source.store()
1128 1128

  
1129 1129
    data_source = NamedDataSource(name='foobar_jsonp')
......
1267 1267
            label='foobar1',
1268 1268
            varname='foobar1',
1269 1269
            data_source={
1270
                'type': 'formula',
1271
                'value': '[dict(id=i, text=\'label %s\' % i, foo=i) for i in range(10)]',
1270
                'type': 'jsonvalue',
1271
                'value': json.dumps([{'id': i, 'text': 'label %s' % i, 'foo': i} for i in range(10)]),
1272 1272
            },
1273 1273
        ),
1274 1274
    ]
tests/api/test_formdata.py
1 1
import base64
2 2
import datetime
3 3
import io
4
import json
4 5
import os
5 6
import re
6 7
import time
......
108 109
    NamedDataSource.wipe()
109 110
    data_source = NamedDataSource(name='foobar')
110 111
    data_source.data_source = {
111
        'type': 'formula',
112
        'value': repr([{'id': '1', 'text': 'foo', 'more': 'XXX'}, {'id': '2', 'text': 'bar', 'more': 'YYY'}]),
112
        'type': 'jsonvalue',
113
        'value': json.dumps(
114
            [{'id': '1', 'text': 'foo', 'more': 'XXX'}, {'id': '2', 'text': 'bar', 'more': 'YYY'}]
115
        ),
113 116
    }
114 117
    data_source.store()
115 118

  
......
1302 1305
    NamedDataSource.wipe()
1303 1306
    data_source = NamedDataSource(name='foobar')
1304 1307
    data_source.data_source = {
1305
        'type': 'formula',
1306
        'value': repr([{'id': '9', 'text': 'foo'}, {'id': '10', 'text': 'bar'}, {'id': '11', 'text': 'baz'}]),
1308
        'type': 'jsonvalue',
1309
        'value': json.dumps(
1310
            [{'id': '9', 'text': 'foo'}, {'id': '10', 'text': 'bar'}, {'id': '11', 'text': 'baz'}]
1311
        ),
1307 1312
    }
1308 1313
    data_source.store()
1309 1314

  
......
1388 1393
    # use large numbers as identifiers as they are concatenated in SQL and it should
1389 1394
    # not trigger any out-of-bounds SQL checks or Python pre-checks.
1390 1395
    data_source.data_source = {
1391
        'type': 'formula',
1392
        'value': repr(
1396
        'type': 'jsonvalue',
1397
        'value': json.dumps(
1393 1398
            [{'id': '9000', 'text': 'foo'}, {'id': '10000', 'text': 'bar'}, {'id': '11000', 'text': 'baz'}]
1394 1399
        ),
1395 1400
    }
......
1772 1777
    NamedDataSource.wipe()
1773 1778
    data_source = NamedDataSource(name='foobar')
1774 1779
    data_source.data_source = {
1775
        'type': 'formula',
1776
        'value': repr([{'id': '1', 'text': 'foo'}, {'id': '2', 'text': 'bar'}]),
1780
        'type': 'jsonvalue',
1781
        'value': json.dumps([{'id': '1', 'text': 'foo'}, {'id': '2', 'text': 'bar'}]),
1777 1782
    }
1778 1783
    data_source.store()
1779 1784

  
tests/api/test_formdef.py
421 421
            label='foobar2',
422 422
            varname='foobar2',
423 423
            data_source={
424
                'type': 'formula',
425
                'value': '[dict(id=i, text=\'label %s\' % i, foo=i) for i in range(10)]',
424
                'type': 'jsonvalue',
425
                'value': json.dumps([{'id': i, 'text': 'label %s' % i, 'foo': i} for i in range(10)]),
426 426
            },
427 427
        ),
428 428
    ]
......
689 689
    NamedDataSource.wipe()
690 690
    data_source = NamedDataSource(name='foobar')
691 691
    source = [{'id': '1', 'text': 'foo', 'more': 'XXX'}, {'id': '2', 'text': 'bar', 'more': 'YYY'}]
692
    data_source.data_source = {'type': 'formula', 'value': repr(source)}
692
    data_source.data_source = {'type': 'jsonvalue', 'value': json.dumps(source)}
693 693
    data_source.store()
694 694

  
695 695
    data_source = NamedDataSource(name='foobar_jsonp')
......
891 891
            label='foobar1',
892 892
            varname='foobar1',
893 893
            data_source={
894
                'type': 'formula',
895
                'value': '[dict(id=i, text=\'label %s\' % i, foo=i) for i in range(10)]',
894
                'type': 'jsonvalue',
895
                'value': json.dumps([{'id': i, 'text': 'label %s' % i, 'foo': i} for i in range(10)]),
896 896
            },
897 897
        ),
898 898
        fields.ItemField(
tests/backoffice_pages/test_all.py
100 100
    if set_receiver:
101 101
        formdef.workflow_roles = {'_receiver': 1}
102 102

  
103
    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
103
    datasource = {
104
        'type': 'jsonvalue',
105
        'value': '[{"id": "A", "text": "aa"}, {"id": "B", "text": "bb"}, {"id": "C", "text": "cc"}]',
106
    }
104 107

  
105 108
    formdef.fields = []
106 109
    formdef.store()  # make sure sql columns are removed
tests/backoffice_pages/test_carddata.py
347 347
    user = create_user(pub)
348 348

  
349 349
    data_source = {
350
        'type': 'formula',
351
        'value': repr([{'id': '1', 'text': 'un', 'more': 'foo'}, {'id': '2', 'text': 'deux', 'more': 'bar'}]),
350
        'type': 'jsonvalue',
351
        'value': json.dumps(
352
            [{'id': '1', 'text': 'un', 'more': 'foo'}, {'id': '2', 'text': 'deux', 'more': 'bar'}]
353
        ),
352 354
    }
353 355

  
354 356
    CardDef.wipe()
......
597 599
    user = create_user(pub)
598 600

  
599 601
    data_source = {
600
        'type': 'formula',
601
        'value': repr([{'id': '1', 'text': 'un', 'more': 'foo'}, {'id': '2', 'text': 'deux', 'more': 'bar'}]),
602
        'type': 'jsonvalue',
603
        'value': json.dumps(
604
            [{'id': '1', 'text': 'un', 'more': 'foo'}, {'id': '2', 'text': 'deux', 'more': 'bar'}]
605
        ),
602 606
    }
603 607

  
604 608
    CardDef.wipe()
tests/backoffice_pages/test_columns.py
322 322
    role = pub.role_class(name='test')
323 323
    role.store()
324 324

  
325
    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
325
    datasource = {
326
        'type': 'jsonvalue',
327
        'value': '[{"id": "A", "text": "aa"}, {"id": "B", "text": "bb"}, {"id": "C", "text": "cc"}]',
328
    }
326 329

  
327 330
    CardDef.wipe()
328 331
    carddef = CardDef()
tests/backoffice_pages/test_custom_view.py
1017 1017
def test_backoffice_custom_view_keep_filters(pub):
1018 1018
    user = create_superuser(pub)
1019 1019

  
1020
    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
1020
    datasource = {
1021
        'type': 'jsonvalue',
1022
        'value': '[{"id": "A", "text": "aa"}, {"id": "B", "text": "bb"}, {"id": "C", "text": "cc"}]',
1023
    }
1021 1024
    FormDef.wipe()
1022 1025
    pub.custom_view_class.wipe()
1023 1026
    formdef = FormDef()
tests/backoffice_pages/test_export.py
49 49
def test_backoffice_csv(pub):
50 50
    create_superuser(pub)
51 51

  
52
    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
52
    datasource = {
53
        'type': 'jsonvalue',
54
        'value': '[{"id": "A", "text": "aa"}, {"id": "B", "text": "bb"}, {"id": "C", "text": "cc"}]',
55
    }
53 56
    FormDef.wipe()
54 57
    formdef = FormDef()
55 58
    formdef.name = 'form title'
tests/backoffice_pages/test_filters.py
1274 1274
    role = pub.role_class(name='test')
1275 1275
    role.store()
1276 1276

  
1277
    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
1277
    datasource = {
1278
        'type': 'jsonvalue',
1279
        'value': '[{"id": "A", "text": "aa"}, {"id": "B", "text": "bb"}, {"id": "C", "text": "cc"}]',
1280
    }
1278 1281
    FormDef.wipe()
1279 1282
    formdef = FormDef()
1280 1283
    formdef.name = 'form-title'
......
1338 1341
    NamedDataSource.wipe()
1339 1342
    data_source = NamedDataSource(name='foobar')
1340 1343
    data_source.data_source = {
1341
        'type': 'formula',
1342
        'value': repr([{'id': '1', 'text': 'foo', 'more': 'XXX'}, {'id': '2', 'text': 'bar', 'more': 'YYY'}]),
1344
        'type': 'jsonvalue',
1345
        'value': '[{"id": "1", "text": "foo", "more": "XXX"}, {"id": "2", "text": "bar", "more": "YYY"}]',
1343 1346
    }
1344 1347
    data_source.store()
1345 1348

  
tests/backoffice_pages/test_form_inspect.py
55 55

  
56 56
    formdef = FormDef()
57 57
    formdef.name = 'form title'
58
    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
58
    datasource = {
59
        'type': 'jsonvalue',
60
        'value': '[{"id": "A", "text": "aa"}, {"id": "B", "text": "bb"}, {"id": "C", "text": "cc"}]',
61
    }
59 62
    formdef.fields = [
60 63
        fields.StringField(
61 64
            id='1', label='1st field', type='string', display_locations=['validation', 'summary', 'listings']
tests/backoffice_pages/test_submission.py
53 53
def test_backoffice_submission(pub):
54 54
    user = create_user(pub)
55 55

  
56
    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
56
    datasource = {
57
        'type': 'jsonvalue',
58
        'value': '[{"id": "A", "text": "aa"}, {"id": "B", "text": "bb"}, {"id": "C", "text": "cc"}]',
59
    }
57 60
    FormDef.wipe()
58 61
    formdef = FormDef()
59 62
    formdef.name = 'form title'
tests/form_pages/test_all.py
1031 1031
    # add the named data source, empty
1032 1032
    NamedDataSource.wipe()
1033 1033
    data_source = NamedDataSource(name='foobar')
1034
    data_source.data_source = {'type': 'formula', 'value': repr([])}
1034
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
1035 1035
    data_source.store()
1036 1036

  
1037 1037
    resp = get_app(pub).get('/test/')
......
1045 1045
    # replace the named data source with one with items
1046 1046
    NamedDataSource.wipe()
1047 1047
    data_source = NamedDataSource(name='foobar')
1048
    data_source.data_source = {'type': 'formula', 'value': repr(['un', 'deux'])}
1048
    data_source.data_source = {
1049
        'type': 'jsonvalue',
1050
        'value': '[{"id": "un", "text": "un"}, {"id": "deux", "text": "deux"}]',
1051
    }
1049 1052
    data_source.store()
1050 1053

  
1051 1054
    resp = resp.forms[0].submit('submit')  # should go to second page
......
3189 3192
        return formdef.data_class().get(data_id).data
3190 3193

  
3191 3194
    ds = {
3192
        'type': 'formula',
3193
        'value': repr([('1', 'un'), ('2', 'deux')]),
3195
        'type': 'jsonvalue',
3196
        'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
3194 3197
    }
3195 3198
    assert submit_item_data_source_field(ds) == {'0': '1', '0_display': 'un'}
3196 3199

  
3197
    ds['value'] = repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}])
3200
    ds['value'] = json.dumps([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}])
3198 3201
    assert submit_item_data_source_field(ds) == {'0': '1', '0_display': 'un'}
3199 3202

  
3200
    ds['value'] = repr([{'id': '1', 'text': 'un', 'more': 'foo'}, {'id': '2', 'text': 'deux', 'more': 'bar'}])
3203
    ds['value'] = json.dumps(
3204
        [{'id': '1', 'text': 'un', 'more': 'foo'}, {'id': '2', 'text': 'deux', 'more': 'bar'}]
3205
    )
3201 3206
    assert submit_item_data_source_field(ds) == {
3202 3207
        '0': '1',
3203 3208
        '0_display': 'un',
......
3205 3210
    }
3206 3211

  
3207 3212
    # numeric identifiers
3208
    ds['value'] = repr([{'id': 1, 'text': 'un'}, {'id': 2, 'text': 'deux'}])
3213
    ds['value'] = json.dumps([{'id': 1, 'text': 'un'}, {'id': 2, 'text': 'deux'}])
3209 3214
    assert submit_item_data_source_field(ds) == {'0': '1', '0_display': 'un'}
3210 3215

  
3211 3216
    # json source
......
3399 3404
        return formdef.data_class().get(data_id).data
3400 3405

  
3401 3406
    ds = {
3402
        'type': 'formula',
3403
        'value': repr([('1', 'un'), ('2', 'deux'), ('3', 'trois')]),
3407
        'type': 'jsonvalue',
3408
        'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}, {"id": "3", "text": "trois"}]',
3404 3409
    }
3405 3410
    assert submit_items_data_source_field(ds) == {
3406 3411
        '0': ['1', '3'],
......
3408 3413
        '0_structured': [{'id': '1', 'text': 'un'}, {'id': '3', 'text': 'trois'}],
3409 3414
    }
3410 3415

  
3411
    ds['value'] = repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}, {'id': '3', 'text': 'trois'}])
3416
    ds['value'] = json.dumps(
3417
        [{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}, {'id': '3', 'text': 'trois'}]
3418
    )
3412 3419
    assert submit_items_data_source_field(ds) == {
3413 3420
        '0': ['1', '3'],
3414 3421
        '0_display': 'un, trois',
3415 3422
        '0_structured': [{'id': '1', 'text': 'un'}, {'id': '3', 'text': 'trois'}],
3416 3423
    }
3417 3424

  
3418
    ds['value'] = repr(
3425
    ds['value'] = json.dumps(
3419 3426
        [
3420 3427
            {'id': '1', 'text': 'un', 'more': 'foo'},
3421 3428
            {'id': '2', 'text': 'deux', 'more': 'bar'},
......
3660 3667
    NamedDataSource.wipe()
3661 3668
    data_source = NamedDataSource(name='foobar')
3662 3669
    data_source.data_source = {
3663
        'type': 'formula',
3664
        'value': repr(
3670
        'type': 'jsonvalue',
3671
        'value': json.dumps(
3665 3672
            [
3666 3673
                {'id': '1', 'text': 'un'},
3667 3674
                {'id': '2', 'text': 'deux'},
......
4769 4776
    # add the named data source
4770 4777
    NamedDataSource.wipe()
4771 4778
    data_source = NamedDataSource(name='foobar')
4772
    data_source.data_source = {'type': 'formula', 'value': repr([])}
4779
    data_source.data_source = {'type': 'jsonvalue', 'value': '[]'}
4773 4780
    data_source.store()
4774 4781

  
4775 4782
    resp = get_app(pub).get('/test/')
......
4782 4789
    # replace the named data source with one with items
4783 4790
    NamedDataSource.wipe()
4784 4791
    data_source = NamedDataSource(name='foobar')
4785
    data_source.data_source = {'type': 'formula', 'value': repr(['un', 'deux'])}
4792
    data_source.data_source = {
4793
        'type': 'jsonvalue',
4794
        'value': '[{"id": "un", "text": "un"}, {"id": "deux", "text": "deux"}]',
4795
    }
4786 4796
    data_source.store()
4787 4797

  
4788 4798
    resp = get_app(pub).get('/test/')
......
4802 4812
    }
4803 4813

  
4804 4814
    data_source.data_source = {
4805
        'type': 'formula',
4806
        'value': repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}]),
4815
        'type': 'jsonvalue',
4816
        'value': json.dumps([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}]),
4807 4817
    }
4808 4818
    data_source.store()
4809 4819

  
......
4825 4835
    }
4826 4836

  
4827 4837
    data_source.data_source = {
4828
        'type': 'formula',
4829
        'value': repr([{'id': '1', 'text': 'un', 'foo': 'bar1'}, {'id': '2', 'text': 'deux', 'foo': 'bar2'}]),
4838
        'type': 'jsonvalue',
4839
        'value': json.dumps(
4840
            [{'id': '1', 'text': 'un', 'foo': 'bar1'}, {'id': '2', 'text': 'deux', 'foo': 'bar2'}]
4841
        ),
4830 4842
    }
4831 4843
    data_source.store()
4832 4844

  
......
8029 8041
            varname='listA',
8030 8042
            type='item',
8031 8043
            label='list A',
8032
            data_source={'type': 'formula', 'value': str(items_A)},
8044
            data_source={'type': 'jsonvalue', 'value': json.dumps(items_A)},
8033 8045
            condition={'type': 'python', 'value': 'form_var_choice_raw == "A"'},
8034 8046
        ),
8035 8047
        fields.ItemField(
......
8037 8049
            varname='listB',
8038 8050
            type='item',
8039 8051
            label='list B',
8040
            data_source={'type': 'formula', 'value': str(items_B)},
8052
            data_source={'type': 'jsonvalue', 'value': json.dumps(items_B)},
8041 8053
            condition={'type': 'python', 'value': 'form_var_choice_raw == "B"'},
8042 8054
        ),
8043 8055
    ]
......
8099 8111
            varname='listA',
8100 8112
            type='item',
8101 8113
            label='list A',
8102
            data_source={'type': 'formula', 'value': str(items_A)},
8114
            data_source={'type': 'jsonvalue', 'value': json.dumps(items_A)},
8103 8115
            condition={'type': 'python', 'value': 'form_var_choice_raw == "A"'},
8104 8116
        ),
8105 8117
        fields.ItemField(
......
8107 8119
            varname='listB',
8108 8120
            type='item',
8109 8121
            label='list B',
8110
            data_source={'type': 'formula', 'value': str(items_B)},
8122
            data_source={'type': 'jsonvalue', 'value': json.dumps(items_B)},
8111 8123
            condition={'type': 'python', 'value': 'form_var_choice_raw == "B"'},
8112 8124
        ),
8113 8125
    ]
......
8650 8662
    NamedDataSource.wipe()
8651 8663
    data_source = NamedDataSource(name='foobar')
8652 8664
    data_source.data_source = {
8653
        'type': 'formula',
8654
        'value': repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}]),
8665
        'type': 'jsonvalue',
8666
        'value': json.dumps([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}]),
8655 8667
    }
8656 8668
    data_source.store()
8657 8669

  
......
8877 8889
        {'id': '2', 'text': 'deux', 'more': 'bar'},
8878 8890
    ]
8879 8891
    ds = {
8880
        'type': 'formula',
8881
        'value': repr(data),
8892
        'type': 'jsonvalue',
8893
        'value': json.dumps(data),
8882 8894
    }
8883 8895
    source_formdef = FormDef()
8884 8896
    source_formdef.name = 'source form'
......
9188 9200
    workflow = Workflow(name='test')
9189 9201
    workflow.variables_formdef = WorkflowVariablesFieldsFormDef(workflow=workflow)
9190 9202
    data_source = {
9191
        'type': 'formula',
9192
        'value': repr([{'id': '1', 'text': 'un', 'more': 'foo'}, {'id': '2', 'text': 'deux', 'more': 'bar'}]),
9203
        'type': 'jsonvalue',
9204
        'value': json.dumps(
9205
            [{'id': '1', 'text': 'un', 'more': 'foo'}, {'id': '2', 'text': 'deux', 'more': 'bar'}]
9206
        ),
9193 9207
    }
9194 9208
    workflow.variables_formdef.fields = [
9195 9209
        fields.StringField(id='1', label='Test', type='string', varname='foo'),
tests/test_content_snapshots.py
352 352
        fields.FileField(id='5', label='File', type='file'),
353 353
        fields.DateField(id='6', label='Date', type='date'),
354 354
        fields.ItemField(
355
            id='7', label='Item', type='item', data_source={'type': 'formula', 'value': repr(['a', 'b'])}
355
            id='7',
356
            label='Item',
357
            type='item',
358
            data_source={
359
                'type': 'jsonvalue',
360
                'value': '[{"id": "a", "text": "a"}, {"id": "b", "text": "b"}]',
361
            },
356 362
        ),
357 363
        fields.ItemsField(
358
            id='8', label='Items', type='items', data_source={'type': 'formula', 'value': repr(['a', 'b'])}
364
            id='8',
365
            label='Items',
366
            type='items',
367
            data_source={
368
                'type': 'jsonvalue',
369
                'value': '[{"id": "a", "text": "a"}, {"id": "b", "text": "b"}]',
370
            },
359 371
        ),
360 372
        fields.MapField(id='9', label='Map', type='map'),
361 373
        fields.PasswordField(id='10', label='Password', type='password'),
......
382 394
        fields.FileField(id='5', label='File', type='file'),
383 395
        fields.DateField(id='6', label='Date', type='date'),
384 396
        fields.ItemField(
385
            id='7', label='Item', type='item', data_source={'type': 'formula', 'value': repr(['a', 'b'])}
397
            id='7',
398
            label='Item',
399
            type='item',
400
            data_source={
401
                'type': 'jsonvalue',
402
                'value': '[{"id": "a", "text": "a"}, {"id": "b", "text": "b"}]',
403
            },
386 404
        ),
387 405
        fields.ItemsField(
388
            id='8', label='Items', type='items', data_source={'type': 'formula', 'value': repr(['a', 'b'])}
406
            id='8',
407
            label='Items',
408
            type='items',
409
            data_source={
410
                'type': 'jsonvalue',
411
                'value': '[{"id": "a", "text": "a"}, {"id": "b", "text": "b"}]',
412
            },
389 413
        ),
390 414
        fields.MapField(id='9', label='Map', type='map'),
391 415
        fields.PasswordField(id='10', label='Password', type='password'),
tests/test_fields.py
162 162
    assert len(fields.ItemsField(items=['a', 'b', 'c'], max_choices=2).get_csv_heading()) == 2
163 163

  
164 164
    field = fields.ItemsField()
165
    field.data_source = {'type': 'formula', 'value': '''[('1', 'foo'), ('2', 'bar')]'''}
165
    field.data_source = {
166
        'type': 'jsonvalue',
167
        'value': '[{"id": "1", "text": "foo"}, {"id": "2", "text": "bar"}]',
168
    }
166 169
    assert field.get_options() == [('1', 'foo', '1'), ('2', 'bar', '2')]
167 170
    assert field.get_options() == [('1', 'foo', '1'), ('2', 'bar', '2')]  # twice for cached behaviour
168 171

  
......
185 188

  
186 189
    # data source with structured : labels are available
187 190
    field = fields.ItemsField(id='1')
188
    field.data_source = {'type': 'formula', 'value': '''[('1', 'un'), ('2', 'deux')]'''}
191
    field.data_source = {
192
        'type': 'jsonvalue',
193
        'value': '[{"id": "1", "text": "foo"}, {"id": "2", "text": "bar"}]',
194
    }
189 195
    assert field.get_value_info(
190 196
        {
191 197
            '1': ['un', 'deux'],
......
199 205

  
200 206
    # data source with no strucured : no labels
201 207
    field = fields.ItemsField(id='1')
202
    field.data_source = {'type': 'formula', 'value': '''[('1', 'un'), ('2', 'deux')]'''}
208
    field.data_source = {
209
        'type': 'jsonvalue',
210
        'value': '[{"id": "1", "text": "foo"}, {"id": "2", "text": "bar"}]',
211
    }
203 212
    assert field.get_value_info({'1': ['un', 'deux'], '1_display': 'un, deux'}) == (
204 213
        'un, deux',
205 214
        {'value_id': ['un', 'deux'], 'labels': []},
......
419 428
def test_item_render():
420 429
    items_kwargs = []
421 430
    items_kwargs.append({'items': ['aa', 'ab', 'ac']})
422
    items_kwargs.append({'data_source': {'type': 'formula', 'value': '''['aa', 'ab', 'ac']'''}})
431
    items_kwargs.append(
432
        {
433
            'data_source': {
434
                'type': 'jsonvalue',
435
                'value': '[{"id": "aa", "text": "aa"}, {"id": "ab", "text": "ab"}, {"id": "ac", "text": "ac"}]',
436
            }
437
        }
438
    )
423 439

  
424 440
    for item_kwargs in items_kwargs:
425 441
        field = fields.ItemField(id='1', label='Foobar', **item_kwargs)
......
451 467
    items_kwargs = []
452 468
    items_kwargs.append({'items': None})
453 469
    items_kwargs.append({'items': []})
454
    items_kwargs.append({'data_source': {'type': 'formula', 'value': '''[]'''}})
470
    items_kwargs.append({'data_source': {'type': 'jsonvalue', 'value': '[]'}})
455 471
    for item_kwargs in items_kwargs:
456 472
        field = fields.ItemField(id='1', label='Foobar', **item_kwargs)
457 473
        form = Form(use_tokens=False)
......
509 525
def test_item_render_as_radio():
510 526
    items_kwargs = []
511 527
    items_kwargs.append({'items': ['aa', 'ab', 'ac']})
512
    items_kwargs.append({'data_source': {'type': 'formula', 'value': '''['aa', 'ab', 'ac']'''}})
528
    items_kwargs.append(
529
        {
530
            'data_source': {
531
                'type': 'jsonvalue',
532
                'value': '[{"id": "aa", "text": "aa"}, {"id": "ab", "text": "ab"}, {"id": "ac", "text": "ac"}]',
533
            }
534
        }
535
    )
513 536

  
514 537
    for item_kwargs in items_kwargs:
515 538
        field = fields.ItemField(id='1', label='Foobar', display_mode='radio', **item_kwargs)
......
539 562
    items_kwargs = []
540 563
    items_kwargs.append({'items': None})
541 564
    items_kwargs.append({'items': []})
542
    items_kwargs.append({'data_source': {'type': 'formula', 'value': '''[]'''}})
565
    items_kwargs.append({'data_source': {'type': 'jsonvalue', 'value': '[]'}})
543 566
    for item_kwargs in items_kwargs:
544 567
        field = fields.ItemField(id='1', label='Foobar', display_mode='radio', **item_kwargs)
545 568
        form = Form(use_tokens=False)
......
595 618
def test_items_render():
596 619
    items_kwargs = []
597 620
    items_kwargs.append({'items': ['aa', 'ab', 'ac']})
598
    items_kwargs.append({'data_source': {'type': 'formula', 'value': '''['aa', 'ab', 'ac']'''}})
621
    items_kwargs.append(
622
        {
623
            'data_source': {
624
                'type': 'jsonvalue',
625
                'value': '[{"id": "aa", "text": "aa"}, {"id": "ab", "text": "ab"}, {"id": "ac", "text": "ac"}]',
626
            }
627
        }
628
    )
599 629

  
600 630
    for item_kwargs in items_kwargs:
601 631
        field = fields.ItemsField(id='1', label='Foobar', **item_kwargs)
tests/test_formdata.py
1 1
import collections
2 2
import datetime
3 3
import io
4
import json
4 5
import os.path
5 6
import time
6 7
import uuid
......
451 452

  
452 453
def test_field_item_substvars(pub):
453 454
    ds = {
454
        'type': 'formula',
455
        'value': repr([('1', 'un'), ('2', 'deux')]),
455
        'type': 'jsonvalue',
456
        'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
456 457
    }
457 458

  
458 459
    formdef = FormDef()
......
3140 3141

  
3141 3142
def test_lazy_url_suffix(pub, variable_test_data):
3142 3143
    ds = {
3143
        'type': 'formula',
3144
        'value': repr(
3144
        'type': 'jsonvalue',
3145
        'value': json.dumps(
3145 3146
            [
3146 3147
                {'id': '1', 'text': 'un', 'more': 'foo', 'url': 'xxx'},
3147 3148
                {'id': '2', 'text': 'deux', 'more': 'bar', 'url': 'yyy'},
......
3176 3177

  
3177 3178
def test_lazy_structured_items(pub, variable_test_data):
3178 3179
    ds = {
3179
        'type': 'formula',
3180
        'value': repr(
3180
        'type': 'jsonvalue',
3181
        'value': json.dumps(
3181 3182
            [
3182 3183
                {'id': '1', 'text': 'un', 'more': 'foo', 'url': 'xxx', 'invalid:key': 'xxx'},
3183 3184
                {'id': '2', 'text': 'deux', 'more': 'bar', 'url': 'yyy', 'invalid:key': 'yyy'},
......
3186 3187
    }
3187 3188

  
3188 3189
    ds2 = {
3189
        'type': 'formula',
3190
        'value': repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}]),
3190
        'type': 'jsonvalue',
3191
        'value': json.dumps([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}]),
3191 3192
    }
3192 3193

  
3193 3194
    FormDef.wipe()
......
3586 3587
    NamedDataSource.wipe()
3587 3588
    data_source = NamedDataSource(name='foobar')
3588 3589
    data_source.data_source = {
3589
        'type': 'formula',
3590
        'value': repr([{'id': '1', 'text': 'foo'}, {'id': '2', 'text': 'bar'}]),
3590
        'type': 'jsonvalue',
3591
        'value': json.dumps([{'id': '1', 'text': 'foo'}, {'id': '2', 'text': 'bar'}]),
3591 3592
    }
3592 3593
    data_source.store()
3593 3594
    data_source2 = NamedDataSource(name='foobar2')
3594 3595
    # use large numbers as identifiers as they are concatenated in SQL and it should
3595 3596
    # not trigger any out-of-bounds SQL checks or Python pre-checks.
3596 3597
    data_source2.data_source = {
3597
        'type': 'formula',
3598
        'value': repr(
3598
        'type': 'jsonvalue',
3599
        'value': json.dumps(
3599 3600
            [{'id': '9000', 'text': 'foo'}, {'id': '10000', 'text': 'bar'}, {'id': '11000', 'text': 'baz'}]
3600 3601
        ),
3601 3602
    }
......
3877 3878
    NamedDataSource.wipe()
3878 3879
    data_source = NamedDataSource(name='foobar')
3879 3880
    data_source.data_source = {
3880
        'type': 'formula',
3881
        'value': repr([{'id': '1', 'text': 'foo'}, {'id': '2', 'text': 'bar'}]),
3881
        'type': 'jsonvalue',
3882
        'value': json.dumps([{'id': '1', 'text': 'foo'}, {'id': '2', 'text': 'bar'}]),
3882 3883
    }
3883 3884
    data_source.store()
3884 3885

  
......
4093 4094
    NamedDataSource.wipe()
4094 4095
    data_source = NamedDataSource(name='foobar')
4095 4096
    data_source.data_source = {
4096
        'type': 'formula',
4097
        'value': repr(
4097
        'type': 'jsonvalue',
4098
        'value': json.dumps(
4098 4099
            [
4099 4100
                {'id': '1', 'text': 'un'},
4100 4101
                {'id': '2', 'text': 'deux'},
......
4175 4176
    NamedDataSource.wipe()
4176 4177
    data_source = NamedDataSource(name='foobar')
4177 4178
    data_source.data_source = {
4178
        'type': 'formula',
4179
        'value': repr(
4179
        'type': 'jsonvalue',
4180
        'value': json.dumps(
4180 4181
            [
4181 4182
                {'id': '1', 'text': 'un'},
4182 4183
                {'id': '2', 'text': 'deux'},
......
4227 4228
    NamedDataSource.wipe()
4228 4229
    data_source = NamedDataSource(name='foobar')
4229 4230
    data_source.data_source = {
4230
        'type': 'formula',
4231
        'value': repr(
4231
        'type': 'jsonvalue',
4232
        'value': json.dumps(
4232 4233
            [
4233 4234
                {'id': '1', 'text': 'un'},
4234 4235
                {'id': '2', 'text': 'deux'},
tests/test_snapshots.py
501 501

  
502 502
    NamedDataSource.wipe()
503 503
    datasource = NamedDataSource(name='test')
504
    datasource.data_source = {'type': 'formula', 'value': repr([('1', 'un'), ('2', 'deux')])}
504
    datasource.data_source = {
505
        'type': 'jsonvalue',
506
        'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
507
    }
505 508
    datasource.store()
506 509
    assert pub.snapshot_class.count() == 1
507 510
    # check calling .store() without changes doesn't create snapshots
tests/workflow/test_all.py
2292 2292
    wf.store()
2293 2293

  
2294 2294
    datasource = {
2295
        'type': 'formula',
2296
        'value': repr(
2295
        'type': 'jsonvalue',
2296
        'value': json.dumps(
2297 2297
            [
2298 2298
                {'id': 'a', 'text': 'aa', 'more': 'aaa'},
2299 2299
                {'id': 'b', 'text': 'bb', 'more': 'bbb'},
tests/workflow/test_backoffice_field.py
1 1
import base64
2 2
import datetime
3
import json
3 4
import os
4 5

  
5 6
import pytest
......
606 607
    assert formdata.data['bo1'] == 'a'
607 608
    assert formdata.data['bo1_display'] == 'a'
608 609

  
609
    datasource = {'type': 'formula', 'value': repr([('a', 'aa'), ('b', 'bb'), ('c', 'cc')])}
610
    datasource = {
611
        'type': 'jsonvalue',
612
        'value': json.dumps(
613
            [
614
                {'id': 'a', 'text': 'aa'},
615
                {'id': 'b', 'text': 'bb'},
616
                {'id': 'c', 'text': 'cc'},
617
            ]
618
        ),
619
    }
610 620

  
611 621
    wf.backoffice_fields_formdef.fields = [
612 622
        ItemField(
......
629 639
    assert formdata.data['bo1_display'] == 'aa'
630 640

  
631 641
    datasource = {
632
        'type': 'formula',
633
        'value': repr([{'id': 'a', 'text': 'aa', 'more': 'aaa'}, {'id': 'b', 'text': 'bb', 'more': 'bbb'}]),
642
        'type': 'jsonvalue',
643
        'value': json.dumps(
644
            [{'id': 'a', 'text': 'aa', 'more': 'aaa'}, {'id': 'b', 'text': 'bb', 'more': 'bbb'}]
645
        ),
634 646
    }
635 647

  
636 648
    wf.backoffice_fields_formdef.fields = [
......
836 848
    assert formdata.data['bo1'] == ['a', 'b']
837 849
    assert formdata.data['bo1_display'] == 'a, b'
838 850

  
839
    datasource = {'type': 'formula', 'value': repr([('a', 'aa'), ('b', 'bb'), ('c', 'cc')])}
851
    datasource = {
852
        'type': 'jsonvalue',
853
        'value': json.dumps(
854
            [
855
                {'id': 'a', 'text': 'aa'},
856
                {'id': 'b', 'text': 'bb'},
857
                {'id': 'c', 'text': 'cc'},
858
            ]
859
        ),
860
    }
840 861

  
841 862
    wf.backoffice_fields_formdef.fields = [
842 863
        ItemsField(
......
859 880
    assert formdata.data['bo1_display'] == 'aa, bb'
860 881

  
861 882
    datasource = {
862
        'type': 'formula',
863
        'value': repr(
883
        'type': 'jsonvalue',
884
        'value': json.dumps(
864 885
            [
865 886
                {'id': 'a', 'text': 'aa', 'more': 'aaa'},
866 887
                {'id': 'b', 'text': 'bb', 'more': 'bbb'},
......
932 953

  
933 954
    # using a single int
934 955
    datasource = {
935
        'type': 'formula',
936
        'value': repr(
956
        'type': 'jsonvalue',
957
        'value': json.dumps(
937 958
            [
938 959
                {'id': 1, 'text': 'aa', 'more': 'aaa'},
939 960
                {'id': 2, 'text': 'bb', 'more': 'bbb'},
......
1337 1358

  
1338 1359
    # "item" subfield, make sure raw and display and structured values are stored
1339 1360
    datasource = {
1340
        'type': 'formula',
1341
        'value': repr(
1361
        'type': 'jsonvalue',
1362
        'value': json.dumps(
1342 1363
            [
1343 1364
                {'id': 'a', 'text': 'aa', 'more': 'aaa'},
1344 1365
                {'id': 'b', 'text': 'bb', 'more': 'bbb'},
tests/workflow/test_carddata.py
1 1
import datetime
2
import json
2 3
import os
3 4

  
4 5
import pytest
......
588 589
    CardDef.wipe()
589 590

  
590 591
    datasource = {
591
        'type': 'formula',
592
        'value': repr(
592
        'type': 'jsonvalue',
593
        'value': json.dumps(
593 594
            [
594 595
                {'id': 'b', 'text': 'baker', 'extra': 'plop'},
595 596
                {'id': 'c', 'text': 'cook', 'extra': 'plop2'},
596
-