custom pages tests templates now in repo

pull/1000/head
Simon Willison 2020-10-07 15:16:41 -07:00
rodzic e02f6c1300
commit b37431976c
10 zmienionych plików z 15 dodań i 33 usunięć

Wyświetl plik

@ -1,41 +1,13 @@
import pathlib
import pytest
from .fixtures import make_app_client
@pytest.fixture(scope="session")
def custom_pages_client(tmp_path_factory):
template_dir = tmp_path_factory.mktemp("page-templates")
pages_dir = template_dir / "pages"
pages_dir.mkdir()
(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:
def custom_pages_client():
with make_app_client(
template_dir=str(pathlib.Path(__file__).parent / "test_templates")
) as client:
yield client

Wyświetl plik

@ -0,0 +1 @@
{{ custom_status(202) }}202!

Wyświetl plik

@ -0,0 +1 @@
ABOUT! view_name:{{ view_name }}

Wyświetl plik

@ -0,0 +1 @@
{{ custom_header("content-type", "application/xml") }}<?xml ...>

Wyświetl plik

@ -0,0 +1 @@
{{ custom_header("x-this-is-foo", "foo") }}FOO{{ custom_header("x-this-is-bar", "bar") }}BAR

Wyświetl plik

@ -0,0 +1 @@
Nest!

Wyświetl plik

@ -0,0 +1 @@
{{ custom_redirect("/example") }}

Wyświetl plik

@ -0,0 +1 @@
{{ custom_redirect("/example", 301) }}

Wyświetl plik

@ -0,0 +1 @@
path:{{ request.path }}

Wyświetl plik

@ -0,0 +1,2 @@
{% if name == "OhNo" %}{{ raise_404("Oh no") }}{% endif %}
<p>Hello from {{ name }}</p>