Skip to content

Commit 334f6d4

Browse files
committed
Fix unittests
1 parent 094d58b commit 334f6d4

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

tests/test_context_processors.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ def func(request):
1616

1717
app = web.Application(loop=loop, middlewares=[
1818
aiohttp_jinja2.context_processors_middleware])
19-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
20-
{'tmpl.jinja2':
21-
'foo: {{ foo }}, bar: {{ bar }}, path: {{ request.path }}'}))
19+
aiohttp_jinja2.setup(
20+
app,
21+
loader=jinja2.DictLoader({
22+
'tmpl.jinja2': ("foo: {{ foo }}, bar: {{ bar }}, "
23+
"path: {{ request.path }}")
24+
}),
25+
enable_async=False,
26+
)
2227

2328
app['aiohttp_jinja2_context_processors'] = (
2429
aiohttp_jinja2.request_processor,
2530
asyncio.coroutine(
26-
lambda request: {'foo': 1, 'bar': 'should be overwriten'}),
31+
lambda request: {'foo': 1, 'bar': 'should be overwritten'}),
2732
)
2833

2934
app.router.add_get('/', func)
@@ -37,15 +42,13 @@ def func(request):
3742

3843

3944
@asyncio.coroutine
40-
def test_context_is_response(test_client, loop):
45+
def test_context_is_response(app_with_template, test_client):
4146

4247
@aiohttp_jinja2.template('tmpl.jinja2')
4348
def func(request):
4449
return web.HTTPForbidden()
4550

46-
app = web.Application(loop=loop)
47-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
48-
{'tmpl.jinja2': "template"}))
51+
app = app_with_template("tmpl")
4952

5053
app.router.add_route('GET', '/', func)
5154
client = yield from test_client(app)
@@ -63,18 +66,18 @@ def test_context_processors_new_setup_style(test_client, loop):
6366
def func(request):
6467
return {'bar': 2}
6568

69+
template = "foo: {{ foo }}, bar: {{ bar }}, path: {{ request.path }}"
70+
ctx_coro = asyncio.coroutine(
71+
lambda request: {'foo': 1, 'bar': 'should be overwritten'})
6672
app = web.Application(loop=loop)
6773
aiohttp_jinja2.setup(
6874
app,
69-
loader=jinja2.DictLoader(
70-
{'tmpl.jinja2':
71-
'foo: {{ foo }}, bar: {{ bar }}, '
72-
'path: {{ request.path }}'}),
73-
context_processors=(aiohttp_jinja2.request_processor,
74-
asyncio.coroutine(
75-
lambda request: {
76-
'foo': 1,
77-
'bar': 'should be overwriten'})))
75+
loader=jinja2.DictLoader({
76+
'tmpl.jinja2': template
77+
}),
78+
context_processors=(aiohttp_jinja2.request_processor, ctx_coro),
79+
enable_async=False,
80+
)
7881

7982
app.router.add_route('GET', '/', func)
8083
client = yield from test_client(app)
@@ -96,11 +99,13 @@ def func(request):
9699
return global_context
97100

98101
app = web.Application(loop=loop)
102+
ctx_coro = asyncio.coroutine(lambda request: {'foo': 1})
99103
aiohttp_jinja2.setup(
100104
app,
101105
loader=jinja2.DictLoader({'tmpl.jinja2': 'foo: {{ foo }}'}),
102-
context_processors=[asyncio.coroutine(
103-
lambda request: {'foo': 1})])
106+
context_processors=[ctx_coro],
107+
enable_async=False,
108+
)
104109

105110
app.router.add_get('/', func)
106111
client = yield from test_client(app)

0 commit comments

Comments
 (0)