Guard pump
This commit is contained in:
@@ -13,7 +13,9 @@ def get_pump_schema(name: str) -> dict[str, dict[str, Any]]:
|
|||||||
|
|
||||||
|
|
||||||
def get_pump(name: str, id: str) -> dict[str, Any]:
|
def get_pump(name: str, id: str) -> dict[str, Any]:
|
||||||
p = read(name, f"select * from pumps where id = '{id}'")
|
p = try_read(name, f"select * from pumps 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'])
|
||||||
@@ -73,6 +75,10 @@ def set_pump_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def set_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
def set_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_pump(name, cs.operations[0]['id']) == {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, set_pump_cmd(name, cs))
|
return execute_command(name, set_pump_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
@@ -92,6 +98,10 @@ def add_pump_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def add_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
def add_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_pump(name, cs.operations[0]['id']) != {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, add_pump_cmd(name, cs))
|
return execute_command(name, add_pump_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
@@ -111,6 +121,10 @@ def delete_pump_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|||||||
|
|
||||||
|
|
||||||
def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
||||||
|
if 'id' not in cs.operations[0]:
|
||||||
|
return ChangeSet()
|
||||||
|
if get_pump(name, cs.operations[0]['id']) == {}:
|
||||||
|
return ChangeSet()
|
||||||
return execute_command(name, delete_pump_cmd(name, cs))
|
return execute_command(name, delete_pump_cmd(name, cs))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1156,6 +1156,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_pump(p, 'p0') == {}
|
||||||
|
|
||||||
add_pump(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'power': 0.0}))
|
add_pump(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'power': 0.0}))
|
||||||
p0 = get_pump(p, 'p0')
|
p0 = get_pump(p, 'p0')
|
||||||
assert p0['node1'] == 'j1'
|
assert p0['node1'] == 'j1'
|
||||||
@@ -1191,6 +1193,8 @@ class TestApi:
|
|||||||
links = get_links(p)
|
links = get_links(p)
|
||||||
assert len(links) == 0
|
assert len(links) == 0
|
||||||
|
|
||||||
|
assert get_pump(p, 'p0') == {}
|
||||||
|
|
||||||
self.leave(p)
|
self.leave(p)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user