Skip to content

Commit bab3d71

Browse files
committed
Add some test cases
1 parent 16082ae commit bab3d71

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

tests/test_asgi/test_middleware.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
import pytest
66
from jinja2 import Environment as JinjaEnvironment
77
from jinja2 import FileSystemLoader as JinjaFileSystemLoader
8+
from requests import request
89
from starlette.applications import Starlette
910
from starlette.routing import Route
1011
from starlette.templating import Jinja2Templates
1112

1213
import reactpy
1314
from reactpy.asgi.middleware import ReactPyMiddleware
15+
from reactpy.config import REACTPY_PATH_PREFIX, REACTPY_TESTS_DEFAULT_TIMEOUT
1416
from reactpy.testing import BackendFixture, DisplayFixture
1517

1618

1719
@pytest.fixture()
1820
async def display(page):
21+
"""Override for the display fixture that uses ReactPyMiddleware."""
1922
templates = Jinja2Templates(
2023
env=JinjaEnvironment(
2124
loader=JinjaFileSystemLoader("tests/templates"),
@@ -101,3 +104,16 @@ def Hello():
101104
await display.page.reload()
102105

103106
await display.page.wait_for_selector("#hello")
107+
108+
109+
async def test_static_file_not_found(page):
110+
async def app(scope, receive, send): ...
111+
112+
app = ReactPyMiddleware(app, [])
113+
114+
async with BackendFixture(app) as server:
115+
url = f"http://{server.host}:{server.port}{REACTPY_PATH_PREFIX.current}static/invalid.js"
116+
response = await asyncio.to_thread(
117+
request, "GET", url, timeout=REACTPY_TESTS_DEFAULT_TIMEOUT.current
118+
)
119+
assert response.status_code == 404

tests/test_asgi/test_pyodide.py

Whitespace-only changes.

tests/test_asgi/test_standalone.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
from reactpy.types import Connection, Location
1515

1616

17-
@pytest.fixture()
18-
async def display(page):
19-
async with BackendFixture() as server:
20-
async with DisplayFixture(backend=server, driver=page) as display:
21-
yield display
22-
23-
2417
async def test_display_simple_hello_world(display: DisplayFixture):
2518
@reactpy.component
2619
def Hello():
@@ -153,17 +146,15 @@ def sample():
153146
app = ReactPy(sample)
154147

155148
async with BackendFixture(app) as server:
156-
async with DisplayFixture(backend=server, driver=page) as new_display:
157-
await new_display.show(sample)
158-
url = f"http://{server.host}:{server.port}"
159-
response = await asyncio.to_thread(
160-
request, "HEAD", url, timeout=REACTPY_TESTS_DEFAULT_TIMEOUT.current
161-
)
162-
assert response.status_code == 200
163-
assert response.headers["content-type"] == "text/html; charset=utf-8"
164-
assert response.headers["cache-control"] == "max-age=60, public"
165-
assert response.headers["access-control-allow-origin"] == "*"
166-
assert response.content == b""
149+
url = f"http://{server.host}:{server.port}"
150+
response = await asyncio.to_thread(
151+
request, "HEAD", url, timeout=REACTPY_TESTS_DEFAULT_TIMEOUT.current
152+
)
153+
assert response.status_code == 200
154+
assert response.headers["content-type"] == "text/html; charset=utf-8"
155+
assert response.headers["cache-control"] == "max-age=60, public"
156+
assert response.headers["access-control-allow-origin"] == "*"
157+
assert response.content == b""
167158

168159

169160
async def test_custom_http_app():

0 commit comments

Comments
 (0)