mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
c10cd48baf
commit
a35393b29c
14 changed files with 125 additions and 141 deletions
|
|
@ -19,8 +19,8 @@ from unittest.mock import patch
|
|||
("foo", ["foo"]),
|
||||
("foo,bar", ["foo", "bar"]),
|
||||
("123,433,112", ["123", "433", "112"]),
|
||||
("123%2C433,112", ["123,433", "112"]),
|
||||
("123%2F433%2F112", ["123/433/112"]),
|
||||
("123~2C433,112", ["123,433", "112"]),
|
||||
("123~2F433~2F112", ["123/433/112"]),
|
||||
],
|
||||
)
|
||||
def test_urlsafe_components(path, expected):
|
||||
|
|
@ -93,7 +93,7 @@ def test_path_with_replaced_args(path, args, expected):
|
|||
"row,pks,expected_path",
|
||||
[
|
||||
({"A": "foo", "B": "bar"}, ["A", "B"], "foo,bar"),
|
||||
({"A": "f,o", "B": "bar"}, ["A", "B"], "f-2Co,bar"),
|
||||
({"A": "f,o", "B": "bar"}, ["A", "B"], "f~2Co,bar"),
|
||||
({"A": 123}, ["A"], "123"),
|
||||
(
|
||||
utils.CustomRow(
|
||||
|
|
@ -393,9 +393,7 @@ def test_table_columns():
|
|||
("/foo?sql=select+1", "json", {}, "/foo.json?sql=select+1"),
|
||||
("/foo/bar", "json", {}, "/foo/bar.json"),
|
||||
("/foo/bar", "csv", {}, "/foo/bar.csv"),
|
||||
("/foo/bar.csv", "json", {}, "/foo/bar.csv?_format=json"),
|
||||
("/foo/bar", "csv", {"_dl": 1}, "/foo/bar.csv?_dl=1"),
|
||||
("/foo/b.csv", "json", {"_dl": 1}, "/foo/b.csv?_dl=1&_format=json"),
|
||||
(
|
||||
"/sf-trees/Street_Tree_List?_search=cherry&_size=1000",
|
||||
"csv",
|
||||
|
|
@ -410,18 +408,6 @@ def test_path_with_format(path, format, extra_qs, expected):
|
|||
assert expected == actual
|
||||
|
||||
|
||||
def test_path_with_format_replace_format():
|
||||
request = Request.fake("/foo/bar.csv")
|
||||
assert (
|
||||
utils.path_with_format(request=request, format="blob")
|
||||
== "/foo/bar.csv?_format=blob"
|
||||
)
|
||||
assert (
|
||||
utils.path_with_format(request=request, format="blob", replace_format="csv")
|
||||
== "/foo/bar.blob"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"bytes,expected",
|
||||
[
|
||||
|
|
@ -652,15 +638,15 @@ async def test_derive_named_parameters(sql, expected):
|
|||
"original,expected",
|
||||
(
|
||||
("abc", "abc"),
|
||||
("/foo/bar", "-2Ffoo-2Fbar"),
|
||||
("/-/bar", "-2F-2D-2Fbar"),
|
||||
("-/db-/table.csv", "-2D-2Fdb-2D-2Ftable-2Ecsv"),
|
||||
(r"%~-/", "-25-7E-2D-2F"),
|
||||
("-25-7E-2D-2F", "-2D25-2D7E-2D2D-2D2F"),
|
||||
("/foo/bar", "~2Ffoo~2Fbar"),
|
||||
("/-/bar", "~2F-~2Fbar"),
|
||||
("-/db-/table.csv", "-~2Fdb-~2Ftable~2Ecsv"),
|
||||
(r"%~-/", "~25~7E-~2F"),
|
||||
("~25~7E~2D~2F", "~7E25~7E7E~7E2D~7E2F"),
|
||||
),
|
||||
)
|
||||
def test_dash_encoding(original, expected):
|
||||
actual = utils.dash_encode(original)
|
||||
def test_tilde_encoding(original, expected):
|
||||
actual = utils.tilde_encode(original)
|
||||
assert actual == expected
|
||||
# And test round-trip
|
||||
assert original == utils.dash_decode(actual)
|
||||
assert original == utils.tilde_decode(actual)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue