11import asyncio
22import json
3+ import ssl
34from unittest import mock
45
56import aiohttp
1415from aiohttp_devtools .runserver .serve import (
1516 WS , create_auxiliary_app , create_main_app , modify_main_app , src_reload , start_main_app )
1617from aiohttp_devtools .runserver .watch import AppTask
17- import ssl
1818
1919from .conftest import SIMPLE_APP , forked , linux_forked
2020
@@ -314,12 +314,12 @@ async def test_websocket_reload(aux_cli):
314314async def check_ssl_server_running (check_callback ):
315315 port_open = False
316316 ssl_context = ssl .create_default_context ()
317- ssl_context .load_verify_locations (' test_certs/rootCA.pem' )
317+ ssl_context .load_verify_locations (" test_certs/rootCA.pem" )
318318
319319 async with aiohttp .ClientSession (timeout = ClientTimeout (total = 1 )) as session :
320320 for i in range (50 ): # pragma: no branch
321321 try :
322- async with session .get (' https://localhost:8000/' , ssl = ssl_context ):
322+ async with session .get (" https://localhost:8000/" , ssl = ssl_context ):
323323 pass
324324 except OSError :
325325 await asyncio .sleep (0.1 )
@@ -333,35 +333,35 @@ async def check_ssl_server_running(check_callback):
333333
334334@pytest .mark .filterwarnings (r"ignore:unclosed:ResourceWarning" )
335335@linux_forked
336- @pytest .mark .datafiles (' tests/test_certs' , keep_top_dir = True )
336+ @pytest .mark .datafiles (" tests/test_certs" , keep_top_dir = True )
337337def test_start_runserver_ssl (datafiles , tmpworkdir , smart_caplog ):
338338 mktree (tmpworkdir , {
339- ' app.py' : """\
339+ " app.py" : """\
340340 from aiohttp import web
341341import ssl
342342async def hello(request):
343- return web.Response(text=' <h1>hello world</h1>' , content_type=' text/html' )
343+ return web.Response(text=" <h1>hello world</h1>" , content_type=" text/html" )
344344
345345async def has_error(request):
346346 raise ValueError()
347347
348348def create_app():
349349 app = web.Application()
350- app.router.add_get('/' , hello)
351- app.router.add_get(' /error' , has_error)
350+ app.router.add_get("/" , hello)
351+ app.router.add_get(" /error" , has_error)
352352 return app
353353
354354def get_ssl_context():
355355 ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
356- ssl_context.load_cert_chain(' test_certs/server.crt', ' test_certs/server.key' )
356+ ssl_context.load_cert_chain(" test_certs/server.crt", " test_certs/server.key" )
357357 return ssl_context
358358 """ ,
359- ' static_dir/foo.js' : ' var bar=1;' ,
359+ " static_dir/foo.js" : " var bar=1;" ,
360360 })
361361 loop = asyncio .new_event_loop ()
362362 asyncio .set_event_loop (loop )
363363 args = runserver (app_path = "app.py" , static_path = "static_dir" ,
364- bind_address = "0.0.0.0" , ssl_context_factory_name = ' get_ssl_context' )
364+ bind_address = "0.0.0.0" , ssl_context_factory_name = " get_ssl_context" )
365365 aux_app = args ["app" ]
366366 aux_port = args ["port" ]
367367 runapp_host = args ["host" ]
@@ -373,17 +373,17 @@ def get_ssl_context():
373373
374374 async def check_callback (session , ssl_context ):
375375 print (session , ssl_context )
376- async with session .get (' https://localhost:8000/' , ssl = ssl_context ) as r :
376+ async with session .get (" https://localhost:8000/" , ssl = ssl_context ) as r :
377377 assert r .status == 200
378- assert r .headers [' content-type' ].startswith (' text/html' )
378+ assert r .headers [" content-type" ].startswith (" text/html" )
379379 text = await r .text ()
380380 print (text )
381- assert ' <h1>hello world</h1>' in text
381+ assert " <h1>hello world</h1>" in text
382382 assert '<script src="http://localhost:8001/livereload.js"></script>' in text
383383
384- async with session .get (' https://localhost:8000/error' , ssl = ssl_context ) as r :
384+ async with session .get (" https://localhost:8000/error" , ssl = ssl_context ) as r :
385385 assert r .status == 500
386- assert ' raise ValueError()' in (await r .text ())
386+ assert " raise ValueError()" in (await r .text ())
387387
388388 try :
389389 loop .run_until_complete (check_ssl_server_running (check_callback ))
@@ -392,8 +392,8 @@ async def check_callback(session, ssl_context):
392392 loop .run_until_complete (shutdown (aux_app ))
393393 loop .run_until_complete (aux_app .cleanup ())
394394 assert (
395- ' adev.server.dft INFO: Starting aux server at http://localhost:8001 ◆\n '
396- ' adev.server.dft INFO: serving static files from ./static_dir/ at http://localhost:8001/static/\n '
397- ' adev.server.dft INFO: Starting dev server at https://localhost:8000 ●\n '
395+ " adev.server.dft INFO: Starting aux server at http://localhost:8001 ◆\n "
396+ " adev.server.dft INFO: serving static files from ./static_dir/ at http://localhost:8001/static/\n "
397+ " adev.server.dft INFO: Starting dev server at https://localhost:8000 ●\n "
398398 ) in smart_caplog
399399 loop .run_until_complete (asyncio .sleep (.25 )) # TODO(aiohttp 4): Remove this hack
0 commit comments