From 802525374d3ea1d1fae6b75a4dde940f9ca185c5 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 26 Nov 2020 16:21:42 +0100 Subject: [PATCH 1/4] tests: decrease indentation level in dataviz (#48865) --- tests/test_dataviz.py | 1039 ++++++++++++++++++++--------------------- 1 file changed, 514 insertions(+), 525 deletions(-) diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 787906f5..6086f166 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -2,9 +2,10 @@ import json import mock import pytest -from httmock import HTTMock +from httmock import HTTMock, with_httmock from requests.exceptions import HTTPError +from django.apps import apps from django.contrib.auth.models import User, Group from django.test import override_settings @@ -27,6 +28,15 @@ def cell(): return cell +@pytest.fixture(autouse=True) +def bijoe_settings(settings): + settings.KNOWN_SERVICES = { + "bijoe": { + "plop": {"title": "test", "url": "https://bijoe.example.com", "secret": "combo", "orig": "combo"} + } + } + + def test_jsonp_gauge(app, cell): with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net'}): resp = app.get('/') @@ -247,574 +257,553 @@ def bijoe_mock(url, request): +@with_httmock(bijoe_mock) def test_chartng_cell(app): page = Page(title='One', slug='index') page.save() - with override_settings(KNOWN_SERVICES={ - 'bijoe': {'plop': {'title': 'test', 'url': 'https://bijoe.example.com', - 'secret': 'combo', 'orig': 'combo'}}}): - with HTTMock(bijoe_mock): - cell = ChartNgCell(page=page, order=1) - cell.data_reference = 'plop:example' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[0] - - # bar - chart = cell.get_chart() - assert chart.__class__.__name__ == 'Bar' - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [([222, 134, 0, 53], {'title': ''})] - - # horizontal bar - cell.chart_type = 'horizontal-bar' - chart = cell.get_chart() - assert chart.__class__.__name__ == 'HorizontalBar' - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [([222, 134, 0, 53], {'title': ''})] - - # pie - cell.chart_type = 'pie' - chart = cell.get_chart() - assert chart.__class__.__name__ == 'Pie' - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222], {'title': u'web'}), - ([134], {'title': u'mail'}), - ([53], {'title': u'email'}) - ] - - # data in Y - cell.chart_type = 'bar' - cell.data_reference = 'plop:second' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[1] - - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [([222, 134, 0, 53], {'title': ''})] - - # data in X/Y - cell.chart_type = 'bar' - cell.data_reference = 'plop:third' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[2] - - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # single data point - cell.chart_type = 'bar' - cell.data_reference = 'plop:fourth' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[3] - - chart = cell.get_chart() - assert chart.x_labels == [''] - assert chart.raw_series == [([222], {'title': ''})] - - # loop/X - cell.data_reference = 'plop:fifth' - cell.save() - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # loop/Y - cell.data_reference = 'plop:sixth' - cell.save() - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # loop/X/Y - cell.data_reference = 'plop:seventh' - cell.save() - with pytest.raises(UnsupportedDataSet): - chart = cell.get_chart() - - # duration - cell.data_reference = 'plop:eighth' - cell.save() - chart = cell.get_chart() - - # loop/X/Y - cell.data_reference = 'plop:nineth' - cell.save() - with pytest.raises(UnsupportedDataSet): - chart = cell.get_chart() - - # deleted visualization - cell.data_reference = 'plop:eleventh' - cell.save() - with pytest.raises(HTTPError): - chart = cell.get_chart() + cell = ChartNgCell(page=page, order=1) + cell.data_reference = 'plop:example' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[0] + + # bar + chart = cell.get_chart() + assert chart.__class__.__name__ == 'Bar' + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [([222, 134, 0, 53], {'title': ''})] + + # horizontal bar + cell.chart_type = 'horizontal-bar' + chart = cell.get_chart() + assert chart.__class__.__name__ == 'HorizontalBar' + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [([222, 134, 0, 53], {'title': ''})] + + # pie + cell.chart_type = 'pie' + chart = cell.get_chart() + assert chart.__class__.__name__ == 'Pie' + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222], {'title': u'web'}), + ([134], {'title': u'mail'}), + ([53], {'title': u'email'}) + ] + + # data in Y + cell.chart_type = 'bar' + cell.data_reference = 'plop:second' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[1] + + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [([222, 134, 0, 53], {'title': ''})] + + # data in X/Y + cell.chart_type = 'bar' + cell.data_reference = 'plop:third' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[2] + + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # single data point + cell.chart_type = 'bar' + cell.data_reference = 'plop:fourth' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[3] + + chart = cell.get_chart() + assert chart.x_labels == [''] + assert chart.raw_series == [([222], {'title': ''})] + + # loop/X + cell.data_reference = 'plop:fifth' + cell.save() + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # loop/Y + cell.data_reference = 'plop:sixth' + cell.save() + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # loop/X/Y + cell.data_reference = 'plop:seventh' + cell.save() + with pytest.raises(UnsupportedDataSet): + chart = cell.get_chart() + + # duration + cell.data_reference = 'plop:eighth' + cell.save() + chart = cell.get_chart() + + # loop/X/Y + cell.data_reference = 'plop:nineth' + cell.save() + with pytest.raises(UnsupportedDataSet): + chart = cell.get_chart() + + # deleted visualization + cell.data_reference = 'plop:eleventh' + cell.save() + with pytest.raises(HTTPError): + chart = cell.get_chart() +@with_httmock(bijoe_mock) def test_chartng_cell_hide_null_values(app): page = Page(title='One', slug='index') page.save() - with override_settings(KNOWN_SERVICES={ - 'bijoe': {'plop': {'title': 'test', 'url': 'https://bijoe.example.com', - 'secret': 'combo', 'orig': 'combo'}}}): - with HTTMock(bijoe_mock): - cell = ChartNgCell(page=page, order=1) - cell.data_reference = 'plop:example' - cell.hide_null_values = True - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[0] - - # bar - chart = cell.get_chart() - assert chart.__class__.__name__ == 'Bar' - assert chart.x_labels == ['web', 'mail', 'email'] - assert chart.raw_series == [([222, 134, 53], {'title': ''})] - - # horizontal bar - cell.chart_type = 'horizontal-bar' - chart = cell.get_chart() - assert chart.__class__.__name__ == 'HorizontalBar' - assert chart.x_labels == ['web', 'mail', 'email'] - assert chart.raw_series == [([222, 134, 53], {'title': ''})] - - # pie - cell.chart_type = 'pie' - chart = cell.get_chart() - assert chart.__class__.__name__ == 'Pie' - assert chart.x_labels == ['web', 'mail', 'email'] - assert chart.raw_series == [ - ([222], {'title': u'web'}), - ([134], {'title': u'mail'}), - ([53], {'title': u'email'}) - ] - - # data in Y - cell.chart_type = 'bar' - cell.data_reference = 'plop:second' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[1] - - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'email'] - assert chart.raw_series == [([222, 134, 53], {'title': ''})] - - # data in X/Y - cell.chart_type = 'bar' - cell.data_reference = 'plop:third' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[2] - - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # single data point - cell.chart_type = 'bar' - cell.data_reference = 'plop:fourth' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[3] - - chart = cell.get_chart() - assert chart.x_labels == [''] - assert chart.raw_series == [([222], {'title': ''})] - - # loop/X - cell.data_reference = 'plop:fifth' - cell.save() - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # loop/Y - cell.data_reference = 'plop:sixth' - cell.save() - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] + cell = ChartNgCell(page=page, order=1) + cell.data_reference = 'plop:example' + cell.hide_null_values = True + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[0] + + # bar + chart = cell.get_chart() + assert chart.__class__.__name__ == 'Bar' + assert chart.x_labels == ['web', 'mail', 'email'] + assert chart.raw_series == [([222, 134, 53], {'title': ''})] + + # horizontal bar + cell.chart_type = 'horizontal-bar' + chart = cell.get_chart() + assert chart.__class__.__name__ == 'HorizontalBar' + assert chart.x_labels == ['web', 'mail', 'email'] + assert chart.raw_series == [([222, 134, 53], {'title': ''})] + + # pie + cell.chart_type = 'pie' + chart = cell.get_chart() + assert chart.__class__.__name__ == 'Pie' + assert chart.x_labels == ['web', 'mail', 'email'] + assert chart.raw_series == [ + ([222], {'title': u'web'}), + ([134], {'title': u'mail'}), + ([53], {'title': u'email'}) + ] + + # data in Y + cell.chart_type = 'bar' + cell.data_reference = 'plop:second' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[1] + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'email'] + assert chart.raw_series == [([222, 134, 53], {'title': ''})] + # data in X/Y + cell.chart_type = 'bar' + cell.data_reference = 'plop:third' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[2] + + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # single data point + cell.chart_type = 'bar' + cell.data_reference = 'plop:fourth' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[3] + + chart = cell.get_chart() + assert chart.x_labels == [''] + assert chart.raw_series == [([222], {'title': ''})] + + # loop/X + cell.data_reference = 'plop:fifth' + cell.save() + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # loop/Y + cell.data_reference = 'plop:sixth' + cell.save() + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + +@with_httmock(bijoe_mock) def test_chartng_cell_sort_order_alpha(app): page = Page(title='One', slug='index') page.save() - with override_settings(KNOWN_SERVICES={ - 'bijoe': {'plop': {'title': 'test', 'url': 'https://bijoe.example.com', - 'secret': 'combo', 'orig': 'combo'}}}): - with HTTMock(bijoe_mock): - cell = ChartNgCell(page=page, order=1) - cell.data_reference = 'plop:example' - cell.sort_order = 'alpha' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[0] - - # bar - chart = cell.get_chart() - assert chart.__class__.__name__ == 'Bar' - assert chart.x_labels == ['email', 'mail', 'phone', 'web'] - assert chart.raw_series == [([53, 134, 0, 222], {'title': ''})] - - # horizontal bar - cell.chart_type = 'horizontal-bar' - chart = cell.get_chart() - assert chart.__class__.__name__ == 'HorizontalBar' - assert chart.x_labels == ['email', 'mail', 'phone', 'web'] - assert chart.raw_series == [([53, 134, 0, 222], {'title': ''})] - - # pie - cell.chart_type = 'pie' - chart = cell.get_chart() - assert chart.__class__.__name__ == 'Pie' - assert chart.x_labels == ['email', 'mail', 'phone', 'web'] - assert chart.raw_series == [ - ([53], {'title': u'email'}), - ([134], {'title': u'mail'}), - ([222], {'title': u'web'}) - ] - - # data in Y - cell.chart_type = 'bar' - cell.data_reference = 'plop:second' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[1] - - chart = cell.get_chart() - assert chart.x_labels == ['email', 'mail', 'phone', 'web'] - assert chart.raw_series == [([53, 134, 0, 222], {'title': ''})] - - # data in X/Y - cell.chart_type = 'bar' - cell.data_reference = 'plop:third' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[2] - - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # single data point - cell.chart_type = 'bar' - cell.data_reference = 'plop:fourth' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[3] - - chart = cell.get_chart() - assert chart.x_labels == [''] - assert chart.raw_series == [([222], {'title': ''})] - - # loop/X - cell.data_reference = 'plop:fifth' - cell.save() - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # loop/Y - cell.data_reference = 'plop:sixth' - cell.save() - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] + cell = ChartNgCell(page=page, order=1) + cell.data_reference = 'plop:example' + cell.sort_order = 'alpha' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[0] + + # bar + chart = cell.get_chart() + assert chart.__class__.__name__ == 'Bar' + assert chart.x_labels == ['email', 'mail', 'phone', 'web'] + assert chart.raw_series == [([53, 134, 0, 222], {'title': ''})] + + # horizontal bar + cell.chart_type = 'horizontal-bar' + chart = cell.get_chart() + assert chart.__class__.__name__ == 'HorizontalBar' + assert chart.x_labels == ['email', 'mail', 'phone', 'web'] + assert chart.raw_series == [([53, 134, 0, 222], {'title': ''})] + + # pie + cell.chart_type = 'pie' + chart = cell.get_chart() + assert chart.__class__.__name__ == 'Pie' + assert chart.x_labels == ['email', 'mail', 'phone', 'web'] + assert chart.raw_series == [ + ([53], {'title': u'email'}), + ([134], {'title': u'mail'}), + ([222], {'title': u'web'}) + ] + + # data in Y + cell.chart_type = 'bar' + cell.data_reference = 'plop:second' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[1] + + chart = cell.get_chart() + assert chart.x_labels == ['email', 'mail', 'phone', 'web'] + assert chart.raw_series == [([53, 134, 0, 222], {'title': ''})] + + # data in X/Y + cell.chart_type = 'bar' + cell.data_reference = 'plop:third' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[2] + + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # single data point + cell.chart_type = 'bar' + cell.data_reference = 'plop:fourth' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[3] + chart = cell.get_chart() + assert chart.x_labels == [''] + assert chart.raw_series == [([222], {'title': ''})] + # loop/X + cell.data_reference = 'plop:fifth' + cell.save() + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # loop/Y + cell.data_reference = 'plop:sixth' + cell.save() + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + +@with_httmock(bijoe_mock) def test_chartng_cell_sort_order_desc(app): page = Page(title='One', slug='index') page.save() - with override_settings(KNOWN_SERVICES={ - 'bijoe': {'plop': {'title': 'test', 'url': 'https://bijoe.example.com', - 'secret': 'combo', 'orig': 'combo'}}}): - with HTTMock(bijoe_mock): - cell = ChartNgCell(page=page, order=1) - cell.data_reference = 'plop:example' - cell.sort_order = 'desc' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[0] - - # bar - chart = cell.get_chart() - assert chart.__class__.__name__ == 'Bar' - assert chart.x_labels == ['web', 'mail', 'email', 'phone'] - assert chart.raw_series == [([222, 134, 53, 0], {'title': ''})] - - # horizontal bar - cell.chart_type = 'horizontal-bar' - chart = cell.get_chart() - assert chart.__class__.__name__ == 'HorizontalBar' - assert chart.x_labels == ['web', 'mail', 'email', 'phone'] - assert chart.raw_series == [([222, 134, 53, 0], {'title': ''})] - - # pie - cell.chart_type = 'pie' - chart = cell.get_chart() - assert chart.__class__.__name__ == 'Pie' - assert chart.x_labels == ['web', 'mail', 'email', 'phone'] - assert chart.raw_series == [ - ([222], {'title': u'web'}), - ([134], {'title': u'mail'}), - ([53], {'title': u'email'}) - ] - - # data in Y - cell.chart_type = 'bar' - cell.data_reference = 'plop:second' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[1] - - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'email', 'phone'] - assert chart.raw_series == [([222, 134, 53, 0], {'title': ''})] - - # data in X/Y - cell.chart_type = 'bar' - cell.data_reference = 'plop:third' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[2] - - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # single data point - cell.chart_type = 'bar' - cell.data_reference = 'plop:fourth' - cell.save() - assert cell.cached_json == VISUALIZATION_JSON[3] - - chart = cell.get_chart() - assert chart.x_labels == [''] - assert chart.raw_series == [([222], {'title': ''})] - - # loop/X - cell.data_reference = 'plop:fifth' - cell.save() - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] - - # loop/Y - cell.data_reference = 'plop:sixth' - cell.save() - chart = cell.get_chart() - assert chart.x_labels == ['web', 'mail', 'phone', 'email'] - assert chart.raw_series == [ - ([222, 134, 0, 53], {'title': u'foo'}), - ([122, 114, 2, 33], {'title': u'bar'}), - ] + cell = ChartNgCell(page=page, order=1) + cell.data_reference = 'plop:example' + cell.sort_order = 'desc' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[0] + + # bar + chart = cell.get_chart() + assert chart.__class__.__name__ == 'Bar' + assert chart.x_labels == ['web', 'mail', 'email', 'phone'] + assert chart.raw_series == [([222, 134, 53, 0], {'title': ''})] + + # horizontal bar + cell.chart_type = 'horizontal-bar' + chart = cell.get_chart() + assert chart.__class__.__name__ == 'HorizontalBar' + assert chart.x_labels == ['web', 'mail', 'email', 'phone'] + assert chart.raw_series == [([222, 134, 53, 0], {'title': ''})] + + # pie + cell.chart_type = 'pie' + chart = cell.get_chart() + assert chart.__class__.__name__ == 'Pie' + assert chart.x_labels == ['web', 'mail', 'email', 'phone'] + assert chart.raw_series == [ + ([222], {'title': u'web'}), + ([134], {'title': u'mail'}), + ([53], {'title': u'email'}) + ] + + # data in Y + cell.chart_type = 'bar' + cell.data_reference = 'plop:second' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[1] + + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'email', 'phone'] + assert chart.raw_series == [([222, 134, 53, 0], {'title': ''})] + + # data in X/Y + cell.chart_type = 'bar' + cell.data_reference = 'plop:third' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[2] + + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # single data point + cell.chart_type = 'bar' + cell.data_reference = 'plop:fourth' + cell.save() + assert cell.cached_json == VISUALIZATION_JSON[3] + + chart = cell.get_chart() + assert chart.x_labels == [''] + assert chart.raw_series == [([222], {'title': ''})] + + # loop/X + cell.data_reference = 'plop:fifth' + cell.save() + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] + + # loop/Y + cell.data_reference = 'plop:sixth' + cell.save() + chart = cell.get_chart() + assert chart.x_labels == ['web', 'mail', 'phone', 'email'] + assert chart.raw_series == [ + ([222, 134, 0, 53], {'title': u'foo'}), + ([122, 114, 2, 33], {'title': u'bar'}), + ] +@with_httmock(bijoe_mock) def test_chartng_cell_view(app, normal_user): page = Page(title='One', slug='index') page.save() - with override_settings(KNOWN_SERVICES={ - 'bijoe': {'plop': {'title': 'test', 'url': 'https://bijoe.example.com', - 'secret': 'combo', 'orig': 'combo'}}}): - with HTTMock(bijoe_mock): - cell = ChartNgCell(page=page, order=1, placeholder='content') - cell.data_reference = 'plop:example' - cell.save() - location = '/api/dataviz/graph/%s/' % cell.id - resp = app.get(location) # get data in cache - resp = app.get('/') - assert 'min-height: 250px' in resp.text - assert location in resp.text - - resp = app.get(location + '?width=400') - assert resp.content_type == 'image/svg+xml' - - resp = app.get(location + '?width=') # no crash - assert resp.content_type == 'image/svg+xml' - - page.public = False - page.save() - resp = app.get(location + '?width=400', status=403) - - page.public = True - page.save() - group = Group(name='plop') - group.save() - cell.public = False - cell.groups.set([group]) - cell.save() - resp = app.get(location + '?width=400', status=403) - - app = login(app, username='normal-user', password='normal-user') - resp = app.get(location + '?width=400', status=403) - - normal_user.groups.set([group]) - normal_user.save() - resp = app.get(location + '?width=400', status=200) - - # table visualization - cell.chart_type = 'table' - cell.save() - resp = app.get('/') - assert '222' in resp.text + cell = ChartNgCell(page=page, order=1, placeholder='content') + cell.data_reference = 'plop:example' + cell.save() + location = '/api/dataviz/graph/%s/' % cell.id + resp = app.get(location) # get data in cache + resp = app.get('/') + assert 'min-height: 250px' in resp.text + assert location in resp.text - # unsupported dataset - cell.data_reference = 'plop:seventh' - cell.save() - resp = app.get(location) # get data in cache - resp = app.get('/') - assert 'Unsupported dataset' in resp.text - - cell.chart_type = 'bar' - cell.save() - resp = app.get(location + '?width=400', status=200) - assert 'Unsupported dataset' in resp.text - - # durations - cell.data_reference = 'plop:eighth' - cell.chart_type = 'table' - cell.save() - resp = app.get(location) # get data in cache - resp = app.get('/') - assert 'Less than an hour' in resp.text - assert '1 day and 10 hours' in resp.text - assert '2 hours' in resp.text - assert '1 day' in resp.text - - cell.chart_type = 'bar' - cell.save() - resp = app.get(location + '?width=400', status=200) - assert '>Less than an hour<' in resp.text - assert '>1 day and 10 hours<' in resp.text - assert '>2 hours<' in resp.text - assert '>1 day<' in resp.text - - # percents - cell.data_reference = 'plop:tenth' - cell.chart_type = 'table' - cell.save() - resp = app.get(location) # get data in cache - resp = app.get('/') - assert '10.0%' in resp.text - - cell.chart_type = 'bar' - cell.save() - resp = app.get(location + '?width=400', status=200) - assert '>10.0%<' in resp.text - - # deleted visualization - cell.data_reference = 'plop:eleventh' - cell.save() - resp = app.get(location) - assert 'not found' in resp.text - - # cell with missing cached_json (probably after import and missing - # bijoe visualisation) - cell.chart_type = 'table' - cell.save() - ChartNgCell.objects.filter(id=cell.id).update(cached_json={}) - resp = app.get('/') - assert 'warningnotice' in resp.text + resp = app.get(location + '?width=400') + assert resp.content_type == 'image/svg+xml' + + resp = app.get(location + '?width=') # no crash + assert resp.content_type == 'image/svg+xml' + + page.public = False + page.save() + resp = app.get(location + '?width=400', status=403) + + page.public = True + page.save() + group = Group(name='plop') + group.save() + cell.public = False + cell.groups.set([group]) + cell.save() + resp = app.get(location + '?width=400', status=403) + + app = login(app, username='normal-user', password='normal-user') + resp = app.get(location + '?width=400', status=403) + + normal_user.groups.set([group]) + normal_user.save() + resp = app.get(location + '?width=400', status=200) + # table visualization + cell.chart_type = 'table' + cell.save() + resp = app.get('/') + assert '222' in resp.text + + # unsupported dataset + cell.data_reference = 'plop:seventh' + cell.save() + resp = app.get(location) # get data in cache + resp = app.get('/') + assert 'Unsupported dataset' in resp.text + cell.chart_type = 'bar' + cell.save() + resp = app.get(location + '?width=400', status=200) + assert 'Unsupported dataset' in resp.text + + # durations + cell.data_reference = 'plop:eighth' + cell.chart_type = 'table' + cell.save() + resp = app.get(location) # get data in cache + resp = app.get('/') + assert 'Less than an hour' in resp.text + assert '1 day and 10 hours' in resp.text + assert '2 hours' in resp.text + assert '1 day' in resp.text + + cell.chart_type = 'bar' + cell.save() + resp = app.get(location + '?width=400', status=200) + assert '>Less than an hour<' in resp.text + assert '>1 day and 10 hours<' in resp.text + assert '>2 hours<' in resp.text + assert '>1 day<' in resp.text + + # percents + cell.data_reference = 'plop:tenth' + cell.chart_type = 'table' + cell.save() + resp = app.get(location) # get data in cache + resp = app.get('/') + assert '10.0%' in resp.text + + cell.chart_type = 'bar' + cell.save() + resp = app.get(location + '?width=400', status=200) + assert '>10.0%<' in resp.text + + # deleted visualization + cell.data_reference = 'plop:eleventh' + cell.save() + resp = app.get(location) + assert 'not found' in resp.text + + # cell with missing cached_json (probably after import and missing + # bijoe visualisation) + cell.chart_type = 'table' + cell.save() + ChartNgCell.objects.filter(id=cell.id).update(cached_json={}) + resp = app.get('/') + assert 'warningnotice' in resp.text + + +@with_httmock(bijoe_mock) def test_chartng_cell_manager(app, admin_user): page = Page(title='One', slug='index') page.save() app = login(app) - with override_settings(KNOWN_SERVICES={ - 'bijoe': {'plop': {'title': 'test', 'url': 'https://bijoe.example.com', - 'secret': 'combo', 'orig': 'combo'}}}): - with HTTMock(bijoe_mock): - cell = ChartNgCell(page=page, order=1, placeholder='content') - cell.data_reference = 'plop:example' - cell.save() - resp = app.get('/manage/pages/%s/' % page.id) - assert resp.form['cdataviz_chartngcell-%s-data_reference' % cell.id].options == [ - (u'plop:eighth', False, u'eighth visualization (duration)'), - (u'plop:eleventh', False, u'eleventh visualization (not found)'), - (u'plop:example', True, u'example visualization (X)'), - (u'plop:fifth', False, u'fifth visualization (loop/X)'), - (u'plop:fourth', False, u'fourth visualization (no axis)'), - (u'plop:nineth', False, u'nineth visualization (loop over varying dimensions)'), - (u'plop:second', False, u'second visualization (Y)'), - (u'plop:seventh', False, u'seventh visualization (loop/X/Y)'), - (u'plop:sixth', False, u'sixth visualization (loop/Y)'), - (u'plop:tenth', False, u'tenth visualization (percents)'), - (u'plop:third', False, u'third visualization (X/Y)'), - ] - - + cell = ChartNgCell(page=page, order=1, placeholder='content') + cell.data_reference = 'plop:example' + cell.save() + resp = app.get('/manage/pages/%s/' % page.id) + assert resp.form['cdataviz_chartngcell-%s-data_reference' % cell.id].options == [ + (u'plop:eighth', False, u'eighth visualization (duration)'), + (u'plop:eleventh', False, u'eleventh visualization (not found)'), + (u'plop:example', True, u'example visualization (X)'), + (u'plop:fifth', False, u'fifth visualization (loop/X)'), + (u'plop:fourth', False, u'fourth visualization (no axis)'), + (u'plop:nineth', False, u'nineth visualization (loop over varying dimensions)'), + (u'plop:second', False, u'second visualization (Y)'), + (u'plop:seventh', False, u'seventh visualization (loop/X/Y)'), + (u'plop:sixth', False, u'sixth visualization (loop/Y)'), + (u'plop:tenth', False, u'tenth visualization (percents)'), + (u'plop:third', False, u'third visualization (X/Y)'), + ] + + +@with_httmock(bijoe_mock) def test_table_cell(app, admin_user): page = Page(title='One', slug='index') page.save() app = login(app) - with override_settings(KNOWN_SERVICES={ - 'bijoe': {'plop': {'title': 'test', 'url': 'https://bijoe.example.com', - 'secret': 'combo', 'orig': 'combo'}}}): - with HTTMock(bijoe_mock): - cell = ChartNgCell(page=page, order=1, placeholder='content') - cell.data_reference = 'plop:example' - cell.chart_type = 'table' - cell.save() - location = '/api/dataviz/graph/%s/' % cell.id - resp = app.get(location) - resp = app.get('/') - assert resp.text.count('Total') == 1 + cell = ChartNgCell(page=page, order=1, placeholder='content') + cell.data_reference = 'plop:example' + cell.chart_type = 'table' + cell.save() + location = '/api/dataviz/graph/%s/' % cell.id + resp = app.get(location) + resp = app.get('/') + assert resp.text.count('Total') == 1 - cell.data_reference = 'plop:second' - cell.save() - resp = app.get(location) - resp = app.get('/') - assert resp.text.count('Total') == 1 + cell.data_reference = 'plop:second' + cell.save() + resp = app.get(location) + resp = app.get('/') + assert resp.text.count('Total') == 1 - cell.data_reference = 'plop:third' - cell.save() - resp = app.get(location) - resp = app.get('/') - assert '114' in resp.text - assert resp.text.count('Total') == 2 + cell.data_reference = 'plop:third' + cell.save() + resp = app.get(location) + resp = app.get('/') + assert '114' in resp.text + assert resp.text.count('Total') == 2 - cell.data_reference = 'plop:fourth' - cell.save() - resp = app.get(location) - resp = app.get('/') - assert resp.text.count('Total') == 0 + cell.data_reference = 'plop:fourth' + cell.save() + resp = app.get(location) + resp = app.get('/') + assert resp.text.count('Total') == 0 - # total of durations is not computed - cell.data_reference = 'plop:eigth' - cell.save() - resp = app.get(location) - resp = app.get('/') - assert resp.text.count('Total') == 0 + # total of durations is not computed + cell.data_reference = 'plop:eigth' + cell.save() + resp = app.get(location) + resp = app.get('/') + assert resp.text.count('Total') == 0 -- 2.20.1