Skip to content

Commit

Permalink
simplify gpkg conversion test
Browse files Browse the repository at this point in the history
  • Loading branch information
elisalle committed Jan 14, 2025
1 parent e0b8791 commit d811335
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions threedi_schema/tests/test_gpkg.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
import pytest
from sqlalchemy import text

from threedi_schema.application.schema import get_schema_version
from threedi_schema.infrastructure.spatialite_versions import get_spatialite_version


@pytest.mark.parametrize("upgrade_spatialite", [True, False])
def test_convert_to_geopackage(oldest_sqlite, upgrade_spatialite):
# if get_schema_version() < 300:
# pytest.skip("Gpkg not supported for schema < 300")
# In case the fixture changes and refers to a geopackage,
# convert_to_geopackage will be ignored because the db is already a geopackage

# Ensure that before the conversion, spatialite is used
with oldest_sqlite.session_scope() as session:
spatialite_table_exists = bool(
session.execute(
text(
"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='spatial_ref_sys';"
)
).scalar()
)

assert spatialite_table_exists

if upgrade_spatialite:
_, file_version = get_spatialite_version(oldest_sqlite)
assert file_version == 3
oldest_sqlite.schema.upgrade(revision="0229")
oldest_sqlite.schema.upgrade_spatialite_version()
_, file_version = get_spatialite_version(oldest_sqlite)
assert file_version >= 4
oldest_sqlite.schema.upgrade(upgrade_spatialite_version=True)

oldest_sqlite.schema.convert_to_geopackage()
# Ensure that after the conversion the geopackage is used
Expand All @@ -51,5 +26,6 @@ def test_convert_to_geopackage(oldest_sqlite, upgrade_spatialite):
).scalar()
)

assert gpkg_table_exists and not spatialite_table_exists
assert gpkg_table_exists
assert not spatialite_table_exists
assert oldest_sqlite.schema.validate_schema()

0 comments on commit d811335

Please sign in to comment.