kopia lustrzana https://github.com/simonw/datasette
custom pages tests templates now in repo
rodzic
e02f6c1300
commit
b37431976c
|
@ -1,41 +1,13 @@
|
||||||
|
import pathlib
|
||||||
import pytest
|
import pytest
|
||||||
from .fixtures import make_app_client
|
from .fixtures import make_app_client
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def custom_pages_client(tmp_path_factory):
|
def custom_pages_client():
|
||||||
template_dir = tmp_path_factory.mktemp("page-templates")
|
with make_app_client(
|
||||||
pages_dir = template_dir / "pages"
|
template_dir=str(pathlib.Path(__file__).parent / "test_templates")
|
||||||
pages_dir.mkdir()
|
) as client:
|
||||||
(pages_dir / "about.html").write_text("ABOUT! view_name:{{ view_name }}", "utf-8")
|
|
||||||
(pages_dir / "request.html").write_text("path:{{ request.path }}", "utf-8")
|
|
||||||
(pages_dir / "202.html").write_text("{{ custom_status(202) }}202!", "utf-8")
|
|
||||||
(pages_dir / "headers.html").write_text(
|
|
||||||
'{{ custom_header("x-this-is-foo", "foo") }}FOO'
|
|
||||||
'{{ custom_header("x-this-is-bar", "bar") }}BAR',
|
|
||||||
"utf-8",
|
|
||||||
)
|
|
||||||
(pages_dir / "atom.html").write_text(
|
|
||||||
'{{ custom_header("content-type", "application/xml") }}<?xml ...>',
|
|
||||||
"utf-8",
|
|
||||||
)
|
|
||||||
(pages_dir / "redirect.html").write_text(
|
|
||||||
'{{ custom_redirect("/example") }}', "utf-8"
|
|
||||||
)
|
|
||||||
(pages_dir / "redirect2.html").write_text(
|
|
||||||
'{{ custom_redirect("/example", 301) }}', "utf-8"
|
|
||||||
)
|
|
||||||
(pages_dir / "route_{name}.html").write_text(
|
|
||||||
"""
|
|
||||||
{% if name == "OhNo" %}{{ raise_404("Oh no") }}{% endif %}
|
|
||||||
<p>Hello from {{ name }}</p>
|
|
||||||
""",
|
|
||||||
"utf-8",
|
|
||||||
)
|
|
||||||
nested_dir = pages_dir / "nested"
|
|
||||||
nested_dir.mkdir()
|
|
||||||
(nested_dir / "nest.html").write_text("Nest!", "utf-8")
|
|
||||||
with make_app_client(template_dir=str(template_dir)) as client:
|
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{{ custom_status(202) }}202!
|
|
@ -0,0 +1 @@
|
||||||
|
ABOUT! view_name:{{ view_name }}
|
|
@ -0,0 +1 @@
|
||||||
|
{{ custom_header("content-type", "application/xml") }}<?xml ...>
|
|
@ -0,0 +1 @@
|
||||||
|
{{ custom_header("x-this-is-foo", "foo") }}FOO{{ custom_header("x-this-is-bar", "bar") }}BAR
|
|
@ -0,0 +1 @@
|
||||||
|
Nest!
|
|
@ -0,0 +1 @@
|
||||||
|
{{ custom_redirect("/example") }}
|
|
@ -0,0 +1 @@
|
||||||
|
{{ custom_redirect("/example", 301) }}
|
|
@ -0,0 +1 @@
|
||||||
|
path:{{ request.path }}
|
|
@ -0,0 +1,2 @@
|
||||||
|
{% if name == "OhNo" %}{{ raise_404("Oh no") }}{% endif %}
|
||||||
|
<p>Hello from {{ name }}</p>
|
Ładowanie…
Reference in New Issue