From be0fee99e76907467bc4a5db6d8844aebe406d0e Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 2 Sep 2016 11:20:59 +0200 Subject: [PATCH] Test pcap streaming --- tests/handlers/api/controller/test_link.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/handlers/api/controller/test_link.py b/tests/handlers/api/controller/test_link.py index 371a76fb..160240c9 100644 --- a/tests/handlers/api/controller/test_link.py +++ b/tests/handlers/api/controller/test_link.py @@ -182,15 +182,26 @@ def test_stop_capture(http_controller, tmpdir, project, compute, async_run): assert response.status == 201 -def test_pcap(http_controller, tmpdir, project, compute, async_run): +def test_pcap(http_controller, tmpdir, project, compute, loop): + @asyncio.coroutine + def go(future): + response = yield from aiohttp.request("GET", http_controller.get_url("/projects/{}/links/{}/pcap".format(project.id, link.id))) + response.body = yield from response.content.read(5) + response.close() + future.set_result(response) + link = Link(project) link._capture_file_name = "test" link._capturing = True with open(link.capture_file_path, "w+") as f: f.write("hello") project._links = {link.id: link} - response = http_controller.get("/projects/{}/links/{}/pcap".format(project.id, link.id), example=False) - assert response.body == b"hello" + + future = asyncio.Future() + asyncio.async(go(future)) + response = loop.run_until_complete(future) + assert response.status == 200 + assert b'hello' == response.body def test_delete_link(http_controller, tmpdir, project, compute, async_run):