Skip to content

Commit 094d58b

Browse files
committed
Update simple renderer with test fixture
1 parent 9da1191 commit 094d58b

File tree

1 file changed

+16
-45
lines changed

1 file changed

+16
-45
lines changed

tests/test_simple_renderer.py

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def func(request):
3030

3131

3232
@asyncio.coroutine
33-
def test_render_class_based_view(loop, test_client):
33+
def test_render_class_based_view(app_with_template, test_client):
3434
class MyView(web.View):
3535
@aiohttp_jinja2.template('tmpl.jinja2')
3636
@asyncio.coroutine
@@ -39,11 +39,7 @@ def get(self):
3939

4040
template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'
4141

42-
app = web.Application(loop=loop)
43-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
44-
'tmpl.jinja2': template
45-
}))
46-
42+
app = app_with_template(template)
4743
app.router.add_route('*', '/', MyView)
4844

4945
client = yield from test_client(app)
@@ -56,7 +52,7 @@ def get(self):
5652

5753

5854
@asyncio.coroutine
59-
def test_meth(loop, test_client):
55+
def test_meth(app_with_template, test_client):
6056

6157
class Handler:
6258

@@ -69,11 +65,7 @@ def meth(self, request):
6965

7066
handler = Handler()
7167

72-
app = web.Application(loop=loop)
73-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
74-
'tmpl.jinja2': template
75-
}))
76-
68+
app = app_with_template(template)
7769
app.router.add_route('*', '/', handler.meth)
7870

7971
client = yield from test_client(app)
@@ -86,19 +78,15 @@ def meth(self, request):
8678

8779

8880
@asyncio.coroutine
89-
def test_convert_func_to_coroutine(loop, test_client):
81+
def test_convert_func_to_coroutine(app_with_template, test_client):
9082

9183
@aiohttp_jinja2.template('tmpl.jinja2')
9284
def func(request):
9385
return {'head': 'HEAD', 'text': 'text'}
9486

9587
template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'
9688

97-
app = web.Application(loop=loop)
98-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
99-
'tmpl.jinja2': template
100-
}))
101-
89+
app = app_with_template(template)
10290
app.router.add_route('*', '/', func)
10391

10492
client = yield from test_client(app)
@@ -132,19 +120,15 @@ def func(request):
132120

133121

134122
@asyncio.coroutine
135-
def test_set_status(loop, test_client):
123+
def test_set_status(app_with_template, test_client):
136124

137125
@aiohttp_jinja2.template('tmpl.jinja2', status=201)
138126
def func(request):
139127
return {'head': 'HEAD', 'text': 'text'}
140128

141129
template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'
142130

143-
app = web.Application(loop=loop)
144-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
145-
'tmpl.jinja2': template
146-
}))
147-
131+
app = app_with_template(template)
148132
app.router.add_route('*', '/', func)
149133

150134
client = yield from test_client(app)
@@ -157,7 +141,7 @@ def func(request):
157141

158142

159143
@asyncio.coroutine
160-
def test_render_template(loop, test_client):
144+
def test_render_template(app_with_template, test_client):
161145

162146
@asyncio.coroutine
163147
def func(request):
@@ -167,11 +151,7 @@ def func(request):
167151

168152
template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'
169153

170-
app = web.Application(loop=loop)
171-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
172-
'tmpl.jinja2': template
173-
}))
174-
154+
app = app_with_template(template)
175155
app.router.add_route('*', '/', func)
176156

177157
client = yield from test_client(app)
@@ -184,7 +164,7 @@ def func(request):
184164

185165

186166
@asyncio.coroutine
187-
def test_render_template_custom_status(loop, test_client):
167+
def test_render_template_custom_status(app_with_template, test_client):
188168

189169
@asyncio.coroutine
190170
def func(request):
@@ -194,11 +174,7 @@ def func(request):
194174

195175
template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'
196176

197-
app = web.Application(loop=loop)
198-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
199-
'tmpl.jinja2': template
200-
}))
201-
177+
app = app_with_template(template)
202178
app.router.add_route('*', '/', func)
203179

204180
client = yield from test_client(app)
@@ -233,17 +209,14 @@ def func(request):
233209

234210

235211
@asyncio.coroutine
236-
def test_render_not_mapping(loop):
212+
def test_render_not_mapping(app_with_template):
237213

238214
@aiohttp_jinja2.template('tmpl.jinja2')
239215
@asyncio.coroutine
240216
def func(request):
241217
return 123
242218

243-
app = web.Application(loop=loop)
244-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
245-
{'tmpl.jinja2': 'tmpl'}))
246-
219+
app = app_with_template("tmpl")
247220
app.router.add_route('GET', '/', func)
248221

249222
req = make_mocked_request('GET', '/', app=app)
@@ -255,17 +228,15 @@ def func(request):
255228

256229

257230
@asyncio.coroutine
258-
def test_render_without_context(loop, test_client):
231+
def test_render_without_context(app_with_template, test_client):
259232

260233
@aiohttp_jinja2.template('tmpl.jinja2')
261234
def func(request):
262235
pass
263236

264237
template = '<html><body><p>{{text}}</p></body></html>'
265238

266-
app = web.Application(loop=loop)
267-
aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
268-
{'tmpl.jinja2': template}))
239+
app = app_with_template(template)
269240

270241
app.router.add_route('GET', '/', func)
271242

0 commit comments

Comments
 (0)