From 38078be63466f5cd78ad97963502e47b8435c07f Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 21 Mar 2019 14:18:44 +0100 Subject: behavior: Test crash --- crocoite/test_behavior.py | 49 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'crocoite') diff --git a/crocoite/test_behavior.py b/crocoite/test_behavior.py index 8a0dff4..bc2dab6 100644 --- a/crocoite/test_behavior.py +++ b/crocoite/test_behavior.py @@ -28,8 +28,9 @@ from aiohttp import web import pkg_resources from .logger import Logger from .devtools import Process -from .behavior import Scroll, Behavior, ExtractLinks, ExtractLinksEvent +from .behavior import Scroll, Behavior, ExtractLinks, ExtractLinksEvent, Crash from .controller import SinglePageController, EventHandler +from .devtools import Crashed with pkg_resources.resource_stream (__name__, os.path.join ('data', 'click.yaml')) as fd: sites = list (yaml.safe_load_all (fd)) @@ -110,13 +111,26 @@ class ExtractLinksCheck(EventHandler): if isinstance (item, ExtractLinksEvent): self.links.extend (item.links) +async def simpleServer (url, response): + async def f (req): + return web.Response (body=response, status=200, content_type='text/html', charset='utf-8') + + app = web.Application () + app.router.add_route ('GET', url.path, f) + runner = web.AppRunner(app) + await runner.setup() + site = web.TCPSite(runner, url.host, url.port) + await site.start() + return runner + @pytest.mark.asyncio async def test_extract_links (): """ Make sure the CSS selector exists on an example url """ - async def f (req): - return web.Response (body=""" + + url = URL.build (scheme='http', host='localhost', port=8080) + runner = await simpleServer (url, """
foo @@ -134,16 +148,7 @@ async def test_extract_links ():

- """, status=200, content_type='text/html', charset='utf-8') - - url = URL.build (scheme='http', host='localhost', port=8080) - - app = web.Application () - app.router.add_route ('GET', '/', f) - runner = web.AppRunner(app) - await runner.setup() - site = web.TCPSite(runner, url.host, url.port) - await site.start() + """) try: handler = ExtractLinksCheck () @@ -163,3 +168,21 @@ async def test_extract_links (): finally: await runner.cleanup () +@pytest.mark.asyncio +async def test_crash (): + """ + Crashing through Behavior works? + """ + + url = URL.build (scheme='http', host='localhost', port=8080) + runner = await simpleServer (url, '') + + try: + logger = Logger () + controller = SinglePageController (url=url, logger=logger, + service=Process (), behavior=[Crash]) + with pytest.raises (Crashed): + await controller.run () + finally: + await runner.cleanup () + -- cgit v1.2.3