kopia lustrzana https://github.com/simonw/datasette
ds_client for test_internal_db.py, refs #1959
rodzic
4a151b15cc
commit
ef74d0ff70
|
@ -1,38 +1,45 @@
|
|||
from .fixtures import app_client
|
||||
import pytest
|
||||
|
||||
|
||||
def test_internal_only_available_to_root(app_client):
|
||||
cookie = app_client.actor_cookie({"id": "root"})
|
||||
assert app_client.get("/_internal").status == 403
|
||||
assert app_client.get("/_internal", cookies={"ds_actor": cookie}).status == 200
|
||||
@pytest.mark.ds_client
|
||||
@pytest.mark.asyncio
|
||||
async def test_internal_only_available_to_root(ds_client):
|
||||
cookie = ds_client.actor_cookie({"id": "root"})
|
||||
assert (await ds_client.get("/_internal")).status_code == 403
|
||||
assert (await ds_client.get("/_internal", cookies={"ds_actor": cookie})).status_code == 200
|
||||
|
||||
|
||||
def test_internal_databases(app_client):
|
||||
cookie = app_client.actor_cookie({"id": "root"})
|
||||
databases = app_client.get(
|
||||
@pytest.mark.ds_client
|
||||
@pytest.mark.asyncio
|
||||
async def test_internal_databases(ds_client):
|
||||
cookie = ds_client.actor_cookie({"id": "root"})
|
||||
databases = (await ds_client.get(
|
||||
"/_internal/databases.json?_shape=array", cookies={"ds_actor": cookie}
|
||||
).json
|
||||
)).json()
|
||||
assert len(databases) == 2
|
||||
assert databases[0]["database_name"] == "_internal"
|
||||
assert databases[1]["database_name"] == "fixtures"
|
||||
|
||||
|
||||
def test_internal_tables(app_client):
|
||||
cookie = app_client.actor_cookie({"id": "root"})
|
||||
tables = app_client.get(
|
||||
@pytest.mark.ds_client
|
||||
@pytest.mark.asyncio
|
||||
async def test_internal_tables(ds_client):
|
||||
cookie = ds_client.actor_cookie({"id": "root"})
|
||||
tables = (await ds_client.get(
|
||||
"/_internal/tables.json?_shape=array", cookies={"ds_actor": cookie}
|
||||
).json
|
||||
)).json()
|
||||
assert len(tables) > 5
|
||||
table = tables[0]
|
||||
assert set(table.keys()) == {"rootpage", "table_name", "database_name", "sql"}
|
||||
|
||||
|
||||
def test_internal_indexes(app_client):
|
||||
cookie = app_client.actor_cookie({"id": "root"})
|
||||
indexes = app_client.get(
|
||||
@pytest.mark.ds_client
|
||||
@pytest.mark.asyncio
|
||||
async def test_internal_indexes(ds_client):
|
||||
cookie = ds_client.actor_cookie({"id": "root"})
|
||||
indexes = (await ds_client.get(
|
||||
"/_internal/indexes.json?_shape=array", cookies={"ds_actor": cookie}
|
||||
).json
|
||||
)).json()
|
||||
assert len(indexes) > 5
|
||||
index = indexes[0]
|
||||
assert set(index.keys()) == {
|
||||
|
@ -46,11 +53,13 @@ def test_internal_indexes(app_client):
|
|||
}
|
||||
|
||||
|
||||
def test_internal_foreign_keys(app_client):
|
||||
cookie = app_client.actor_cookie({"id": "root"})
|
||||
foreign_keys = app_client.get(
|
||||
@pytest.mark.ds_client
|
||||
@pytest.mark.asyncio
|
||||
async def test_internal_foreign_keys(ds_client):
|
||||
cookie = ds_client.actor_cookie({"id": "root"})
|
||||
foreign_keys = (await ds_client.get(
|
||||
"/_internal/foreign_keys.json?_shape=array", cookies={"ds_actor": cookie}
|
||||
).json
|
||||
)).json()
|
||||
assert len(foreign_keys) > 5
|
||||
foreign_key = foreign_keys[0]
|
||||
assert set(foreign_key.keys()) == {
|
||||
|
|
Ładowanie…
Reference in New Issue