Guard pipe
This commit is contained in:
@@ -19,7 +19,9 @@ def get_pipe_schema(name: str) -> dict[str, dict[str, Any]]:
|
|||||||
|
|
||||||
|
|
||||||
def get_pipe(name: str, id: str) -> dict[str, Any]:
|
def get_pipe(name: str, id: str) -> dict[str, Any]:
|
||||||
p = read(name, f"select * from pipes where id = '{id}'")
|
p = try_read(name, f"select * from pipes where id = '{id}'")
|
||||||
|
if p == None:
|
||||||
|
return {}
|
||||||
d = {}
|
d = {}
|
||||||
d['id'] = str(p['id'])
|
d['id'] = str(p['id'])
|
||||||
d['node1'] = str(p['node1'])
|
d['node1'] = str(p['node1'])
|
||||||
@@ -82,6 +84,10 @@ def set_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def set_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
def set_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_pipe(name, cs.operations[0]['id']) == {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, set_pipe_cmd(name, cs))
|
return execute_command(name, set_pipe_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
@@ -101,6 +107,10 @@ def add_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def add_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
def add_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_pipe(name, cs.operations[0]['id']) != {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, add_pipe_cmd(name, cs))
|
return execute_command(name, add_pipe_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
@@ -120,6 +130,10 @@ def delete_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def delete_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
def delete_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_pipe(name, cs.operations[0]['id']) == {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, delete_pipe_cmd(name, cs))
|
return execute_command(name, delete_pipe_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -907,6 +907,8 @@ class TestApi:
|
|||||||
assert is_junction(p, 'j3')
|
assert is_junction(p, 'j3')
|
||||||
assert is_junction(p, 'j4')
|
assert is_junction(p, 'j4')
|
||||||
|
|
||||||
|
assert get_pipe(p, 'p0') == {}
|
||||||
|
|
||||||
add_pipe(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'length': 100.0, 'diameter': 10.0, 'roughness': 0.1, 'minor_loss': 0.5, 'status': PIPE_STATUS_OPEN }))
|
add_pipe(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'length': 100.0, 'diameter': 10.0, 'roughness': 0.1, 'minor_loss': 0.5, 'status': PIPE_STATUS_OPEN }))
|
||||||
p0 = get_pipe(p, 'p0')
|
p0 = get_pipe(p, 'p0')
|
||||||
assert p0['node1'] == 'j1'
|
assert p0['node1'] == 'j1'
|
||||||
@@ -959,6 +961,8 @@ class TestApi:
|
|||||||
links = get_links(p)
|
links = get_links(p)
|
||||||
assert len(links) == 0
|
assert len(links) == 0
|
||||||
|
|
||||||
|
assert get_pipe(p, 'p0') == {}
|
||||||
|
|
||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user