@@ -1764,3 +1764,50 @@ def test_report_failure(mc):
17641764
17651765 warnings = create_report (mc , project_dir , "v1" , "v5" , report_file )
17661766 assert warnings
1767+
1768+
1769+ def test_changesets_download (mc ):
1770+ """Check that downloading diffs works correctly, including case when
1771+ changesets are cached.
1772+ """
1773+ test_project = 'test_changesets_download'
1774+ project = API_USER + '/' + test_project
1775+ project_dir = os .path .join (TMP_DIR , test_project ) # primary project dir
1776+ test_gpkg = 'test.gpkg'
1777+ file_path = os .path .join (project_dir , 'test.gpkg' )
1778+ download_dir = os .path .join (TMP_DIR , "changesets" )
1779+
1780+ cleanup (mc , project , [project_dir ])
1781+
1782+ os .makedirs (project_dir , exist_ok = True )
1783+ shutil .copy (os .path .join (TEST_DATA_DIR , 'base.gpkg' ), file_path )
1784+ mc .create_project_and_push (test_project , project_dir )
1785+
1786+ shutil .copy (os .path .join (TEST_DATA_DIR , 'inserted_1_A.gpkg' ), file_path )
1787+ mc .push_project (project_dir )
1788+
1789+ shutil .copy (os .path .join (TEST_DATA_DIR , 'inserted_1_A_mod.gpkg' ), file_path )
1790+ mc .push_project (project_dir )
1791+
1792+ mp = MerginProject (project_dir )
1793+
1794+ os .makedirs (download_dir , exist_ok = True )
1795+ diff_file = os .path .join (download_dir , "base-v1-2.diff" )
1796+ mc .get_file_diff (project_dir , test_gpkg , diff_file , "v1" , "v2" )
1797+ assert os .path .exists (diff_file )
1798+ assert mp .geodiff .has_changes (diff_file )
1799+ assert mp .geodiff .changes_count (diff_file ) == 1
1800+
1801+ diff_file = os .path .join (download_dir , "base-v2-3.diff" )
1802+ mc .get_file_diff (project_dir , test_gpkg , diff_file , "v2" , "v3" )
1803+ assert os .path .exists (diff_file )
1804+ assert mp .geodiff .has_changes (diff_file )
1805+ assert mp .geodiff .changes_count (diff_file ) == 2
1806+
1807+ # even if changesets were cached and were not downloaded destination
1808+ # file should be created and contain a valid changeset
1809+ diff_file = os .path .join (download_dir , "base-all.diff" )
1810+ mc .get_file_diff (project_dir , test_gpkg , diff_file , "v1" , "v3" )
1811+ assert os .path .exists (diff_file )
1812+ assert mp .geodiff .has_changes (diff_file )
1813+ assert mp .geodiff .changes_count (diff_file ) == 3
0 commit comments