Skip to content

Commit 39a1662

Browse files
authored
Merge pull request #76 from dmgav/trim-history
Trim history
2 parents 445ae9a + 253f283 commit 39a1662

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

bluesky_httpserver/tests/test_core_api_main.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,56 @@ def test_http_server_plan_history(re_manager, fastapi_server): # noqa F811
12351235
assert resp3["items"] == []
12361236

12371237

1238+
# fmt: off
1239+
@pytest.mark.parametrize("clear_params, exp_size", [
1240+
({}, 0),
1241+
({"size": 2}, 2),
1242+
({"item_uid": 1}, 2),
1243+
({"item_uid": -1}, 4),
1244+
])
1245+
# fmt: on
1246+
def test_http_server_history_clear(re_manager, fastapi_server, clear_params, exp_size): # noqa F811
1247+
"""
1248+
Test for ``/history/clear`` API with all parameters.
1249+
"""
1250+
clear_params = copy.deepcopy(clear_params) # The dictionary is modified during the test
1251+
1252+
# Select very short plan
1253+
plan = {"item": {"name": "count", "args": [["det1", "det2"]], "item_type": "plan"}}
1254+
request_to_json("post", "/queue/item/add", json=plan)
1255+
request_to_json("post", "/queue/item/add", json=plan)
1256+
request_to_json("post", "/queue/item/add", json=plan)
1257+
request_to_json("post", "/queue/item/add", json=plan)
1258+
1259+
request_to_json("post", "/environment/open")
1260+
assert wait_for_environment_to_be_created(10), "Timeout"
1261+
1262+
request_to_json("post", "/queue/start")
1263+
assert wait_for_queue_execution_to_complete(10), "Timeout"
1264+
1265+
request_to_json("post", "/environment/close")
1266+
assert wait_for_environment_to_be_closed(10), "Timeout"
1267+
1268+
resp1 = request_to_json("get", "/history/get")
1269+
history = resp1["items"]
1270+
assert len(history) == 4
1271+
1272+
uids = [_["item_uid"] for _ in history]
1273+
if "item_uid" in clear_params:
1274+
n = clear_params["item_uid"]
1275+
if n >= 0:
1276+
clear_params["item_uid"] = uids[n]
1277+
else:
1278+
clear_params["item_uid"] = "non-existing-uid"
1279+
1280+
resp2 = request_to_json("post", "/history/clear", json=clear_params)
1281+
assert resp2["success"] is True
1282+
1283+
resp3 = request_to_json("get", "/history/get")
1284+
history2 = resp3["items"]
1285+
assert len(history2) == exp_size
1286+
1287+
12381288
def test_http_server_manager_kill(re_manager, fastapi_server): # noqa F811
12391289
request_to_json("post", "/environment/open")
12401290
assert wait_for_environment_to_be_created(10), "Timeout"

0 commit comments

Comments
 (0)