Skip to content

Commit cffe053

Browse files
committed
Add app with template fixture
1 parent 7e0bf0c commit cffe053

File tree

4 files changed

+63
-22
lines changed

4 files changed

+63
-22
lines changed

tests/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
import jinja2
3+
import aiohttp_jinja2
4+
from aiohttp import web
5+
6+
7+
@pytest.fixture()
8+
def app_with_template(loop):
9+
def aiohttp_app(template):
10+
app = web.Application(loop=loop)
11+
aiohttp_jinja2.setup(
12+
app,
13+
loader=jinja2.DictLoader({
14+
'tmpl.jinja2': template
15+
}),
16+
enable_async=False,
17+
)
18+
return app
19+
20+
return aiohttp_app

tests/test_jinja_filters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def add_2(value):
2121
aiohttp_jinja2.setup(
2222
app,
2323
loader=jinja2.DictLoader({'tmpl.jinja2': "{{ 5|add_2 }}"}),
24-
filters={'add_2': add_2}
24+
filters={'add_2': add_2},
25+
enable_async=False,
2526
)
2627

2728
app.router.add_route('GET', '/', index)

tests/test_jinja_globals.py

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
def test_get_env(loop):
1010
app = web.Application(loop=loop)
11-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
12-
{'tmpl.jinja2': "tmpl"}))
11+
aiohttp_jinja2.setup(
12+
app,
13+
loader=jinja2.DictLoader({
14+
'tmpl.jinja2': "tmpl"
15+
}),
16+
enable_async=False,
17+
)
1318

1419
env = aiohttp_jinja2.get_env(app)
1520
assert isinstance(env, jinja2.Environment)
@@ -29,9 +34,13 @@ def other(request):
2934
return
3035

3136
app = web.Application(loop=loop)
32-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
33-
{'tmpl.jinja2':
34-
"{{ url('other', name='John_Doe')}}"}))
37+
aiohttp_jinja2.setup(
38+
app,
39+
loader=jinja2.DictLoader({
40+
'tmpl.jinja2': "{{ url('other', name='John_Doe')}}"
41+
}),
42+
enable_async=False,
43+
)
3544

3645
app.router.add_route('GET', '/', index)
3746
app.router.add_route('GET', '/user/{name}', other, name='other')
@@ -52,9 +61,13 @@ def index(request):
5261
return {}
5362

5463
app = web.Application(loop=loop)
55-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
56-
{'tmpl.jinja2':
57-
"{{ url('index', query_={'foo': 'bar'})}}"}))
64+
aiohttp_jinja2.setup(
65+
app,
66+
loader=jinja2.DictLoader({
67+
'tmpl.jinja2': "{{ url('index', query_={'foo': 'bar'})}}"
68+
}),
69+
enable_async=False,
70+
)
5871

5972
app.router.add_get('/', index, name='index')
6073
client = yield from test_client(app)
@@ -81,8 +94,10 @@ def other(request):
8194
aiohttp_jinja2.setup(
8295
app,
8396
default_helpers=False,
84-
loader=jinja2.DictLoader(
85-
{'tmpl.jinja2': "{{ url('index')}}"})
97+
loader=jinja2.DictLoader({
98+
'tmpl.jinja2': "{{ url('index')}}"
99+
}),
100+
enable_async=False,
86101
)
87102

88103
app.router.add_route('GET', '/', index)
@@ -102,9 +117,13 @@ def index(request):
102117
return {}
103118

104119
app = web.Application(loop=loop)
105-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
106-
{'tmpl.jinja2':
107-
"{{ static('whatever.js') }}"}))
120+
aiohttp_jinja2.setup(
121+
app,
122+
loader=jinja2.DictLoader({
123+
'tmpl.jinja2': "{{ static('whatever.js') }}"
124+
}),
125+
enable_async=False,
126+
)
108127

109128
app['static_root_url'] = '/static'
110129
app.router.add_route('GET', '/', index)
@@ -125,9 +144,13 @@ def index(request):
125144
return {}
126145

127146
app = web.Application(loop=loop)
128-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
129-
{'tmpl.jinja2':
130-
"{{ static('whatever.js') }}"}))
147+
aiohttp_jinja2.setup(
148+
app,
149+
loader=jinja2.DictLoader({
150+
'tmpl.jinja2': "{{ static('whatever.js') }}"
151+
}),
152+
enable_async=False,
153+
)
131154

132155
app.router.add_route('GET', '/', index)
133156
client = yield from test_client(app)

tests/test_simple_renderer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99

1010

1111
@asyncio.coroutine
12-
def test_func(loop, test_client):
12+
def test_func(app_with_template, test_client):
1313

1414
@aiohttp_jinja2.template('tmpl.jinja2')
1515
@asyncio.coroutine
1616
def func(request):
1717
return {'head': 'HEAD', 'text': 'text'}
1818

1919
template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'
20-
app = web.Application(loop=loop)
21-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
22-
'tmpl.jinja2': template
23-
}))
20+
app = app_with_template(template)
2421

2522
app.router.add_route('*', '/', func)
2623

0 commit comments

Comments
 (0)