Return status. Handle double calls.

This commit is contained in:
Chris Amico 2022-01-18 09:59:03 -05:00
commit 0df57367e9
3 changed files with 55 additions and 11 deletions

View file

@ -70,6 +70,28 @@ def test_add_geometry_column():
reason="sqlite3.Connection missing enable_load_extension",
)
def test_create_spatial_index():
db = Database(memory=True)
spatialite = gis.find_spatialite()
assert gis.init_spatialite(db, spatialite)
# create a table, add a geometry column with default values
db.create_table("locations", {"id": str, "properties": str})
assert gis.add_geometry_column(db["locations"], "Point", "geometry")
# index it
assert gis.create_spatial_index(db["locations"], "geometry")
assert "idx_locations_geometry" in db.table_names()
@pytest.mark.skipif(
not gis.find_spatialite(), reason="Could not find SpatiaLite extension"
)
@pytest.mark.skipif(
not hasattr(sqlite3.Connection, "enable_load_extension"),
reason="sqlite3.Connection missing enable_load_extension",
)
def test_double_create_spatial_index():
db = Database(memory=True)
spatialite = gis.find_spatialite()
gis.init_spatialite(db, spatialite)
@ -78,7 +100,10 @@ def test_create_spatial_index():
db.create_table("locations", {"id": str, "properties": str})
gis.add_geometry_column(db["locations"], "Point", "geometry")
# index it
gis.create_spatial_index(db["locations"], "geometry")
# index it, return True
assert gis.create_spatial_index(db["locations"], "geometry")
assert "idx_locations_geometry" in db.table_names()
# call it again, return False
assert not gis.create_spatial_index(db["locations"], "geometry")