mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
extra_css_urls(template, database, table, datasette)
The extra_css_urls and extra_js_urls hooks now take additional optional parameters. Also refactored them out of the Datasette class and into RenderMixin. Plus improved plugin documentation to explicitly list parameters.
This commit is contained in:
parent
fbf446965b
commit
b7c6a9f9bd
7 changed files with 124 additions and 52 deletions
|
|
@ -2,6 +2,7 @@ from bs4 import BeautifulSoup as Soup
|
|||
from .fixtures import ( # noqa
|
||||
app_client,
|
||||
)
|
||||
import base64
|
||||
import json
|
||||
import re
|
||||
import pytest
|
||||
|
|
@ -15,16 +16,44 @@ def test_plugins_dir_plugin(app_client):
|
|||
assert pytest.approx(328.0839) == response.json['rows'][0][0]
|
||||
|
||||
|
||||
def test_plugin_extra_css_urls(app_client):
|
||||
response = app_client.get('/')
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected_decoded_object",
|
||||
[
|
||||
(
|
||||
"/",
|
||||
{
|
||||
"template": "index.html",
|
||||
"database": None,
|
||||
"table": None,
|
||||
},
|
||||
),
|
||||
(
|
||||
"/fixtures/",
|
||||
{
|
||||
"template": "database.html",
|
||||
"database": "fixtures",
|
||||
"table": None,
|
||||
},
|
||||
),
|
||||
(
|
||||
"/fixtures/sortable",
|
||||
{
|
||||
"template": "table.html",
|
||||
"database": "fixtures",
|
||||
"table": "sortable",
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_plugin_extra_css_urls(app_client, path, expected_decoded_object):
|
||||
response = app_client.get(path)
|
||||
links = Soup(response.body, 'html.parser').findAll('link')
|
||||
assert [
|
||||
l for l in links
|
||||
if l.attrs == {
|
||||
'rel': ['stylesheet'],
|
||||
'href': 'https://example.com/app.css'
|
||||
}
|
||||
]
|
||||
special_href = [
|
||||
l for l in links if l.attrs["href"].endswith("/extra-css-urls-demo.css")
|
||||
][0]["href"]
|
||||
# This link has a base64-encoded JSON blob in it
|
||||
encoded = special_href.split("/")[3]
|
||||
assert expected_decoded_object == json.loads(base64.b64decode(encoded))
|
||||
|
||||
|
||||
def test_plugin_extra_js_urls(app_client):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue