File size: 1,809 Bytes
9684bdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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'<html><body\n style="margin:0">','more_body':True})
        await send({'type':'http.response.body','body':b'<gradio-app></gradio-app></body></html>'})
    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"')<body.index(b'<gradio-app>')
    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