kopia lustrzana https://github.com/simonw/datasette
Refactored generated_columns test, no longer in fixtures.db - refs #1391
rodzic
83f6799a96
commit
2e8d924cdc
|
@ -1,5 +1,5 @@
|
|||
from datasette.app import Datasette
|
||||
from datasette.utils.sqlite import sqlite3, sqlite_version, supports_generated_columns
|
||||
from datasette.utils.sqlite import sqlite3, sqlite_version
|
||||
from datasette.utils.testing import TestClient
|
||||
import click
|
||||
import contextlib
|
||||
|
@ -118,8 +118,6 @@ def make_app_client(
|
|||
immutables = []
|
||||
conn = sqlite3.connect(filepath)
|
||||
conn.executescript(TABLES)
|
||||
if supports_generated_columns():
|
||||
conn.executescript(GENERATED_COLUMNS_SQL)
|
||||
for sql, params in TABLE_PARAMETERIZED_SQL:
|
||||
with conn:
|
||||
conn.execute(sql, params)
|
||||
|
@ -720,18 +718,6 @@ INSERT INTO "searchable_fts" (rowid, text1, text2)
|
|||
SELECT rowid, text1, text2 FROM searchable;
|
||||
"""
|
||||
|
||||
GENERATED_COLUMNS_SQL = """
|
||||
CREATE TABLE generated_columns (
|
||||
body TEXT,
|
||||
id INT GENERATED ALWAYS AS (json_extract(body, '$.number')) STORED,
|
||||
consideration INT GENERATED ALWAYS AS (json_extract(body, '$.string')) STORED
|
||||
);
|
||||
INSERT INTO generated_columns (body) VALUES ('{
|
||||
"number": 1,
|
||||
"string": "This is a string"
|
||||
}');
|
||||
"""
|
||||
|
||||
|
||||
def assert_permissions_checked(datasette, actions):
|
||||
# actions is a list of "action" or (action, resource) tuples
|
||||
|
@ -792,9 +778,6 @@ def cli(db_filename, metadata, plugins_path, recreate, extra_db_filename):
|
|||
for sql, params in TABLE_PARAMETERIZED_SQL:
|
||||
with conn:
|
||||
conn.execute(sql, params)
|
||||
if supports_generated_columns():
|
||||
with conn:
|
||||
conn.executescript(GENERATED_COLUMNS_SQL)
|
||||
print(f"Test tables written to {db_filename}")
|
||||
if metadata:
|
||||
with open(metadata, "w") as fp:
|
||||
|
|
|
@ -20,7 +20,6 @@ from .fixtures import ( # noqa
|
|||
generate_compound_rows,
|
||||
generate_sortable_rows,
|
||||
make_app_client,
|
||||
supports_generated_columns,
|
||||
EXPECTED_PLUGINS,
|
||||
METADATA,
|
||||
)
|
||||
|
@ -38,7 +37,7 @@ def test_homepage(app_client):
|
|||
assert response.json.keys() == {"fixtures": 0}.keys()
|
||||
d = response.json["fixtures"]
|
||||
assert d["name"] == "fixtures"
|
||||
assert d["tables_count"] == 25 if supports_generated_columns() else 24
|
||||
assert d["tables_count"] == 24
|
||||
assert len(d["tables_and_views_truncated"]) == 5
|
||||
assert d["tables_and_views_more"] is True
|
||||
# 4 hidden FTS tables + no_primary_key (hidden in metadata)
|
||||
|
@ -271,22 +270,7 @@ def test_database_page(app_client):
|
|||
},
|
||||
"private": False,
|
||||
},
|
||||
] + (
|
||||
[
|
||||
{
|
||||
"columns": ["body", "id", "consideration"],
|
||||
"count": 1,
|
||||
"foreign_keys": {"incoming": [], "outgoing": []},
|
||||
"fts_table": None,
|
||||
"hidden": False,
|
||||
"name": "generated_columns",
|
||||
"primary_keys": [],
|
||||
"private": False,
|
||||
}
|
||||
]
|
||||
if supports_generated_columns()
|
||||
else []
|
||||
) + [
|
||||
] + [
|
||||
{
|
||||
"name": "infinity",
|
||||
"columns": ["value"],
|
||||
|
@ -2074,8 +2058,22 @@ def test_paginate_using_link_header(app_client, qs):
|
|||
sqlite_version() < (3, 31, 0),
|
||||
reason="generated columns were added in SQLite 3.31.0",
|
||||
)
|
||||
def test_generated_columns_are_visible_in_datasette(app_client):
|
||||
response = app_client.get("/fixtures/generated_columns.json?_shape=array")
|
||||
def test_generated_columns_are_visible_in_datasette():
|
||||
with make_app_client(
|
||||
extra_databases={
|
||||
"generated.db": """
|
||||
CREATE TABLE generated_columns (
|
||||
body TEXT,
|
||||
id INT GENERATED ALWAYS AS (json_extract(body, '$.number')) STORED,
|
||||
consideration INT GENERATED ALWAYS AS (json_extract(body, '$.string')) STORED
|
||||
);
|
||||
INSERT INTO generated_columns (body) VALUES ('{
|
||||
"number": 1,
|
||||
"string": "This is a string"
|
||||
}');"""
|
||||
}
|
||||
) as client:
|
||||
response = app_client.get("/generated/generated_columns.json?_shape=array")
|
||||
assert response.json == [
|
||||
{
|
||||
"rowid": 1,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Tests for the datasette.database.Database class
|
||||
"""
|
||||
from datasette.database import Database, Results, MultipleValues
|
||||
from datasette.utils.sqlite import sqlite3, supports_generated_columns
|
||||
from datasette.utils.sqlite import sqlite3
|
||||
from datasette.utils import Column
|
||||
from .fixtures import app_client, app_client_two_attached_databases_crossdb_enabled
|
||||
import pytest
|
||||
|
@ -340,9 +340,7 @@ async def test_get_all_foreign_keys(db):
|
|||
@pytest.mark.asyncio
|
||||
async def test_table_names(db):
|
||||
table_names = await db.table_names()
|
||||
assert (
|
||||
table_names
|
||||
== [
|
||||
assert table_names == [
|
||||
"simple_primary_key",
|
||||
"primary_key_multiple_columns",
|
||||
"primary_key_multiple_columns_explicit_label",
|
||||
|
@ -374,8 +372,6 @@ async def test_table_names(db):
|
|||
"attraction_characteristic",
|
||||
"roadside_attraction_characteristics",
|
||||
]
|
||||
+ (["generated_columns"] if supports_generated_columns() else [])
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
Ładowanie…
Reference in New Issue