mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New run_sanity_checks mechanism, for SpatiLite
Moved VirtualSpatialIndex check into a new mechanism that should allow us to add further sanity checks in the future. To test this I've had to commit a binary sample SpatiaLite database to the repository. I included a build script for creating that database. Closes #466
This commit is contained in:
parent
c692cd2911
commit
da0b3ce2b7
6 changed files with 98 additions and 56 deletions
23
tests/build_small_spatialite_db.py
Normal file
23
tests/build_small_spatialite_db.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import sqlite3
|
||||
|
||||
# This script generates the spatialite.db file in our tests directory.
|
||||
|
||||
|
||||
def generate_it(filename):
|
||||
conn = sqlite3.connect(filename)
|
||||
# Lead the spatialite extension:
|
||||
conn.enable_load_extension(True)
|
||||
conn.load_extension("/usr/local/lib/mod_spatialite.dylib")
|
||||
conn.execute("select InitSpatialMetadata(1)")
|
||||
conn.executescript("create table museums (name text)")
|
||||
conn.execute("SELECT AddGeometryColumn('museums', 'point_geom', 4326, 'POINT', 2);")
|
||||
# At this point it is around 5MB - we can shrink it dramatically by doing thisO
|
||||
conn.execute("delete from spatial_ref_sys")
|
||||
conn.execute("delete from spatial_ref_sys_aux")
|
||||
conn.commit()
|
||||
conn.execute("vacuum")
|
||||
conn.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate_it("spatialite.db")
|
||||
BIN
tests/spatialite.db
Normal file
BIN
tests/spatialite.db
Normal file
Binary file not shown.
|
|
@ -1,6 +1,7 @@
|
|||
from .fixtures import app_client
|
||||
from datasette.cli import cli
|
||||
from click.testing import CliRunner
|
||||
import pathlib
|
||||
import json
|
||||
|
||||
|
||||
|
|
@ -28,3 +29,12 @@ def test_inspect_cli_writes_to_file(app_client):
|
|||
assert 0 == result.exit_code, result.output
|
||||
data = json.load(open("foo.json"))
|
||||
assert ["fixtures"] == list(data.keys())
|
||||
|
||||
|
||||
def test_spatialite_error_if_attempt_to_open_spatialite():
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli, ["serve", str(pathlib.Path(__file__).parent / "spatialite.db")]
|
||||
)
|
||||
assert result.exit_code != 0
|
||||
assert "trying to load a SpatiaLite database" in result.output
|
||||
Loading…
Add table
Add a link
Reference in a new issue