Don't show hidden tables on index page, closes #455

Refs #460. Also bulked out HTML index page unit tests.
This commit is contained in:
Simon Willison 2019-05-14 08:46:57 -07:00
commit e04511410f
3 changed files with 68 additions and 6 deletions

View file

@ -30,14 +30,26 @@ def make_app_client(
config=None,
filename="fixtures.db",
is_immutable=False,
extra_databases=None,
):
with tempfile.TemporaryDirectory() as tmpdir:
filepath = os.path.join(tmpdir, filename)
if is_immutable:
files = []
immutables = [filepath]
else:
files = [filepath]
immutables = []
conn = sqlite3.connect(filepath)
conn.executescript(TABLES)
for sql, params in TABLE_PARAMETERIZED_SQL:
with conn:
conn.execute(sql, params)
if extra_databases is not None:
for extra_filename, extra_sql in extra_databases.items():
extra_filepath = os.path.join(tmpdir, extra_filename)
sqlite3.connect(extra_filepath).executescript(extra_sql)
files.append(extra_filepath)
os.chdir(os.path.dirname(filepath))
plugins_dir = os.path.join(tmpdir, "plugins")
os.mkdir(plugins_dir)
@ -52,8 +64,8 @@ def make_app_client(
}
)
ds = Datasette(
[] if is_immutable else [filepath],
immutables=[filepath] if is_immutable else [],
files,
immutables=immutables,
memory=memory,
cors=cors,
metadata=METADATA,
@ -79,6 +91,13 @@ def app_client_no_files():
yield client
@pytest.fixture(scope="session")
def app_client_two_attached_databases():
yield from make_app_client(
extra_databases={"extra_database.db": EXTRA_DATABASE_SQL}
)
@pytest.fixture(scope="session")
def app_client_with_memory():
yield from make_app_client(memory=True)
@ -586,6 +605,22 @@ TABLE_PARAMETERIZED_SQL = [
("insert into binary_data (data) values (?);", [b"this is binary data"])
]
EXTRA_DATABASE_SQL = """
CREATE TABLE searchable (
pk integer primary key,
text1 text,
text2 text
);
INSERT INTO searchable VALUES (1, 'barry cat', 'terry dog');
INSERT INTO searchable VALUES (2, 'terry dog', 'sara weasel');
CREATE VIRTUAL TABLE "searchable_fts"
USING FTS3 (text1, text2, content="searchable");
INSERT INTO "searchable_fts" (rowid, text1, text2)
SELECT rowid, text1, text2 FROM searchable;
"""
if __name__ == "__main__":
# Can be called with data.db OR data.db metadata.json
arg_index = -1