Skip to content

Commit

Permalink
Add CI job to run system tests (#761)
Browse files Browse the repository at this point in the history
Fixes #630
  • Loading branch information
callumforrester authored Dec 17, 2024
1 parent 86d9470 commit cdfedb4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/_system_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
workflow_call:

env:
# https://github.com/pytest-dev/pytest/issues/2042
PY_IGNORE_IMPORTMISMATCH: "1"

jobs:
run:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Need this to get version number from last tag
fetch-depth: 0

- name: Install python packages
uses: ./.github/actions/install_requirements

- name: Start RabbitMQ
uses: namoshek/rabbitmq-github-action@v1
with:
ports: "61613:61613"
plugins: rabbitmq_stomp

- name: Start Blueapi Server
run: blueapi -c ${{ github.workspace }}/tests/unit_tests/example_yaml/valid_stomp_config.yaml serve &

- name: Run tests
run: tox -e system-test
3 changes: 0 additions & 3 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ on:
env:
# https://github.com/pytest-dev/pytest/issues/2042
PY_IGNORE_IMPORTMISMATCH: "1"
BLUEAPI_TEST_STOMP_PORTS: "[61613,61614]"



jobs:
run:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

system-test:
needs: check
if: needs.check.outputs.branch-pr == ''
uses: ./.github/workflows/_system_test.yml

container:
needs: check
if: needs.check.outputs.branch-pr == ''
Expand Down
26 changes: 25 additions & 1 deletion tests/system_tests/test_blueapi_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from bluesky_stomp.models import BasicAuthentication
from pydantic import TypeAdapter
from requests.exceptions import ConnectionError

from blueapi.client.client import (
BlueapiClient,
Expand Down Expand Up @@ -32,6 +33,13 @@

_DATA_PATH = Path(__file__).parent

_REQUIRES_AUTH_MESSAGE = """
Authentication credentials are required to run this test.
The test has been skipped because authentication is currently disabled.
For more details, see: https://github.com/DiamondLightSource/blueapi/issues/676.
To enable and execute these tests, set `REQUIRES_AUTH=1` and provide valid credentials.
"""

# Step 1: Ensure a message bus that supports stomp is running and available:
# src/script/start_rabbitmq.sh
#
Expand All @@ -43,7 +51,7 @@


@pytest.fixture
def client_without_auth(tmp_path) -> BlueapiClient:
def client_without_auth(tmp_path: Path) -> BlueapiClient:
return BlueapiClient.from_config(config=ApplicationConfig(auth_token_path=tmp_path))


Expand All @@ -58,6 +66,20 @@ def client_with_stomp() -> BlueapiClient:
)


@pytest.fixture(scope="module", autouse=True)
def wait_for_server():
client = BlueapiClient.from_config(config=ApplicationConfig())

for _ in range(20):
try:
client.get_environment()
return
except ConnectionError:
...
time.sleep(0.5)
raise TimeoutError("No connection to the blueapi server")


# This client will have auth enabled if it finds cached valid token
@pytest.fixture
def client() -> BlueapiClient:
Expand Down Expand Up @@ -101,6 +123,7 @@ def clean_existing_tasks(client: BlueapiClient):
yield


@pytest.mark.xfail(reason=_REQUIRES_AUTH_MESSAGE)
def test_cannot_access_endpoints(
client_without_auth: BlueapiClient, blueapi_client_get_methods: list[str]
):
Expand All @@ -112,6 +135,7 @@ def test_cannot_access_endpoints(
getattr(client_without_auth, get_method)()


@pytest.mark.xfail(reason=_REQUIRES_AUTH_MESSAGE)
def test_can_get_oidc_config_without_auth(client_without_auth: BlueapiClient):
assert client_without_auth.get_oidc_config() == OIDCConfig(
well_known_url="https://example.com/realms/master/.well-known/openid-configuration",
Expand Down

0 comments on commit cdfedb4

Please sign in to comment.