|
| 1 | +import pytest |
| 2 | +import time |
| 3 | +import asyncio |
| 4 | +import os |
| 5 | + |
| 6 | + |
| 7 | +@pytest.fixture(params=[['--Voila.base_url="/base/"'], []]) |
| 8 | +def using_base_url(request): |
| 9 | + return request.param |
| 10 | + |
| 11 | + |
| 12 | +@pytest.fixture(params=[['--Voila.server_url="/server/"'], []]) |
| 13 | +def using_server_url(request): |
| 14 | + return request.param |
| 15 | + |
| 16 | + |
| 17 | +@pytest.fixture() |
| 18 | +def voila_args_extra(using_server_url, using_base_url): |
| 19 | + return using_server_url + using_base_url |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture |
| 23 | +def preheat_mode(http_server_port): |
| 24 | + os.environ['VOILA_APP_PORT'] = str(http_server_port[-1]) |
| 25 | + return True |
| 26 | + |
| 27 | + |
| 28 | +@pytest.fixture |
| 29 | +def voila_notebook(notebook_directory): |
| 30 | + return os.path.join( |
| 31 | + notebook_directory, 'preheat', 'get_query_string.ipynb' |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +NOTEBOOK_EXECUTION_TIME = 2 |
| 36 | +TIME_THRESHOLD = NOTEBOOK_EXECUTION_TIME |
| 37 | + |
| 38 | + |
| 39 | +async def send_request(sc, url, wait=0): |
| 40 | + await asyncio.sleep(wait) |
| 41 | + real_time = time.time() |
| 42 | + response = await sc.fetch(url) |
| 43 | + real_time = time.time() - real_time |
| 44 | + html_text = response.body.decode('utf-8') |
| 45 | + return real_time, html_text |
| 46 | + |
| 47 | + |
| 48 | +async def test_request_with_query( |
| 49 | + http_server_client, base_url, using_base_url, using_server_url |
| 50 | +): |
| 51 | + """ |
| 52 | + We sent request with query parameter, `get_query_string` should |
| 53 | + return value. |
| 54 | + """ |
| 55 | + if len(using_server_url) > 0: |
| 56 | + url = '/server/?foo=bar' |
| 57 | + else: |
| 58 | + if len(using_base_url) > 0: |
| 59 | + url = '/base/?foo=bar' |
| 60 | + else: |
| 61 | + url = f'{base_url}?foo=bar' |
| 62 | + _, html_text = await send_request( |
| 63 | + sc=http_server_client, url=url, wait=NOTEBOOK_EXECUTION_TIME + 1 |
| 64 | + ) |
| 65 | + assert 'foo=bar' in html_text |
0 commit comments