Guard junction
This commit is contained in:
@@ -12,7 +12,9 @@ def get_junction_schema(name: str) -> dict[str, dict[str, Any]]:
|
|||||||
|
|
||||||
|
|
||||||
def get_junction(name: str, id: str) -> dict[str, Any]:
|
def get_junction(name: str, id: str) -> dict[str, Any]:
|
||||||
j = read(name, f"select * from junctions where id = '{id}'")
|
j = try_read(name, f"select * from junctions where id = '{id}'")
|
||||||
|
if j == None:
|
||||||
|
return {}
|
||||||
xy = get_node_coord(name, id)
|
xy = get_node_coord(name, id)
|
||||||
d = {}
|
d = {}
|
||||||
d['id'] = str(j['id'])
|
d['id'] = str(j['id'])
|
||||||
@@ -67,6 +69,10 @@ def set_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def set_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
def set_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_junction(name, cs.operations[0]['id']) == {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, set_junction_cmd(name, cs))
|
return execute_command(name, set_junction_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
@@ -88,6 +94,10 @@ def add_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def add_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
def add_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_junction(name, cs.operations[0]['id']) != {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, add_junction_cmd(name, cs))
|
return execute_command(name, add_junction_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
@@ -109,6 +119,10 @@ def delete_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_junction(name, cs.operations[0]['id']) == {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, delete_junction_cmd(name, cs))
|
return execute_command(name, delete_junction_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -249,6 +249,8 @@ class TestApi:
|
|||||||
p = 'test_junction'
|
p = 'test_junction'
|
||||||
self.enter(p)
|
self.enter(p)
|
||||||
|
|
||||||
|
assert get_junction(p, 'j0') == {}
|
||||||
|
|
||||||
add_junction(p, ChangeSet({'id': 'j0', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
add_junction(p, ChangeSet({'id': 'j0', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
j0 = get_junction(p, 'j0')
|
j0 = get_junction(p, 'j0')
|
||||||
assert j0['x'] == 0.0
|
assert j0['x'] == 0.0
|
||||||
@@ -284,6 +286,8 @@ class TestApi:
|
|||||||
nodes = get_nodes(p)
|
nodes = get_nodes(p)
|
||||||
assert len(nodes) == 0
|
assert len(nodes) == 0
|
||||||
|
|
||||||
|
assert get_junction(p, 'j0') == {}
|
||||||
|
|
||||||
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
add_junction(p, ChangeSet({'id': 'j3', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
add_junction(p, ChangeSet({'id': 'j3', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
|
||||||
|
|||||||
Reference in New Issue
Block a user