Projet

Général

Profil

0002-tests-add-test-on-JSON-dimensions-41814.patch

Benjamin Dauvergne, 20 avril 2020 20:17

Télécharger (5,86 ko)

Voir les différences:

Subject: [PATCH 2/5] tests: add test on JSON dimensions (#41814)

 tests/fixtures/schema1/01_schema.json |  3 ++-
 tests/fixtures/schema1/01_schema.sql  | 39 ++++++++++++++-------------
 tests/test_schema1.py                 | 27 +++++++++++++++++++
 3 files changed, 49 insertions(+), 20 deletions(-)
tests/fixtures/schema1/01_schema.json
242 242
            "warnings": [
243 243
                "le champ \u00ab pou\u00ebt \u00bb n'est pas bon",
244 244
                "warning2"
245
            ]
245
            ],
246
            "json_field": "json"
246 247
        }
247 248
    ],
248 249
    "label": "test schema1",
tests/fixtures/schema1/01_schema.sql
27 27
    rightsubcategory_id integer references schema1.subcategory(id),
28 28
    outersubcategory_id integer references schema1.subcategory(id),
29 29
    "String" varchar,
30
    geo point
30
    geo point,
31
    json jsonb
31 32
);
32 33

  
33 34
INSERT INTO category (ord, label) VALUES
......
47 48
   (3, 0, 'subé9');
48 49

  
49 50

  
50
INSERT INTO "Facts" (date, datetime, integer, boolean, cnt, innersubcategory_id, leftsubcategory_id, rightsubcategory_id, outersubcategory_id, "String", geo) VALUES
51
   ('2017-01-01', '2017-01-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
52
   ('2017-01-02', '2017-01-02 10:00', 1, TRUE, 10, 3, 3, 3, 3, 'b', '(1, 1)'),
53
   ('2017-01-03', '2017-01-03 10:00', 1, FALSE, 10, NULL, NULL, NULL, NULL, 'a', '(1, 1)'),
54
   ('2017-01-04', '2017-01-04 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
55
   ('2017-01-05', '2017-01-05 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'c', '(1, 1)'),
56
   ('2017-01-06', '2017-01-06 10:00', 1, FALSE, 10, 1, 1, 1, 1, NULL, '(1, 1)'),
57
   ('2017-01-07', '2017-01-07 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
58
   ('2017-01-08', '2017-01-08 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
59
   ('2017-01-09', '2017-01-09 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
60
   ('2017-01-10', '2017-01-10 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
61
   ('2017-02-01', '2017-02-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
62
   ('2017-03-01', '2017-03-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'c', '(1, 1)'),
63
   ('2017-04-01', '2017-04-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
64
   ('2017-05-01', '2017-05-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
65
   ('2017-06-01', '2017-06-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'c', '(1, 1)'),
66
   ('2017-07-01', '2017-07-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'),
67
   ('2017-08-01', '2017-08-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'b', '(1, 1)');
51
INSERT INTO "Facts" (date, datetime, integer, boolean, cnt, innersubcategory_id, leftsubcategory_id, rightsubcategory_id, outersubcategory_id, "String", geo, json) VALUES
52
   ('2017-01-01', '2017-01-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "x"}'),
53
   ('2017-01-02', '2017-01-02 10:00', 1, TRUE, 10, 3, 3, 3, 3, 'b', '(1, 1)', '{"a": "x"}'),
54
   ('2017-01-03', '2017-01-03 10:00', 1, FALSE, 10, NULL, NULL, NULL, NULL, 'a', '(1, 1)', '{"a": "x"}'),
55
   ('2017-01-04', '2017-01-04 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "x"}'),
56
   ('2017-01-05', '2017-01-05 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'c', '(1, 1)', '{"a": "x"}'),
57
   ('2017-01-06', '2017-01-06 10:00', 1, FALSE, 10, 1, 1, 1, 1, NULL, '(1, 1)', '{"a": "x"}'),
58
   ('2017-01-07', '2017-01-07 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "x"}'),
59
   ('2017-01-08', '2017-01-08 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'),
60
   ('2017-01-09', '2017-01-09 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'),
61
   ('2017-01-10', '2017-01-10 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'),
62
   ('2017-02-01', '2017-02-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'),
63
   ('2017-03-01', '2017-03-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'c', '(1, 1)', '{"a": "y"}'),
64
   ('2017-04-01', '2017-04-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'),
65
   ('2017-05-01', '2017-05-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'),
66
   ('2017-06-01', '2017-06-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'c', '(1, 1)', '{"a": "y"}'),
67
   ('2017-07-01', '2017-07-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'),
68
   ('2017-08-01', '2017-08-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'b', '(1, 1)', '{"a": "z"}');
tests/test_schema1.py
348 348
        }
349 349
    })
350 350
    assert visu.json_data() == [{'coords': [], 'measures': [{'value': 17}]}]
351

  
352

  
353
def test_json_dimensions(schema1, app, admin):
354
    login(app, admin)
355
    response = app.get('/')
356
    response = response.click('schema1')
357
    response = response.click('Facts 1')
358
    form = response.form
359

  
360
    form.set('representation', 'table')
361
    form.set('measure', 'simple_count')
362
    form.set('drilldown_x', 'a')
363
    response = form.submit('visualize')
364
    assert get_table(response) == [
365
        ['A', 'x', 'y', 'z'],
366
        ['number of rows', '7', '9', '1']
367
    ]
368

  
369
    assert 'filter__a' in form.fields
370
    assert set([o[0] for o in form['filter__a'].options]) == {'x', 'y', 'z', '__none__'}
371

  
372
    form.set('filter__a', ['x', 'y'])
373
    response = form.submit('visualize')
374
    assert get_table(response) == [
375
        ['A', 'x', 'y', 'z'],
376
        ['number of rows', '7', '9', '0']
377
    ]
351
-