mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
datasette.urls.table(..., format="json"), closes #1035
Also improved tests for datasette.urls and added format= to some other methods
This commit is contained in:
parent
b84cfe1b08
commit
11eb1e026f
7 changed files with 92 additions and 40 deletions
|
|
@ -82,18 +82,44 @@ def test_logout(ds, base_url, expected):
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"base_url,expected",
|
||||
"base_url,format,expected",
|
||||
[
|
||||
("/", "/:memory:"),
|
||||
("/prefix/", "/prefix/:memory:"),
|
||||
("/", None, "/:memory:"),
|
||||
("/prefix/", None, "/prefix/:memory:"),
|
||||
("/", "json", "/:memory:.json"),
|
||||
],
|
||||
)
|
||||
def test_database(ds, base_url, expected):
|
||||
def test_database(ds, base_url, format, expected):
|
||||
ds._config["base_url"] = base_url
|
||||
assert ds.urls.database(":memory:") == expected
|
||||
# Do table and query while we are here
|
||||
assert ds.urls.table(":memory:", "name") == expected + "/name"
|
||||
assert ds.urls.query(":memory:", "name") == expected + "/name"
|
||||
assert ds.urls.database(":memory:", format=format) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"base_url,name,format,expected",
|
||||
[
|
||||
("/", "name", None, "/:memory:/name"),
|
||||
("/prefix/", "name", None, "/prefix/:memory:/name"),
|
||||
("/", "name", "json", "/:memory:/name.json"),
|
||||
("/", "name.json", "json", "/:memory:/name.json?_format=json"),
|
||||
],
|
||||
)
|
||||
def test_table_and_query(ds, base_url, name, format, expected):
|
||||
ds._config["base_url"] = base_url
|
||||
assert ds.urls.table(":memory:", name, format=format) == expected
|
||||
assert ds.urls.query(":memory:", name, format=format) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"base_url,format,expected",
|
||||
[
|
||||
("/", None, "/:memory:/facetable/1"),
|
||||
("/prefix/", None, "/prefix/:memory:/facetable/1"),
|
||||
("/", "json", "/:memory:/facetable/1.json"),
|
||||
],
|
||||
)
|
||||
def test_row(ds, base_url, format, expected):
|
||||
ds._config["base_url"] = base_url
|
||||
assert ds.urls.row(":memory:", "facetable", "1", format=format) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base_url", ["/", "/prefix/"])
|
||||
|
|
|
|||
|
|
@ -382,15 +382,19 @@ def test_table_columns():
|
|||
)
|
||||
def test_path_with_format(path, format, extra_qs, expected):
|
||||
request = Request.fake(path)
|
||||
actual = utils.path_with_format(request, format, extra_qs)
|
||||
actual = utils.path_with_format(request=request, format=format, extra_qs=extra_qs)
|
||||
assert expected == actual
|
||||
|
||||
|
||||
def test_path_with_format_replace_format():
|
||||
request = Request.fake("/foo/bar.csv")
|
||||
assert utils.path_with_format(request, "blob") == "/foo/bar.csv?_format=blob"
|
||||
assert (
|
||||
utils.path_with_format(request, "blob", replace_format="csv") == "/foo/bar.blob"
|
||||
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"
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue