mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
truncate_cells_html now affects URLs too, refs #1805
This commit is contained in:
parent
ff9c87197d
commit
d0737e4de5
8 changed files with 68 additions and 14 deletions
|
|
@ -598,23 +598,24 @@ CREATE TABLE roadside_attractions (
|
|||
pk integer primary key,
|
||||
name text,
|
||||
address text,
|
||||
url text,
|
||||
latitude real,
|
||||
longitude real
|
||||
);
|
||||
INSERT INTO roadside_attractions VALUES (
|
||||
1, "The Mystery Spot", "465 Mystery Spot Road, Santa Cruz, CA 95065",
|
||||
1, "The Mystery Spot", "465 Mystery Spot Road, Santa Cruz, CA 95065", "https://www.mysteryspot.com/",
|
||||
37.0167, -122.0024
|
||||
);
|
||||
INSERT INTO roadside_attractions VALUES (
|
||||
2, "Winchester Mystery House", "525 South Winchester Boulevard, San Jose, CA 95128",
|
||||
2, "Winchester Mystery House", "525 South Winchester Boulevard, San Jose, CA 95128", "https://winchestermysteryhouse.com/",
|
||||
37.3184, -121.9511
|
||||
);
|
||||
INSERT INTO roadside_attractions VALUES (
|
||||
3, "Burlingame Museum of PEZ Memorabilia", "214 California Drive, Burlingame, CA 94010",
|
||||
3, "Burlingame Museum of PEZ Memorabilia", "214 California Drive, Burlingame, CA 94010", null,
|
||||
37.5793, -122.3442
|
||||
);
|
||||
INSERT INTO roadside_attractions VALUES (
|
||||
4, "Bigfoot Discovery Museum", "5497 Highway 9, Felton, CA 95018",
|
||||
4, "Bigfoot Discovery Museum", "5497 Highway 9, Felton, CA 95018", "https://www.bigfootdiscoveryproject.com/",
|
||||
37.0414, -122.0725
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ def test_database_page(app_client):
|
|||
},
|
||||
{
|
||||
"name": "roadside_attractions",
|
||||
"columns": ["pk", "name", "address", "latitude", "longitude"],
|
||||
"columns": ["pk", "name", "address", "url", "latitude", "longitude"],
|
||||
"primary_keys": ["pk"],
|
||||
"count": 4,
|
||||
"hidden": False,
|
||||
|
|
|
|||
|
|
@ -615,11 +615,12 @@ def test_table_through(app_client):
|
|||
response = app_client.get(
|
||||
'/fixtures/roadside_attractions.json?_through={"table":"roadside_attraction_characteristics","column":"characteristic_id","value":"1"}'
|
||||
)
|
||||
assert [
|
||||
assert response.json["rows"] == [
|
||||
[
|
||||
3,
|
||||
"Burlingame Museum of PEZ Memorabilia",
|
||||
"214 California Drive, Burlingame, CA 94010",
|
||||
None,
|
||||
37.5793,
|
||||
-122.3442,
|
||||
],
|
||||
|
|
@ -627,13 +628,15 @@ def test_table_through(app_client):
|
|||
4,
|
||||
"Bigfoot Discovery Museum",
|
||||
"5497 Highway 9, Felton, CA 95018",
|
||||
"https://www.bigfootdiscoveryproject.com/",
|
||||
37.0414,
|
||||
-122.0725,
|
||||
],
|
||||
] == response.json["rows"]
|
||||
]
|
||||
|
||||
assert (
|
||||
'where roadside_attraction_characteristics.characteristic_id = "1"'
|
||||
== response.json["human_description_en"]
|
||||
response.json["human_description_en"]
|
||||
== 'where roadside_attraction_characteristics.characteristic_id = "1"'
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,17 @@ def test_table_cell_truncation():
|
|||
td.string
|
||||
for td in table.findAll("td", {"class": "col-neighborhood-b352a7"})
|
||||
]
|
||||
# URLs should be truncated too
|
||||
response2 = client.get("/fixtures/roadside_attractions")
|
||||
assert response2.status == 200
|
||||
table = Soup(response2.body, "html.parser").find("table")
|
||||
tds = table.findAll("td", {"class": "col-url"})
|
||||
assert [str(td) for td in tds] == [
|
||||
'<td class="col-url type-str"><a href="https://www.mysteryspot.com/">http…</a></td>',
|
||||
'<td class="col-url type-str"><a href="https://winchestermysteryhouse.com/">http…</a></td>',
|
||||
'<td class="col-url type-none">\xa0</td>',
|
||||
'<td class="col-url type-str"><a href="https://www.bigfootdiscoveryproject.com/">http…</a></td>',
|
||||
]
|
||||
|
||||
|
||||
def test_add_filter_redirects(app_client):
|
||||
|
|
|
|||
|
|
@ -626,3 +626,23 @@ def test_tilde_encoding(original, expected):
|
|||
assert actual == expected
|
||||
# And test round-trip
|
||||
assert original == utils.tilde_decode(actual)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"url,length,expected",
|
||||
(
|
||||
("https://example.com/", 5, "http…"),
|
||||
("https://example.com/foo/bar", 15, "https://exampl…"),
|
||||
("https://example.com/foo/bar/baz.jpg", 30, "https://example.com/foo/ba….jpg"),
|
||||
# Extensions longer than 4 characters are not treated specially:
|
||||
("https://example.com/foo/bar/baz.jpeg2", 30, "https://example.com/foo/bar/b…"),
|
||||
(
|
||||
"https://example.com/foo/bar/baz.jpeg2",
|
||||
None,
|
||||
"https://example.com/foo/bar/baz.jpeg2",
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_truncate_url(url, length, expected):
|
||||
actual = utils.truncate_url(url, length)
|
||||
assert actual == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue