113 lines
3.9 KiB
Python
113 lines
3.9 KiB
Python
# bijoe - BI dashboard
|
|
# Copyright (C) 2015 Entr'ouvert
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from bijoe.visualization.models import Visualization
|
|
|
|
from utils import login
|
|
|
|
|
|
def test_simple_user_403(app, john_doe):
|
|
login(app, john_doe)
|
|
app.get('/', status=403)
|
|
app.get('/manage/menu.json', status=403)
|
|
|
|
|
|
def test_superuser(app, admin):
|
|
login(app, admin)
|
|
resp = app.get('/manage/menu.json', status=200)
|
|
assert len(resp.json) == 1
|
|
assert resp.json[0]['slug'] == 'statistics'
|
|
app.get('/', status=200)
|
|
app.get('/visualization/', status=200)
|
|
|
|
|
|
def test_visualizations_json_api(schema1, app, admin):
|
|
Visualization(name='test', parameters={'warehouse': 'schema1', 'cube': 'test'}).save()
|
|
Visualization(name='test', parameters={'warehouse': 'schema1', 'cube': 'test'}).save()
|
|
Visualization(name='test', parameters={'warehouse': 'schema1', 'cube': 'test'}).save()
|
|
login(app, admin)
|
|
resp = app.get(reverse('visualizations-json'))
|
|
assert set([x['slug'] for x in resp.json]) == set(['test', 'test-2', 'test-3'])
|
|
|
|
|
|
def test_visualization_json_api(schema1, app, admin):
|
|
visualization = Visualization(
|
|
name='test',
|
|
parameters={
|
|
'cube': 'facts1',
|
|
'warehouse': 'schema1',
|
|
'measure': 'simple_count',
|
|
'representation': 'table',
|
|
'loop': '',
|
|
'filters': {},
|
|
'drilldown_x': 'date__yearmonth'})
|
|
visualization.save()
|
|
|
|
login(app, admin)
|
|
resp = app.get(reverse('visualization-json', kwargs={'pk': visualization.id}))
|
|
# values from test_schem1/test_yearmonth_drilldown
|
|
assert resp.json == {
|
|
'axis': {'x_labels': ['01/2017', '02/2017', '03/2017', '04/2017', '05/2017', '06/2017', '07/2017', '08/2017']},
|
|
'data': [10, 1, 1, 1, 1, 1, 1, 1],
|
|
'format': '1',
|
|
'unit': None,
|
|
'measure': 'integer',
|
|
}
|
|
|
|
|
|
def test_visualization_json_api_duration(schema1, app, admin):
|
|
visualization = Visualization(
|
|
name='test',
|
|
parameters={
|
|
'cube': 'facts1',
|
|
'warehouse': 'schema1',
|
|
'measure': 'duration',
|
|
'representation': 'table',
|
|
'loop': '',
|
|
'filters': {},
|
|
'drilldown_x': 'date__yearmonth'})
|
|
visualization.save()
|
|
|
|
login(app, admin)
|
|
resp = app.get(reverse('visualization-json', kwargs={'pk': visualization.id}))
|
|
# values from test_schem1/test_yearmonth_drilldown
|
|
assert resp.json == {
|
|
'axis': {'x_labels': ['01/2017', '02/2017', '03/2017', '04/2017', '05/2017', '06/2017', '07/2017', '08/2017']},
|
|
'data': [536968800.0, 539258400.0, 541677600.0, 544352400.0, 546944400.0, 549622800.0, 552214800.0, 554893200.0],
|
|
'format': '1',
|
|
'unit': 'seconds',
|
|
'measure': 'duration',
|
|
}
|
|
|
|
|
|
def test_missing_data(schema1, app, admin):
|
|
visualization = Visualization(
|
|
name='test',
|
|
parameters={
|
|
'cube': 'missing_cube',
|
|
'warehouse': 'schema1',
|
|
'measure': 'duration',
|
|
'representation': 'table',
|
|
'loop': '',
|
|
'filters': {}})
|
|
visualization.save()
|
|
login(app, admin)
|
|
|
|
response = app.get('/')
|
|
assert response.pyquery('ul li a.disabled').text() == visualization.name
|