Completed
Push — master ( e542da...d38e8d )
by Chris
01:08
created

test_metadata_bad()   A

Complexity

Conditions 3

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
import json
2
from datetime import datetime as dt
3
4
from flask import Flask, current_app
5
import pytest
6
7
from flask_jsondash import charts_builder
8
9
10
app = Flask('test_flask_jsondash')
11
app.debug = True
12
app.register_blueprint(charts_builder.charts)
13
14
15
def _username():
16
    return 'Username'
17
18
19
def _authtest():
20
    return False
21
22
23
@pytest.fixture(scope='module')
24
def client():
25
    app.config.update(
26
        JSONDASH_GLOBALDASH=False,
27
        JSONDASH_FILTERUSERS=False,
28
        JSONDASH_GLOBAL_USER='global-test',
29
    )
30
    app.config['JSONDASH'] = dict(
31
        metadata=dict(
32
            created_by=_username,
33
            username=_username,
34
        ),
35
        static=dict(
36
            js_path='js/vendor/',
37
            css_path='css/vendor/',
38
        ),
39
        auth=dict(
40
            edit_global=_authtest,
41
            clone=_authtest,
42
            delete=_authtest,
43
        )
44
    )
45
    return app.test_client()
46
47
48
def test_no_config_sanity_test(client):
49
    assert app.config.get('JSONDASH_GLOBALDASH') == False
50
    assert app.config.get('JSONDASH_FILTERUSERS') == False
51
    assert app.config.get('JSONDASH_GLOBAL_USER') == 'global-test'
52
53
54
def test_setting(client):
55
    with app.app_context():
56
        _get = charts_builder.setting
57
        assert _get('JSONDASH_GLOBALDASH') == False
58
        assert _get('JSONDASH_FILTERUSERS') == False
59
        assert _get('JSONDASH_GLOBAL_USER') == 'global-test'
60
61
62
def test_metadata(client):
63
    with app.app_context():
64
        assert charts_builder.metadata(key='created_by') == 'Username'
65
        assert charts_builder.metadata(key='username') == 'Username'
66
67
68
def test_metadata_bad(client):
69
    with app.app_context():
70
        assert charts_builder.metadata(key='foo') is None
71
72
73
def test_app_redirect(client):
74
    resp = client.get('/charts')
75
    assert 'You should be redirected automatically' in resp.data
76