Skip to content

Commit 2ead57e

Browse files
committed
test that changing project raises correct error
1 parent 373c2c3 commit 2ead57e

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

test/test_init_db.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
MerginClient,
1414
)
1515

16-
from dbsync import dbsync_pull, dbsync_push, config, DbSyncError
16+
from dbsync import dbsync_pull, dbsync_push, config, DbSyncError, dbsync_init
1717

1818
from .conftest import (
1919
GEODIFF_EXE,
@@ -148,3 +148,65 @@ def test_missing_table(mc: MerginClient):
148148
init_sync_from_db(mc, project_name, path_test_data("create_another_schema.sql"))
149149

150150
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

Comments
 (0)