mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Fake server 404 support (#994)
* Fake server 404 support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * 404 test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import dataclasses
|
||||
import os
|
||||
import pdb
|
||||
import re
|
||||
import sys
|
||||
@@ -595,7 +596,10 @@ class SmartRouter:
|
||||
self.log_request(200, "fake_server", full_url)
|
||||
assert url.path[0] == "/"
|
||||
relative_path = url.path[1:]
|
||||
route.fulfill(status=200, path=relative_path)
|
||||
if os.path.exists(relative_path):
|
||||
route.fulfill(status=200, path=relative_path)
|
||||
else:
|
||||
route.fulfill(status=404)
|
||||
return
|
||||
|
||||
# network requests might be cached
|
||||
|
||||
@@ -389,3 +389,12 @@ class TestSupport(PyScriptTest):
|
||||
(200, "fake_server", "http://fake_server/mytest.html"),
|
||||
(200, "CACHED", URL),
|
||||
]
|
||||
|
||||
def test_404(self):
|
||||
"""
|
||||
Test that we capture a 404 in loading a page that does not exist.
|
||||
"""
|
||||
self.goto("this_url_does_not_exist.html")
|
||||
assert [
|
||||
"Failed to load resource: the server responded with a status of 404 (Not Found)"
|
||||
] == self.console.all.lines
|
||||
|
||||
@@ -180,8 +180,12 @@ class TestBasic(PyScriptTest):
|
||||
self.check_js_errors()
|
||||
|
||||
error_msg = str(exc.value)
|
||||
print(error_msg)
|
||||
if self.is_fake_server:
|
||||
assert "Failed to fetch" in error_msg
|
||||
assert (
|
||||
"Fetching from URL foo.py failed with error 404 (Not Found)."
|
||||
in error_msg
|
||||
)
|
||||
else:
|
||||
assert (
|
||||
"Fetching from URL foo.py failed with error 404 (File not found)"
|
||||
|
||||
@@ -245,16 +245,10 @@ class TestConfig(PyScriptTest):
|
||||
wait_for_pyscript=False,
|
||||
)
|
||||
|
||||
if self.is_fake_server:
|
||||
expected = """PyScript: Access to local files
|
||||
(using "Paths:" in <py-config>)
|
||||
is not available when directly opening a HTML file;
|
||||
you must use a webserver to serve the additional files."""
|
||||
else:
|
||||
expected = (
|
||||
"Loading from file <u>./f.py</u> failed with error 404 (File not Found). "
|
||||
"Are your filename and path are correct?"
|
||||
)
|
||||
expected = (
|
||||
"Loading from file <u>./f.py</u> failed with error 404 (File not Found). "
|
||||
"Are your filename and path are correct?"
|
||||
)
|
||||
|
||||
inner_html = self.page.locator(".py-error").inner_html()
|
||||
assert expected in inner_html
|
||||
|
||||
Reference in New Issue
Block a user