Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ def run_plan(
instrument_session: str,
parameters: TaskParameters,
) -> None:
"""Run a plan with parameters"""
"""Run a plan with parameters

To run in the foreground and block until it is complete, stomp
configuration is required. Without stomp configuration, '--bg' can be used
to start a plan in the background.
"""

client = cast(BlueapiClient, obj["client"])
task = TaskRequest(
Expand Down
48 changes: 27 additions & 21 deletions tests/unit_tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_get_plans(runner: CliRunner):

response = responses.add(
responses.GET,
"http://localhost:8000/plans",
"http://localhost:8000/api/v1/plans",
json=PlanResponse(plans=[PlanModel.from_plan(plan)]).model_dump(),
status=200,
)
Expand All @@ -176,7 +176,7 @@ def test_get_devices(runner: CliRunner):

response = responses.add(
responses.GET,
"http://localhost:8000/devices",
"http://localhost:8000/api/v1/devices",
json=DeviceResponse(devices=[DeviceModel.from_device(device)]).model_dump(),
status=200,
)
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_submit_plan(runner: CliRunner):
}

response = responses.post(
url="http://a.fake.host:12345/tasks",
url="http://a.fake.host:12345/api/v1/tasks",
match=[matchers.json_params_matcher(body_data)],
)

Expand Down Expand Up @@ -268,7 +268,7 @@ def test_submit_plan_without_stomp(runner: CliRunner):
def test_run_plan(stomp_client: StompClient, runner: CliRunner):
task_id = "abcd-1234"
submit_response = responses.post(
url="http://a.fake.host:12345/tasks",
url="http://a.fake.host:12345/api/v1/tasks",
match=[
matchers.json_params_matcher(
{
Expand All @@ -282,7 +282,7 @@ def test_run_plan(stomp_client: StompClient, runner: CliRunner):
status=201,
)
run_response = responses.put(
url="http://a.fake.host:12345/worker/task",
url="http://a.fake.host:12345/api/v1/worker/task",
match=[matchers.json_params_matcher({"task_id": task_id})],
json={"task_id": task_id},
)
Expand Down Expand Up @@ -398,7 +398,7 @@ def test_run_plan_feedback(
@responses.activate
def test_run_plan_background_without_stomp(runner: CliRunner):
submit_response = responses.post(
url="http://a.fake.host:12345/tasks",
url="http://a.fake.host:12345/api/v1/tasks",
match=[
matchers.json_params_matcher(
{
Expand All @@ -412,7 +412,7 @@ def test_run_plan_background_without_stomp(runner: CliRunner):
status=201,
)
run_response = responses.put(
url="http://a.fake.host:12345/worker/task",
url="http://a.fake.host:12345/api/v1/worker/task",
match=[matchers.json_params_matcher({"task_id": "abcd-1234"})],
json={"task_id": "abcd-1234"},
)
Expand Down Expand Up @@ -541,7 +541,7 @@ def test_get_env(runner: CliRunner):
environment_id = uuid.uuid4()
responses.add(
responses.GET,
"http://localhost:8000/environment",
"http://localhost:8000/api/v1/environment",
json=EnvironmentResponse(
environment_id=environment_id, initialized=True
).model_dump(mode="json"),
Expand All @@ -559,7 +559,10 @@ def test_get_env(runner: CliRunner):
@responses.activate
def test_get_state(runner: CliRunner):
responses.add(
responses.GET, "http://localhost:8000/worker/state", json="IDLE", status=200
responses.GET,
"http://localhost:8000/api/v1/worker/state",
json="IDLE",
status=200,
)
state = runner.invoke(main, ["controller", "state"])
print(state.stderr)
Expand All @@ -576,7 +579,7 @@ def test_reset_env_client_behavior(
environment_id = uuid.uuid4()
responses.add(
responses.DELETE,
"http://localhost:8000/environment",
"http://localhost:8000/api/v1/environment",
json=EnvironmentResponse(
environment_id=environment_id, initialized=False
).model_dump(mode="json"),
Expand All @@ -588,7 +591,7 @@ def test_reset_env_client_behavior(
for state in env_state:
responses.add(
responses.GET,
"http://localhost:8000/environment",
"http://localhost:8000/api/v1/environment",
json=EnvironmentResponse(
environment_id=environment_id, initialized=state
).model_dump(mode="json"),
Expand All @@ -604,10 +607,10 @@ def test_reset_env_client_behavior(
for index, call in enumerate(responses.calls):
if index == 0:
assert call.request.method == "DELETE"
assert call.request.url == "http://localhost:8000/environment"
assert call.request.url == "http://localhost:8000/api/v1/environment"
else:
assert call.request.method == "GET"
assert call.request.url == "http://localhost:8000/environment"
assert call.request.url == "http://localhost:8000/api/v1/environment"

# Check if the final environment status is printed correctly
# assert "Environment is initialized." in result.output
Expand All @@ -625,7 +628,7 @@ def test_env_timeout(mock_sleep: Mock, runner: CliRunner):
environment_id = uuid.uuid4()
responses.add(
responses.DELETE,
"http://localhost:8000/environment",
"http://localhost:8000/api/v1/environment",
status=200,
json=EnvironmentResponse(
environment_id=environment_id, initialized=False
Expand All @@ -634,7 +637,7 @@ def test_env_timeout(mock_sleep: Mock, runner: CliRunner):
# Add responses for each polling attempt, all indicating not initialized
responses.add(
responses.GET,
"http://localhost:8000/environment",
"http://localhost:8000/api/v1/environment",
json=EnvironmentResponse(
environment_id=environment_id, initialized=False
).model_dump(mode="json"),
Expand All @@ -655,12 +658,12 @@ def test_env_timeout(mock_sleep: Mock, runner: CliRunner):

# First call should be DELETE
assert responses.calls[0].request.method == "DELETE"
assert responses.calls[0].request.url == "http://localhost:8000/environment"
assert responses.calls[0].request.url == "http://localhost:8000/api/v1/environment"

# Remaining calls should all be GET
for call in responses.calls[1:]: # Skip the first DELETE request # type: ignore
assert call.request.method == "GET"
assert call.request.url == "http://localhost:8000/environment"
assert call.request.url == "http://localhost:8000/api/v1/environment"

# Check the output for the timeout message
assert result.output == "Reloading environment\n"
Expand All @@ -673,7 +676,10 @@ def test_env_timeout(mock_sleep: Mock, runner: CliRunner):
def test_env_reload_server_side_error(runner: CliRunner):
# Setup mocked error response from the server
responses.add(
responses.DELETE, "http://localhost:8000/environment", status=500, json={}
responses.DELETE,
"http://localhost:8000/api/v1/environment",
status=500,
json={},
)

result = runner.invoke(main, ["controller", "env", "-r"])
Expand All @@ -687,7 +693,7 @@ def test_env_reload_server_side_error(runner: CliRunner):

# Only call should be DELETE
assert responses.calls[0].request.method == "DELETE"
assert responses.calls[0].request.url == "http://localhost:8000/environment"
assert responses.calls[0].request.url == "http://localhost:8000/api/v1/environment"

# Check the output for the timeout message
# TODO this seems wrong but this is the current behaviour
Expand Down Expand Up @@ -1279,7 +1285,7 @@ def test_get_python_environment(runner: CliRunner):
}
response = responses.add(
responses.GET,
"http://localhost:8000/python_environment",
"http://localhost:8000/api/v1/python_environment",
json=scratch_config,
status=200,
)
Expand All @@ -1302,7 +1308,7 @@ def test_get_python_env_with_empty_response(runner: CliRunner):
}
response = responses.add(
responses.GET,
"http://localhost:8000/python_environment",
"http://localhost:8000/api/v1/python_environment",
json=scratch_config,
status=200,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/client/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_auth_request_functionality(
environment_id = uuid.uuid4()
mock_authn_server.stop() # Cannot use multiple RequestsMock context manager
mock_get_env = mock_authn_server.get(
"http://localhost:8000/environment",
"http://localhost:8000/api/v1/environment",
json=EnvironmentResponse(
environment_id=environment_id, initialized=True
).model_dump(mode="json"),
Expand All @@ -143,7 +143,7 @@ def test_refresh_if_signature_expired(
environment_id = uuid.uuid4()
mock_authn_server.stop() # Cannot use multiple RequestsMock context manager
mock_get_env = mock_authn_server.get(
"http://localhost:8000/environment",
"http://localhost:8000/api/v1/environment",
json=EnvironmentResponse(
environment_id=environment_id, initialized=True
).model_dump(mode="json"),
Expand Down
Loading
Loading