Update title and junction test

This commit is contained in:
wqy
2022-09-24 23:30:17 +08:00
parent c7f47bf06d
commit baeef6c859
3 changed files with 29 additions and 28 deletions

View File

@@ -11,14 +11,8 @@ def get_title(name: str) -> str:
def set_title(name: str, value: str) -> ChangeSet:
old = get_title(name)
with conn[name].cursor() as cur:
sql = f"update title set value = '{value}'"
cur.execute(sql)
redo = sql.replace("'", '"')
undo = f'update title set value = "{old}"'
add_operation(name, redo, undo)
change = ChangeSet()
change.update('title', 'null', 'value')
return change
sql = f"update title set value = '{value}'"
undo = f"update title set value = ''{old}''"
write(name, sql)
add_operation(name, sql.replace("'", "''"), undo, 'set_title', API_UPDATE, 'title', '')
return get_current_change_set(name)

View File

@@ -10,7 +10,7 @@ CREATE TABLE OPERATION
, Api_Id TEXT NOT NULL
, Api_Op API_OPERATION NOT NULL
, Api_Object_Type TEXT NOT NULL
, Api_Object_Id TEXT NOT NULL -- VARCHAR(32)
, Api_Object_Id TEXT NOT NULL
, Api_Object_Properties TEXT[]
);

View File

@@ -17,7 +17,7 @@ class TestApi:
delete_project(p)
def test_project(self):
p = "test_title"
p = "test_project"
assert not have_project(p)
assert not is_project_open(p)
@@ -66,7 +66,10 @@ class TestApi:
assert get_title(p) == ""
set_title(p, "title")
change = set_title(p, "title").operations[0]
assert change['operation'] == 'update'
assert change['type'] == 'title'
assert change['id'] == ''
assert get_title(p) == "title"
set_title(p, "test")
@@ -84,22 +87,22 @@ class TestApi:
assert change_set.operations[0]['operation'] == 'add'
assert change_set.operations[0]['type'] == JUNCTION
assert change_set.operations[0]['id'] == "j0"
coord = get_junction_properties(p, 'j0')['coord']
coord = get_junction(p, 'j0')['coord']
assert coord['x'] == 0.0
assert coord['y'] == 10.0
z = get_junction_properties(p, 'j0')['elevation']
z = get_junction(p, 'j0')['elevation']
assert z == 20.0
assert get_junction_properties(p, 'j') == None
assert get_junction_properties(p, 'j0')['demand'] == None
assert get_junction_properties(p, 'j0')['demand'] == None
change_set = set_junction_demand(p, 'j0', 100.0)
assert get_junction(p, 'j') == None
assert get_junction(p, 'j0')['demand'] == None
assert get_junction(p, 'j0')['demand'] == None
change_set = set_junction(p, 'j0', {'demand': 100.0})
assert len(change_set.operations) == 1
assert change_set.operations[0]['operation'] == 'update'
assert change_set.operations[0]['type'] == JUNCTION
assert change_set.operations[0]['id'] == 'j0'
assert change_set.operations[0]['property'] == 'demand'
assert get_junction_properties(p, 'j0')['demand'] == 100.0
assert 'demand' in change_set.operations[0]['properties']
assert get_junction(p, 'j0')['demand'] == 100.0
# TODO: pattern
@@ -139,19 +142,23 @@ class TestApi:
nodes = get_nodes(p)
assert len(nodes) == 0
self.leave(p)
'''
add_junction(p, 'j1', 0.0, 0.0, 0.0)
add_junction(p, 'j2', 10.0, 10.0, 10.0)
add_junction(p, 'j3', 10.0, 10.0, 10.0)
add_pipe(p, 'p1', 'j1', 'j2')
add_pump(p, 'p2', 'j1', 'j2')
add_valve(p, 'v1', 'j2', 'j3')
assert get_junction_properties(p, 'j1')['links'] == ['p1', 'p2']
assert get_junction_properties(p, 'j2')['links'] == ['p1', 'p2', 'v1']
assert get_junction_properties(p, 'j3')['links'] == ['v1']
self.leave(p)
assert get_junction(p, 'j1')['links'] == ['p1', 'p2']
assert get_junction(p, 'j2')['links'] == ['p1', 'p2', 'v1']
assert get_junction(p, 'j3')['links'] == ['v1']
'''
'''
def test_reservoir(self):
p = "test_reservoir"
self.enter(p)
@@ -671,6 +678,6 @@ class TestApi:
assert change_set.operations[0]['id'] == "v2"
self.leave(p)
'''
if __name__ == '__main__':
pytest.main()