Skip to content
Merged
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
8 changes: 0 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ RUNNER := "docker"
compose +ARGS="up -d":
{{ RUNNER }} compose -f tests/system_tests/compose.yaml {{ARGS}}

configure-adsim: (compose "exec" "numtracker" "/app/numtracker" "client" "configure" "adsim"
"--directory" '/tmp/'
"--scan" '{instrument}-{scan_number}'
"--detector" '{instrument}-{scan_number}-{detector}'
"--number" "43")

services: compose configure-adsim

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to play havoc with muscle memory :/. Are there any docs that mention just services that will need updating?

@ZohebShaikh ZohebShaikh Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @shree-iyengar-dls look at it as she is already re writing the docs. But I did a quick search suggests that it is not mentioned in the docs


serve *OPTS:
#!/usr/bin/env bash
source tests/system_tests/.env
Expand Down
1 change: 1 addition & 0 deletions tests/system_tests/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ services:
- KC_BOOTSTRAP_ADMIN_PASSWORD=admin
- KC_BOOTSTRAP_ADMIN_USERNAME=admin
- KEYCLOAK_REALM=master
- NT_URL=http://localhost:8406/graphql
command: ["uv", "run", "/startup.py"]
depends_on:
keycloak:
Expand Down
50 changes: 46 additions & 4 deletions tests/system_tests/services/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# requires-python = ">=3.11"
# dependencies = [
# "mantelo==2.2.1",
# "requests"
# ]
# ///
"""Configure the local Keycloak instance used by the system tests."""
Expand All @@ -11,12 +12,14 @@
from functools import wraps
from typing import Any

import requests
from mantelo import KeycloakAdmin

SERVER = os.environ.get("KEYCLOAK_SERVER")
REALM = os.environ.get("KEYCLOAK_REALM")
ADMIN_USERNAME = os.environ.get("KC_BOOTSTRAP_ADMIN_USERNAME")
ADMIN_PASSWORD = os.environ.get("KC_BOOTSTRAP_ADMIN_PASSWORD")
SERVER = os.environ.get("KEYCLOAK_SERVER", "http://localhost:8081")
REALM = os.environ.get("KEYCLOAK_REALM", "master")
ADMIN_USERNAME = os.environ.get("KC_BOOTSTRAP_ADMIN_USERNAME", "admin")
ADMIN_PASSWORD = os.environ.get("KC_BOOTSTRAP_ADMIN_PASSWORD", "admin")
NT_URL = os.environ.get("NT_URL", "http://localhost:8406/graphql")

USERS = {"alice": "alice", "bob": "bob"}

Expand Down Expand Up @@ -138,6 +141,9 @@ def cleanup_components() -> None:

def create_users() -> None:
for username, password in USERS.items():
if admin.users.get(username=username):
print(f">> Skipping {username} (exists)")
continue
response, _ = admin.users.as_raw().post({"username": username, "enabled": True})
user_id = response.headers["Location"].rsplit("/", 1)[-1]
admin.users(user_id).reset_password.put(
Expand Down Expand Up @@ -229,6 +235,7 @@ def create_user_service_account_client(
def create_clients() -> None:
create_cli_client(client_id="ixx-cli-blueapi", aud="ixx-blueapi")
create_cli_client(client_id="tiled-cli", aud="tiled")
create_cli_client(client_id="numtracker", aud="numtracker")
create_web_client(
client_id="ixx-blueapi",
aud="ixx-blueapi",
Expand All @@ -254,7 +261,42 @@ def create_clients() -> None:
)


def configure_numtracker():
token_url = SERVER + "/realms/master/protocol/openid-connect/token"
response = requests.post(
token_url,
data={
"client_id": "system-test-blueapi-admin",
"client_secret": "secret",
"grant_type": "client_credentials",
},
)
response.raise_for_status()
access_token = response.json().get("access_token")

response = requests.post(
NT_URL,
json={
"query": """mutation {
configure(instrument: "adsim",
config: {directory: "/tmp/",
scan: "{instrument}-{scan_number}",
detector: "{instrument}-{scan_number}-{detector}",
scanNumber: 43}) {
scanTemplate
}
}"""
},
headers={"authorization": "Bearer " + access_token},
)
response.raise_for_status()
if response.json().get("errors") is not None:
raise Exception(response.json())
print(">> Configurated numtracker")


if __name__ == "__main__":
cleanup_components()
create_users()
create_clients()
configure_numtracker()
7 changes: 5 additions & 2 deletions tests/system_tests/test_blueapi_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def clean_existing_tasks(rest_client: BlueapiRestClient):
def reset_numtracker():
server_config = load_config(Path(_DATA_PATH, "config.yaml"))
nt_url = server_config.numtracker.url # type: ignore - if numtracker is None we should fail
requests.post(
response = requests.post(
str(nt_url),
json={
"query": f"""mutation {{
Expand All @@ -285,7 +285,10 @@ def reset_numtracker():
}}"""
},
headers={"authorization": "Bearer " + get_access_token(User.admin)},
).raise_for_status()
)
response.raise_for_status()
if response.json().get("errors") is not None:
raise Exception(response.json())
yield


Expand Down