mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Test for prepare_jinja2_environment, refs #773
This commit is contained in:
parent
57f48b8416
commit
cbeea23d00
2 changed files with 15 additions and 0 deletions
|
|
@ -87,3 +87,8 @@ def extra_template_vars(template, database, table, view_name, request, datasette
|
||||||
default=lambda b: b.decode("utf8"),
|
default=lambda b: b.decode("utf8"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@hookimpl
|
||||||
|
def prepare_jinja2_environment(env):
|
||||||
|
env.filters["format_numeric"] = lambda s: "{:,.0f}".format(float(s))
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ from .fixtures import (
|
||||||
from datasette.app import Datasette
|
from datasette.app import Datasette
|
||||||
from datasette.plugins import get_plugins, DEFAULT_PLUGINS, pm
|
from datasette.plugins import get_plugins, DEFAULT_PLUGINS, pm
|
||||||
from datasette.utils import sqlite3
|
from datasette.utils import sqlite3
|
||||||
|
from jinja2.environment import Template
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
@ -408,3 +409,12 @@ def test_register_output_renderer_custom_headers(app_client):
|
||||||
)
|
)
|
||||||
assert "1" == response.headers["x-wow"]
|
assert "1" == response.headers["x-wow"]
|
||||||
assert "2" == response.headers["x-gosh"]
|
assert "2" == response.headers["x-gosh"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_prepare_jinja2_environment(app_client):
|
||||||
|
template = app_client.ds.jinja_env.from_string(
|
||||||
|
"Hello there, {{ a|format_numeric }}", {"a": 3412341}
|
||||||
|
)
|
||||||
|
rendered = await app_client.ds.render_template(template)
|
||||||
|
assert "Hello there, 3,412,341" == rendered
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue