|
@@ -228,7 +228,89 @@ class TestAiohttpExt(object):
|
228
|
228
|
line = await resp.content.readline()
|
229
|
229
|
assert b'{"name": "Hello, franck"}\n' == line
|
230
|
230
|
|
231
|
|
- # TODO BS 2018-07-26: How to ensure we are at end of response ?
|
|
231
|
+ async def test_aiohttp_output_stream__error__ignore(
|
|
232
|
+ self,
|
|
233
|
+ aiohttp_client,
|
|
234
|
+ loop,
|
|
235
|
+ ):
|
|
236
|
+ hapic = Hapic(async_=True)
|
|
237
|
+
|
|
238
|
+ class AsyncGenerator:
|
|
239
|
+ def __init__(self):
|
|
240
|
+ self._iterator = iter([
|
|
241
|
+ {'name': 'Hello, bob'},
|
|
242
|
+ {'nameZ': 'Hello, Z'}, # This line is incorrect
|
|
243
|
+ {'name': 'Hello, franck'},
|
|
244
|
+ ])
|
|
245
|
+
|
|
246
|
+ async def __aiter__(self):
|
|
247
|
+ return self
|
|
248
|
+
|
|
249
|
+ async def __anext__(self):
|
|
250
|
+ return next(self._iterator)
|
|
251
|
+
|
|
252
|
+ class OuputStreamItemSchema(marshmallow.Schema):
|
|
253
|
+ name = marshmallow.fields.String(required=True)
|
|
254
|
+
|
|
255
|
+ @hapic.output_stream(OuputStreamItemSchema(), ignore_on_error=True)
|
|
256
|
+ async def hello(request):
|
|
257
|
+ return AsyncGenerator()
|
|
258
|
+
|
|
259
|
+ app = web.Application(debug=True)
|
|
260
|
+ app.router.add_get('/', hello)
|
|
261
|
+ hapic.set_context(AiohttpContext(app))
|
|
262
|
+ client = await aiohttp_client(app)
|
|
263
|
+
|
|
264
|
+ resp = await client.get('/')
|
|
265
|
+ assert resp.status == 200
|
|
266
|
+
|
|
267
|
+ line = await resp.content.readline()
|
|
268
|
+ assert b'{"name": "Hello, bob"}\n' == line
|
|
269
|
+
|
|
270
|
+ line = await resp.content.readline()
|
|
271
|
+ assert b'{"name": "Hello, franck"}\n' == line
|
|
272
|
+
|
|
273
|
+ async def test_aiohttp_output_stream__error__interrupt(
|
|
274
|
+ self,
|
|
275
|
+ aiohttp_client,
|
|
276
|
+ loop,
|
|
277
|
+ ):
|
|
278
|
+ hapic = Hapic(async_=True)
|
|
279
|
+
|
|
280
|
+ class AsyncGenerator:
|
|
281
|
+ def __init__(self):
|
|
282
|
+ self._iterator = iter([
|
|
283
|
+ {'name': 'Hello, bob'},
|
|
284
|
+ {'nameZ': 'Hello, Z'}, # This line is incorrect
|
|
285
|
+ {'name': 'Hello, franck'}, # This line must not be reached
|
|
286
|
+ ])
|
|
287
|
+
|
|
288
|
+ async def __aiter__(self):
|
|
289
|
+ return self
|
|
290
|
+
|
|
291
|
+ async def __anext__(self):
|
|
292
|
+ return next(self._iterator)
|
|
293
|
+
|
|
294
|
+ class OuputStreamItemSchema(marshmallow.Schema):
|
|
295
|
+ name = marshmallow.fields.String(required=True)
|
|
296
|
+
|
|
297
|
+ @hapic.output_stream(OuputStreamItemSchema(), ignore_on_error=False)
|
|
298
|
+ async def hello(request):
|
|
299
|
+ return AsyncGenerator()
|
|
300
|
+
|
|
301
|
+ app = web.Application(debug=True)
|
|
302
|
+ app.router.add_get('/', hello)
|
|
303
|
+ hapic.set_context(AiohttpContext(app))
|
|
304
|
+ client = await aiohttp_client(app)
|
|
305
|
+
|
|
306
|
+ resp = await client.get('/')
|
|
307
|
+ assert resp.status == 200
|
|
308
|
+
|
|
309
|
+ line = await resp.content.readline()
|
|
310
|
+ assert b'{"name": "Hello, bob"}\n' == line
|
|
311
|
+
|
|
312
|
+ line = await resp.content.readline()
|
|
313
|
+ assert b'' == line
|
232
|
314
|
|
233
|
315
|
def test_unit__generate_doc__ok__nominal_case(
|
234
|
316
|
self,
|