From ba47743521ef92a9ecf4f4e5ae8bd5f8b7a7f8ad Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 17 Apr 2020 18:55:54 +0200 Subject: [PATCH 2/4] 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(-) diff --git tests/fixtures/schema1/01_schema.json tests/fixtures/schema1/01_schema.json index b5b0b17..7b487cc 100644 --- tests/fixtures/schema1/01_schema.json +++ tests/fixtures/schema1/01_schema.json @@ -242,7 +242,8 @@ "warnings": [ "le champ \u00ab pou\u00ebt \u00bb n'est pas bon", "warning2" - ] + ], + "json_field": "json" } ], "label": "test schema1", diff --git tests/fixtures/schema1/01_schema.sql tests/fixtures/schema1/01_schema.sql index 3dc1dc2..2157d38 100644 --- tests/fixtures/schema1/01_schema.sql +++ tests/fixtures/schema1/01_schema.sql @@ -27,7 +27,8 @@ CREATE TABLE "Facts" ( rightsubcategory_id integer references schema1.subcategory(id), outersubcategory_id integer references schema1.subcategory(id), "String" varchar, - geo point + geo point, + json jsonb ); INSERT INTO category (ord, label) VALUES @@ -47,21 +48,21 @@ INSERT INTO subcategory (category_id, ord, label) VALUES (3, 0, 'subé9'); -INSERT INTO "Facts" (date, datetime, integer, boolean, cnt, innersubcategory_id, leftsubcategory_id, rightsubcategory_id, outersubcategory_id, "String", geo) VALUES - ('2017-01-01', '2017-01-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-01-02', '2017-01-02 10:00', 1, TRUE, 10, 3, 3, 3, 3, 'b', '(1, 1)'), - ('2017-01-03', '2017-01-03 10:00', 1, FALSE, 10, NULL, NULL, NULL, NULL, 'a', '(1, 1)'), - ('2017-01-04', '2017-01-04 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-01-05', '2017-01-05 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'c', '(1, 1)'), - ('2017-01-06', '2017-01-06 10:00', 1, FALSE, 10, 1, 1, 1, 1, NULL, '(1, 1)'), - ('2017-01-07', '2017-01-07 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-01-08', '2017-01-08 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-01-09', '2017-01-09 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-01-10', '2017-01-10 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-02-01', '2017-02-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-03-01', '2017-03-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'c', '(1, 1)'), - ('2017-04-01', '2017-04-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-05-01', '2017-05-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-06-01', '2017-06-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'c', '(1, 1)'), - ('2017-07-01', '2017-07-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)'), - ('2017-08-01', '2017-08-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'b', '(1, 1)'); +INSERT INTO "Facts" (date, datetime, integer, boolean, cnt, innersubcategory_id, leftsubcategory_id, rightsubcategory_id, outersubcategory_id, "String", geo, json) VALUES + ('2017-01-01', '2017-01-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "x"}'), + ('2017-01-02', '2017-01-02 10:00', 1, TRUE, 10, 3, 3, 3, 3, 'b', '(1, 1)', '{"a": "x"}'), + ('2017-01-03', '2017-01-03 10:00', 1, FALSE, 10, NULL, NULL, NULL, NULL, 'a', '(1, 1)', '{"a": "x"}'), + ('2017-01-04', '2017-01-04 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "x"}'), + ('2017-01-05', '2017-01-05 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'c', '(1, 1)', '{"a": "x"}'), + ('2017-01-06', '2017-01-06 10:00', 1, FALSE, 10, 1, 1, 1, 1, NULL, '(1, 1)', '{"a": "x"}'), + ('2017-01-07', '2017-01-07 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "x"}'), + ('2017-01-08', '2017-01-08 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'), + ('2017-01-09', '2017-01-09 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'), + ('2017-01-10', '2017-01-10 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'), + ('2017-02-01', '2017-02-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'), + ('2017-03-01', '2017-03-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'c', '(1, 1)', '{"a": "y"}'), + ('2017-04-01', '2017-04-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'), + ('2017-05-01', '2017-05-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'), + ('2017-06-01', '2017-06-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'c', '(1, 1)', '{"a": "y"}'), + ('2017-07-01', '2017-07-01 10:00', 1, FALSE, 10, 1, 1, 1, 1, 'a', '(1, 1)', '{"a": "y"}'), + ('2017-08-01', '2017-08-01 10:00', 1, TRUE, 10, 1, 1, 1, 1, 'b', '(1, 1)', '{"a": "z"}'); diff --git tests/test_schema1.py tests/test_schema1.py index be74a81..b47edf8 100644 --- tests/test_schema1.py +++ tests/test_schema1.py @@ -348,3 +348,30 @@ def test_empty_filter(schema1, app, admin): } }) assert visu.json_data() == [{'coords': [], 'measures': [{'value': 17}]}] + + +def test_json_dimensions(schema1, app, admin): + login(app, admin) + response = app.get('/') + response = response.click('schema1') + response = response.click('Facts 1') + form = response.form + + form.set('representation', 'table') + form.set('measure', 'simple_count') + form.set('drilldown_x', 'a') + response = form.submit('visualize') + assert get_table(response) == [ + ['A', 'x', 'y', 'z'], + ['number of rows', '7', '9', '1'] + ] + + assert 'filter__a' in form.fields + assert set([o[0] for o in form['filter__a'].options]) == {'x', 'y', 'z', '__none__'} + + form.set('filter__a', ['x', 'y']) + response = form.submit('visualize') + assert get_table(response) == [ + ['A', 'x', 'y', 'z'], + ['number of rows', '7', '9', '0'] + ] -- 2.26.0