From c3ae9b306f705e191bf1da0e30884cbfd07d0596 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Fri, 24 Feb 2023 13:46:19 +0800 Subject: [PATCH] Fix snapshot api and test --- api/database.py | 4 ++-- test_tjnetwork.py | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/api/database.py b/api/database.py index 474bf18..3e17798 100644 --- a/api/database.py +++ b/api/database.py @@ -180,12 +180,12 @@ def take_snapshot_for_operation(name: str, operation: int, tag: str) -> None: write(name, f"insert into snapshot_operation (id, tag) values ({operation}, '{tag}')") -def take_snapshot_for_current_operation(name: str, tag: str) -> int | None: +def take_snapshot_for_current_operation(name: str, tag: str) -> None: take_snapshot_for_operation(name, get_current_operation(name), tag) # deprecated ! use take_snapshot_for_current_operation instead -def take_snapshot(name: str, tag: str) -> int | None: +def take_snapshot(name: str, tag: str) -> None: take_snapshot_for_current_operation(name, tag) diff --git a/test_tjnetwork.py b/test_tjnetwork.py index 18a4310..837513b 100644 --- a/test_tjnetwork.py +++ b/test_tjnetwork.py @@ -77,18 +77,26 @@ class TestApi: add_junction(p, ChangeSet({'id': 'j3', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})) add_junction(p, ChangeSet({'id': 'j4', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})) - client_op = get_current_operation(p) - assert client_op == 4 - assert take_snapshot(p, 'x') == 4 + op_4 = get_current_operation(p) + assert op_4 == 4 + take_snapshot(p, 'x') + assert get_snapshot_by_operation(p, 4) == 'x' + assert get_operation_by_snapshot(p, 'x') == 4 + update_snapshot_for_current_operation(p, 'y') + assert get_snapshot_by_operation(p, 4) == 'y' execute_undo(p) execute_undo(p) add_junction(p, ChangeSet({'id': 'j5', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})) add_junction(p, ChangeSet({'id': 'j6', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})) - assert take_snapshot(p, 'xx') == 6 + op_6 = get_current_operation(p) + assert op_6 == 6 + take_snapshot(p, 'xx') + assert get_snapshot_by_operation(p, 6) == 'xx' + assert get_operation_by_snapshot(p, 'xx') == 6 - cs = sync_with_server(p, client_op).operations + cs = sync_with_server(p, op_4).operations cs[0]['operation'] = API_DELETE cs[0]['id'] = 'j4' cs[1]['operation'] = API_DELETE @@ -98,7 +106,7 @@ class TestApi: cs[3]['operation'] = API_ADD cs[3]['id'] = 'j6' - cs = pick_snapshot(p, 'x').operations + cs = pick_snapshot(p, 'y').operations cs[0]['operation'] = 'delete' cs[0]['id'] = 'j6' cs[1]['operation'] = 'delete'