1
|
|
|
"""Test configuration utilities.""" |
2
|
|
|
|
3
|
|
|
from flask import Flask |
4
|
|
|
|
5
|
|
|
from flask_extras.filters import config |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class TestGetFuncs: |
9
|
|
|
"""All tests for get funcs function.""" |
10
|
|
|
|
11
|
|
|
def test_get_module_funcs(self, client): |
12
|
|
|
"""Test the return value.""" |
13
|
|
|
assert isinstance(config._get_funcs(config), dict) |
14
|
|
|
|
15
|
|
|
def test_get_module_funcs_notempty(self, client): |
16
|
|
|
"""Test the return value functions length.""" |
17
|
|
|
assert len(config._get_funcs(config).items()) > 0 |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class TestInjectFilters: |
21
|
|
|
"""All tests for inject filters function.""" |
22
|
|
|
|
23
|
|
|
def test_inject_filters_inst(self, client): |
24
|
|
|
"""Test the return value.""" |
25
|
|
|
app, test = client |
26
|
|
|
assert isinstance(config._inject_filters(app, {}), Flask) |
27
|
|
|
|
28
|
|
|
def test_inject_filters_count(self, client): |
29
|
|
|
"""Test the return value.""" |
30
|
|
|
app, test = client |
31
|
|
|
old = len(app.jinja_env.filters) |
32
|
|
|
config._inject_filters(app, {'foo': lambda x: x}) |
33
|
|
|
new = len(app.jinja_env.filters) |
34
|
|
|
assert new > old |
35
|
|
|
assert 'foo' in app.jinja_env.filters |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
class TestConfigFlaskFilters: |
39
|
|
|
"""All tests for config flask filters function.""" |
40
|
|
|
|
41
|
|
|
def test_config_filters_inst(self, client): |
42
|
|
|
"""Test the return value.""" |
43
|
|
|
app, test = client |
44
|
|
|
assert isinstance(config.config_flask_filters(app), Flask) |
45
|
|
|
|
46
|
|
|
def test_config_filters_count(self, client): |
47
|
|
|
"""Test the return value.""" |
48
|
|
|
app, test = client |
49
|
|
|
del app.jinja_env.filters |
50
|
|
|
setattr(app.jinja_env, 'filters', dict()) |
51
|
|
|
old = len(app.jinja_env.filters) |
52
|
|
|
config.config_flask_filters(app) |
53
|
|
|
new = len(app.jinja_env.filters) |
54
|
|
|
assert new > old |
55
|
|
|
|