import asyncio from boot import EntryShell from config import ROOT def test_entry_shell_is_sent_before_javascript_and_is_not_cached(): async def app(scope, receive, send): await send({'type':'http.response.start','status':200,'headers':[(b'content-type',b'text/html'),(b'content-length',b'31'),(b'etag',b'old')]}) await send({'type':'http.response.body','body':b'','more_body':True}) await send({'type':'http.response.body','body':b''}) result=[] async def send(message):result.append(message) asyncio.run(EntryShell(app,ROOT/'assets/boot.html')({'type':'http','method':'GET','path':'/'},None,send)) headers=dict(result[0]['headers']);body=result[1]['body'] assert headers[b'cache-control']==b'no-store' and b'etag' not in headers assert int(headers[b'content-length'])==len(body) assert body.index(b'id="zonos-boot"')') assert b'Loading the interface' in body and b'Open in a new tab' in body def test_api_and_audio_streams_pass_through_without_buffering(): for path in ['/gradio_api/queue/data','/gradio_api/file=voice.wav','/assets/script.js','/config']: sent=[] async def app(scope,receive,send): for message in [{'type':'http.response.start','status':200,'headers':[]}, {'type':'http.response.body','body':b'first','more_body':True}, {'type':'http.response.body','body':b'last'}]: await send(message) assert sent[-1] is message async def send(message):sent.append(message) asyncio.run(EntryShell(app,ROOT/'assets/boot.html')({'type':'http','method':'GET','path':path},None,send)) assert len(sent)==3