@@ -1008,6 +1008,24 @@ def _create_test_table(db_file):
10081008 cursor .execute ('COMMIT;' )
10091009
10101010
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+
10111029def _check_test_table (db_file ):
10121030 """ Checks whether the 'test' table exists and has one row - otherwise fails with an exception. """
10131031 #con_verify = sqlite3.connect(db_file)
@@ -1662,6 +1680,7 @@ def test_report(mc):
16621680 with pytest .raises (InvalidProject ):
16631681 create_report (mc , directory , since , to , report_file )
16641682
1683+
16651684def test_project_versions_list (mc , mc2 ):
16661685 """
16671686 Test retrieving user permissions
@@ -1703,3 +1722,39 @@ def test_project_versions_list(mc, mc2):
17031722
17041723 # writer should have write access
17051724 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