@@ -1008,6 +1008,24 @@ def _create_test_table(db_file):
1008
1008
cursor .execute ('COMMIT;' )
1009
1009
1010
1010
1011
+ def _create_spatial_table (db_file ):
1012
+ """ Creates a spatial table called 'test' in sqlite database. Useful to simulate change of database schema. """
1013
+ con = sqlite3 .connect (db_file )
1014
+ cursor = con .cursor ()
1015
+ cursor .execute ('CREATE TABLE geo_test (fid SERIAL, geometry POINT NOT NULL, txt TEXT);' )
1016
+ cursor .execute ('INSERT INTO gpkg_contents VALUES (\' geo_test\' , \' features\' ,\' description\' ,\' geo_test\' ,\' 2019-06-18T14:52:50.928Z\' ,-1.08892,0.0424077,-0.363885,0.562244,4326);' )
1017
+ cursor .execute ('INSERT INTO gpkg_geometry_columns VALUES (\' geo_test\' ,\' geometry\' ,\' POINT\' ,4326, 0, 0 )' )
1018
+ cursor .execute ('COMMIT;' )
1019
+
1020
+ def _delete_spatial_table (db_file ):
1021
+ """ Drops spatial table called 'test' in sqlite database. Useful to simulate change of database schema. """
1022
+ con = sqlite3 .connect (db_file )
1023
+ cursor = con .cursor ()
1024
+ cursor .execute ('DROP TABLE poi;' )
1025
+ cursor .execute ('DELETE FROM gpkg_geometry_columns WHERE table_name=\' poi\' ;' )
1026
+ cursor .execute ('DELETE FROM gpkg_contents WHERE table_name=\' poi\' ;' )
1027
+ cursor .execute ('COMMIT;' )
1028
+
1011
1029
def _check_test_table (db_file ):
1012
1030
""" Checks whether the 'test' table exists and has one row - otherwise fails with an exception. """
1013
1031
#con_verify = sqlite3.connect(db_file)
@@ -1662,6 +1680,7 @@ def test_report(mc):
1662
1680
with pytest .raises (InvalidProject ):
1663
1681
create_report (mc , directory , since , to , report_file )
1664
1682
1683
+
1665
1684
def test_project_versions_list (mc , mc2 ):
1666
1685
"""
1667
1686
Test retrieving user permissions
@@ -1703,3 +1722,39 @@ def test_project_versions_list(mc, mc2):
1703
1722
1704
1723
# writer should have write access
1705
1724
assert mc2 .has_writing_permissions (test_project_fullname )
1725
+
1726
+
1727
+ def test_report_failure (mc ):
1728
+ """Check that report generated without errors when a table was added
1729
+ and then deleted.
1730
+ """
1731
+ test_project = 'test_report_failure'
1732
+ project = API_USER + '/' + test_project
1733
+ project_dir = os .path .join (TMP_DIR , test_project ) # primary project dir
1734
+ test_gpkg = os .path .join (project_dir , 'test.gpkg' )
1735
+ report_file = os .path .join (TMP_DIR , "report.csv" )
1736
+
1737
+ cleanup (mc , project , [project_dir ])
1738
+
1739
+ os .makedirs (project_dir )
1740
+ shutil .copy (os .path .join (TEST_DATA_DIR , 'base.gpkg' ), test_gpkg )
1741
+ mc .create_project_and_push (test_project , project_dir )
1742
+
1743
+ shutil .copy (os .path .join (TEST_DATA_DIR , 'inserted_1_A.gpkg' ), test_gpkg )
1744
+ mc .push_project (project_dir )
1745
+
1746
+ # add a new table to the geopackage
1747
+ shutil .copy (os .path .join (TEST_DATA_DIR , 'two_tables.gpkg' ), test_gpkg )
1748
+ mc .push_project (project_dir )
1749
+
1750
+ shutil .copy (os .path .join (TEST_DATA_DIR , 'two_tables_1_A.gpkg' ), test_gpkg )
1751
+ mc .push_project (project_dir )
1752
+
1753
+ warnings = create_report (mc , project_dir , "v1" , "v4" , report_file )
1754
+ assert warnings
1755
+
1756
+ shutil .copy (os .path .join (TEST_DATA_DIR , 'two_tables_drop.gpkg' ), test_gpkg )
1757
+ mc .push_project (project_dir )
1758
+
1759
+ warnings = create_report (mc , project_dir , "v1" , "v5" , report_file )
1760
+ assert warnings
0 commit comments