diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2019-03-21 14:18:44 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2019-03-21 14:21:35 +0100 |
commit | 38078be63466f5cd78ad97963502e47b8435c07f (patch) | |
tree | df84e30077a47937d17574b311e4b5ee48901d43 /crocoite | |
parent | 48a79ef69381266c3d46f446dc9b422a691a4a39 (diff) | |
download | crocoite-38078be63466f5cd78ad97963502e47b8435c07f.tar.gz crocoite-38078be63466f5cd78ad97963502e47b8435c07f.tar.bz2 crocoite-38078be63466f5cd78ad97963502e47b8435c07f.zip |
behavior: Test crash
Diffstat (limited to 'crocoite')
-rw-r--r-- | crocoite/test_behavior.py | 49 |
1 files changed, 36 insertions, 13 deletions
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="""<html><head></head> + + url = URL.build (scheme='http', host='localhost', port=8080) + runner = await simpleServer (url, """<html><head></head> <body> <div> <a href="/relative">foo</a> @@ -134,16 +148,7 @@ async def test_extract_links (): <p><img src="shapes.png" usemap="#shapes"> <map name="shapes"><area shape=rect coords="50,50,100,100" href="/map/rect"></map></p> </div> - </body></html>""", 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() + </body></html>""") 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, '<html></html>') + + try: + logger = Logger () + controller = SinglePageController (url=url, logger=logger, + service=Process (), behavior=[Crash]) + with pytest.raises (Crashed): + await controller.run () + finally: + await runner.cleanup () + |