Add backdrop api and test
This commit is contained in:
@@ -70,3 +70,5 @@ from .s23_options import OPTION_QUALITY_NONE, OPTION_QUALITY_CHEMICAL, OPTION_QU
|
||||
from .s23_options import get_option_schema, get_option, set_option
|
||||
|
||||
from .s24_coordinates import get_node_coord
|
||||
|
||||
from .s27_backdrop import get_backdrop_schema, get_backdrop, set_backdrop
|
||||
|
||||
26
api/s27_backdrop.py
Normal file
26
api/s27_backdrop.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from .operation import *
|
||||
|
||||
|
||||
def get_backdrop_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return { 'content' : {'type': 'str' , 'optional': False , 'readonly': False} }
|
||||
|
||||
|
||||
def get_backdrop(name: str) -> dict[str, Any]:
|
||||
e = read(name, f"select * from backdrop")
|
||||
return { 'content': e['content'] }
|
||||
|
||||
|
||||
def set_backdrop_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
old = get_backdrop(name)
|
||||
|
||||
redo_sql = f"update backdrop set content = '{cs.operations[0]['content']}' where content = '{old['content']}';"
|
||||
undo_sql = f"update backdrop set content = '{old['content']}' where content = '{cs.operations[0]['content']}';"
|
||||
|
||||
redo_cs = g_update_prefix | { 'type': 'backdrop', 'content': cs.operations[0]['content'] }
|
||||
undo_cs = g_update_prefix | { 'type': 'backdrop', 'content': old['content'] }
|
||||
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
|
||||
|
||||
def set_backdrop(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_backdrop_cache(name, cs))
|
||||
@@ -4,3 +4,5 @@ create table backdrop
|
||||
(
|
||||
content text primary key
|
||||
);
|
||||
|
||||
insert into backdrop (content) values ('');
|
||||
|
||||
@@ -2488,5 +2488,44 @@ class TestApi:
|
||||
self.leave(p)
|
||||
|
||||
|
||||
# 27 backdrop
|
||||
|
||||
|
||||
def test_backdrop(self):
|
||||
p = 'test_backdrop'
|
||||
self.enter(p)
|
||||
|
||||
assert get_backdrop(p)['content'] == ''
|
||||
|
||||
set_backdrop(p, ChangeSet({'content': 'x'}))
|
||||
assert get_backdrop(p)['content'] == 'x'
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_backdrop_op(self):
|
||||
p = 'test_backdrop_op'
|
||||
self.enter(p)
|
||||
|
||||
cs = set_backdrop(p, ChangeSet({'content': 'x'})).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'backdrop'
|
||||
assert cs['content'] == 'x'
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'backdrop'
|
||||
assert cs['content'] == ''
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
assert cs['operation'] == API_UPDATE
|
||||
assert cs['type'] == 'backdrop'
|
||||
assert cs['content'] == 'x'
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pytest.main()
|
||||
|
||||
19
tjnetwork.py
19
tjnetwork.py
@@ -530,3 +530,22 @@ def set_option(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
|
||||
def get_node_coord(name: str, node_id: str) -> dict[str, float] | None:
|
||||
return api.get_node_coord(name, node_id)
|
||||
|
||||
|
||||
############################################################
|
||||
# backdrop 27.[BACKDROP]
|
||||
############################################################
|
||||
|
||||
def get_backdrop_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return api.get_backdrop_schema(name)
|
||||
|
||||
def get_backdrop(name: str) -> dict[str, Any]:
|
||||
return api.get_backdrop(name)
|
||||
|
||||
def set_backdrop(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.set_backdrop(name, cs)
|
||||
|
||||
|
||||
############################################################
|
||||
# end 28.[END]
|
||||
############################################################
|
||||
|
||||
Reference in New Issue
Block a user