bijoe/tests/test_views.py

68 lines
2.3 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)
def test_visualizations_json_api(schema1, app, admin):
Visualization(name='test', parameters={}).save()
Visualization(name='test', parameters={}).save()
Visualization(name='test', parameters={}).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'
}