Skip to content

Commit e84b8ba

Browse files
committed
Allow test server to be provided externally
This adds support for an optional `DANDI_TESTS_API_URL` environment variable, which if set, will cause the integration test suite to connect to that external server and not boot up a Docker Compose stack. If `DANDI_TESTS_API_URL` is set, then `DANDI_TESTS_DJANGO_API_KEY` must also be set. This makes it possible to run the CLI integration tests more without having to build a Docker image of the API server, allowing simpler validation of any existing running server against the CLI.
1 parent 0fe03cf commit e84b8ba

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

dandi/tests/fixtures.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import Callable, Iterator
4-
from dataclasses import dataclass, field
4+
from dataclasses import dataclass, field, replace
55
from datetime import datetime, timezone
66
import logging
77
import os
@@ -373,6 +373,20 @@ def _make_subdirs_dandisets(path: Path) -> None:
373373
@pytest.fixture(scope="session")
374374
def docker_compose_setup() -> Iterator[dict[str, str]]:
375375
skipif.no_network()
376+
377+
if external_url := os.environ.get("DANDI_TESTS_API_URL"):
378+
api_key = os.environ.get("DANDI_TESTS_DJANGO_API_KEY")
379+
if not api_key:
380+
raise RuntimeError(
381+
"DANDI_TESTS_API_URL is set but DANDI_TESTS_DJANGO_API_KEY is not; "
382+
"set it to a valid admin DRF token for the externally-managed server."
383+
)
384+
known_instances["dandi-api-local-docker-tests"] = replace(
385+
known_instances["dandi-api-local-docker-tests"], api=external_url
386+
)
387+
yield {"django_api_key": api_key}
388+
return
389+
376390
skipif.no_docker_engine()
377391

378392
# Check that we're running on a Unix-based system (Linux or macOS), as the

0 commit comments

Comments
 (0)