Skip to content

Commit

Permalink
Fix typo, add more tests coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
christabor committed Dec 31, 2016
1 parent 3171952 commit 9051289
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flask_jsondash/templates/pages/charts_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1 class="lead">Showing <strong>{{ "{:,}".format(views|length) }}</strong> {{ '
{% if filter_dashboards and username %}
Only showing <strong>your</strong> dashboards ({{ username }})
{% if global_dashboards %}
and all <strong>global</strong> dashoards
and all <strong>global</strong> dashboards
{% endif %}
{% else %}
Not filtering any dashboards.
Expand Down
28 changes: 27 additions & 1 deletion tests/test_charts_builder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from flask import url_for

from pyquery import PyQuery as pq
Expand Down Expand Up @@ -268,7 +270,7 @@ def test_delete_valid(monkeypatch, ctx, client):
assert len(read()) == 0


def test_update_invalid_config(monkeypatch, ctx, client):
def test_update_edit_raw_invalid(monkeypatch, ctx, client):
app, test = client
monkeypatch.setattr(charts_builder, 'auth', auth_valid)
view = get_json_config('inputs.json')
Expand All @@ -282,6 +284,30 @@ def test_update_invalid_config(monkeypatch, ctx, client):
assert dom.find('.alert-danger').text() == 'Error: Invalid JSON config.'


def test_update_edit_raw_valid(monkeypatch, ctx, client):
app, test = client
monkeypatch.setattr(charts_builder, 'auth', auth_valid)
assert not read()
res = test.post(
url_for('jsondash.create'),
data=dict(name='newname', modules=[]),
follow_redirects=True)
assert len(read()) == 1
view_id = read()[0]['id']
data = {'name': 'foo', 'modules': []}
view = json.dumps(data)
readfunc = read(override=dict(data))
monkeypatch.setattr(charts_builder.adapter, 'read', readfunc)
res = test.post(
url_for('jsondash.update', c_id=view_id),
data={'config': view, 'edit-raw': 'on'},
follow_redirects=True)
dom = pq(res.data)
flash_msg = 'Updated view "{}"'.format(view_id)
assert dom.find('.alert-info').text() == flash_msg
assert len(read()) == 1


def test_update_valid(monkeypatch, ctx, client):
app, test = client
monkeypatch.setattr(charts_builder, 'auth', auth_valid)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_global_flags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from pyquery import PyQuery as pq

from flask_jsondash import charts_builder

from conftest import (
Expand Down Expand Up @@ -63,3 +65,21 @@ def test_is_global_dashboard_false(ctx, client):
is_global = charts_builder.is_global_dashboard
assert not is_global(dict(created_by='foo'))
assert not is_global(dict(created_by='Username'))


@pytest.mark.globalflag
def test_dashboard_filter_users_and_all_global(ctx, client, monkeypatch):
app, test = client
app.config['JSONDASH_FILTERUSERS'] = True
app.config['JSONDASH_GLOBALDASH'] = True
assert charts_builder.setting('JSONDASH_FILTERUSERS')
assert charts_builder.setting('JSONDASH_GLOBALDASH')
monkeypatch.setattr(charts_builder, 'auth', auth_valid)
data = dict(name='global-check')
test.post('/charts/create', data=data).data
res = test.get('/charts', follow_redirects=True).data
dom = pq(res)
text = dom.find('p > small').text()
assert 'Only showing' in text
assert 'and all global dashboards' in text
assert 'Not filtering any dashboards.' not in text

0 comments on commit 9051289

Please sign in to comment.