|
13 | 13 | MerginClient,
|
14 | 14 | )
|
15 | 15 |
|
16 |
| -from dbsync import dbsync_pull, dbsync_push, config, DbSyncError |
| 16 | +from dbsync import dbsync_pull, dbsync_push, config, DbSyncError, dbsync_init |
17 | 17 |
|
18 | 18 | from .conftest import (
|
19 | 19 | GEODIFF_EXE,
|
@@ -148,3 +148,65 @@ def test_missing_table(mc: MerginClient):
|
148 | 148 | init_sync_from_db(mc, project_name, path_test_data("create_another_schema.sql"))
|
149 | 149 |
|
150 | 150 | assert "The 'modified' schema does not exist" in str(err.value)
|
| 151 | + |
| 152 | + |
| 153 | +def test_mm_project_change(mc: MerginClient, db_connection): |
| 154 | + """Test that after init and local changes the changes are correctly pushed to database""" |
| 155 | + project_name = "test_project_change" |
| 156 | + project_full_name = complete_project_name(project_name) |
| 157 | + project_dir = name_project_dir(project_name) |
| 158 | + db_schema_main = "test_init_from_db_main" |
| 159 | + db_schema_base = "test_init_from_db_base" |
| 160 | + |
| 161 | + path_synced_gpkg = project_dir + "/" + filename_sync_gpkg() |
| 162 | + |
| 163 | + init_sync_from_db(mc, project_name, path_test_data("create_base.sql")) |
| 164 | + |
| 165 | + cur = db_connection.cursor() |
| 166 | + |
| 167 | + # check that there are 3 features prior to changes |
| 168 | + cur.execute(f'SELECT COUNT(*) from {db_schema_main}."simple"') |
| 169 | + assert cur.fetchone()[0] == 3 |
| 170 | + |
| 171 | + mc.download_project(project_full_name, project_dir) |
| 172 | + |
| 173 | + # make changes in GPKG to create new version of the project |
| 174 | + shutil.copy(path_test_data("inserted_point_from_db.gpkg"), path_synced_gpkg) |
| 175 | + |
| 176 | + # push project |
| 177 | + mc.push_project(project_dir) |
| 178 | + |
| 179 | + # run sync |
| 180 | + dbsync_pull(mc) |
| 181 | + dbsync_push(mc) |
| 182 | + |
| 183 | + # check that new feature was added |
| 184 | + cur.execute(f'SELECT COUNT(*) from {db_schema_main}."simple"') |
| 185 | + assert cur.fetchone()[0] == 4 |
| 186 | + |
| 187 | + project_name = "test_project_change_2" |
| 188 | + project_full_name = complete_project_name(project_name) |
| 189 | + project_dir = name_project_dir(project_name) |
| 190 | + mc.create_project_and_push(project_full_name, project_dir) |
| 191 | + |
| 192 | + # change config to new project |
| 193 | + config.update( |
| 194 | + { |
| 195 | + "CONNECTIONS": [ |
| 196 | + { |
| 197 | + "driver": "postgres", |
| 198 | + "conn_info": DB_CONNINFO, |
| 199 | + "modified": db_schema_main, |
| 200 | + "base": db_schema_base, |
| 201 | + "mergin_project": project_full_name, |
| 202 | + "sync_file": filename_sync_gpkg(), |
| 203 | + } |
| 204 | + ] |
| 205 | + } |
| 206 | + ) |
| 207 | + |
| 208 | + # run init |
| 209 | + with pytest.raises( |
| 210 | + DbSyncError, match="Mergin Maps project ID doesn't match Mergin Maps project ID stored in the database" |
| 211 | + ): |
| 212 | + dbsync_init(mc) |
0 commit comments