skipcheck

TM1 Testcontainers · Docs · Containers

Tm1ServerContainer

from skipcheck_tm1_testcontainers import Tm1ServerContainer

Used in the walkthrough Test your code against a real TM1.

A TM1 server in Docker, for tests, built on the tm1-server image.

The image contains no IBM software, so every container needs a Tm1Source. Most tests don't create containers themselves: they use RequiresTm1, which finds a source from the environment, starts one shared container, and skips the tests when there's no source or no Docker.

By default the server starts with an empty database and the login admin with no password. Once started, the container reads the server's version, available from tm1_version. If with_expected_version was set and the version differs, it fails to start, before any test runs against the wrong TM1.

A client for the server, from its URL and login:

# The container's REST URL and login, in TM1's own security
return Tm1Client.builder().base_url(server.rest_url).basic_auth(server.username, server.password).build()

A container of a test's own, with IBM's SData sample on one TM1 version:

source = Tm1Source.discover()
if source is None:
    raise RuntimeError("Set TM1_HOME_DIR or TM1_BUNDLE_DIR")
# SData's login is admin / apple, and the server must be this version
container = Tm1ServerContainer(source).with_seed(Tm1Seed.SDATA).with_expected_version(Tm1Version.parse("11.8.03500.6"))
# Entering the block starts the container, and leaving it stops it
with container as server:
    # The client's block is the inner one, so its session closes before the container stops
    with Tm1Client.builder().base_url(server.rest_url).basic_auth(server.username, server.password).build() as tm1:
        # SData's cubes, such as SalesCube
        return [cube.name for cube in tm1.cubes.model_cubes(ODataQuery.none().select(Cube.NAME))]

Your own database, from a folder in the project:

# A fixture model (.cub, .dim, .pro files and so on), copied in before TM1 starts,
# and a login the database has
container = Tm1ServerContainer(source).with_data(Path("tests/tm1/sales")).with_credentials("admin", "apple")
with container as server:
    return server.rest_url  # http://localhost:54321/api/v1/

In Cognos (CAM) security, with with_cam_security, each Cognos test user logs in as themselves:

cognos = CognosContainer(cognos_source).with_user("admin", "adminpw", "Admins").with_user("viewer", "viewerpw", "Readers")
# Entering the block starts the server, and Cognos first; leaving it stops the server
with cognos, Tm1ServerContainer(tm1_source).with_cam_security(cognos, "admin") as server:
    # Each test user logs in with their own identity, through the LDAP namespace
    viewer = auth.cam_namespace("viewer", "viewerpw", CognosContainer.NAMESPACE)
    with Tm1Client.builder().base_url(server.rest_url).authenticator(viewer).build() as tm1:
        # TM1 knows the user by their CAMID
        return tm1.users.active_user(ODataQuery.none().select(User.NAME)).name

Members

DEFAULT_IMAGEThe tm1-server image, without a tag.
SERVER_IMAGEOverrides the tm1-server image (not used with PrivateImage), e.g.
REST_PORTThe REST API's port inside the container.
CACHE_VOLUMEThe volume bundle installs are cached in, shared by every container on this Docker host.
__init__ constructorA container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source.
default_image staticThe image a server from this source runs in.
image_tag staticThe image tag for a library version.
library_version staticThis library's version, which picks the image's tag.
shared staticOne server for every test in this process, from the settings (Tm1Source.discover), started on first use and marked for reuse.
with_seedStarts from a seed database instead of an empty one, and logs in as its user.
with_dataCopies a database folder in, as the server's data directory.
with_credentialsThe login for the database the server starts with.
with_cam_securityRuns TM1 in CAM security (mode 5) against a CognosContainer, with the named test users as administrators, logging in as the first.
with_admin_serverRegisters with a shared Admin Server instead of the server's own.
with_expected_versionFails to start unless the server reports this version.
admin_server propertyThe Admin Server set with with_admin_server, or None if this container runs its own.
cognos propertyThe Cognos set with with_cam_security, or None if TM1 uses its own (native) security.
cam_namespace propertyThe Cognos namespace TM1's users log on through, set with with_cam_security, or None if TM1 uses its own (native) security.
authorization propertyThe Authorization header to log in with.
source propertyWhere TM1 comes from.
rest_url propertyThe REST API's root, such as http://localhost:54321/api/v1/.
username propertyThe TM1 user name tests should log in as; admin unless set.
password propertyThe password for username; empty unless set.
tm1_version propertyThe version the running server reports.
configureCalled by testcontainers before the container is created.
container_is_startedCalled once the container is up.

DEFAULT_IMAGE

DEFAULT_IMAGE: ClassVar[str]

The tm1-server image, without a tag.

SERVER_IMAGE

SERVER_IMAGE: ClassVar[str]

Overrides the tm1-server image (not used with PrivateImage), e.g. tm1-server:local for a local build. Read as a system property, then an environment variable, like Tm1Source's settings.

REST_PORT

REST_PORT: ClassVar[int]

The REST API's port inside the container.

CACHE_VOLUME

CACHE_VOLUME: ClassVar[str]

The volume bundle installs are cached in, shared by every container on this Docker host. Only the first container to see a bundle installs it; the rest reuse it. Remove the volume to clear it.

__init__

constructor
__init__(source: Tm1Source, image: str | None = None) -> None

A container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source.

default_image

static
default_image(source: Tm1Source) -> str

The image a server from this source runs in: a private image as it is, else TM1_SERVER_IMAGE if set, else the published image at the tag for this library's version.

image_tag

static
image_tag(library_version: str) -> str

The image tag for a library version: edge for snapshots and development releases.

library_version

static
library_version() -> str

This library's version, which picks the image's tag.

shared

static
shared() -> Tm1ServerContainer

One server for every test in this process, from the settings (Tm1Source.discover), started on first use and marked for reuse. It's removed when the process ends, unless reuse is enabled (testcontainers.reuse.enable=true), when a later run reuses it.

with_seed

with_seed(seed: Tm1Seed) -> Self

Starts from a seed database instead of an empty one, and logs in as its user.

with_data

with_data(data_dir: Path | str) -> Self

Copies a database folder in, as the server's data directory.

with_credentials

with_credentials(username: str, password: str) -> Self

The login for the database the server starts with.

with_cam_security

with_cam_security(cognos: CognosContainer, *admins: Any) -> Self

Runs TM1 in CAM security (mode 5) against a CognosContainer, with the named test users as administrators, logging in as the first. with_cam_security(cognos, Namespace.OIDC, "admin") uses Keycloak's OIDC namespace instead of LDAP.

with_admin_server

with_admin_server(admin: Tm1AdminServerContainer) -> Self

Registers with a shared Admin Server instead of the server's own.

with_expected_version

with_expected_version(version: Tm1Version | str) -> Self

Fails to start unless the server reports this version.

admin_server

property
admin_server: Tm1AdminServerContainer | None

The Admin Server set with with_admin_server, or None if this container runs its own.

cognos

property
cognos: CognosContainer | None

The Cognos set with with_cam_security, or None if TM1 uses its own (native) security.

cam_namespace

property
cam_namespace: Namespace | None

The Cognos namespace TM1's users log on through, set with with_cam_security, or None if TM1 uses its own (native) security.

authorization

property
authorization: str

The Authorization header to log in with: Basic, or CAMNamespace in CAM security.

source

property
source: Tm1Source

Where TM1 comes from.

rest_url

property
rest_url: str

The REST API's root, such as http://localhost:54321/api/v1/.

username

property
username: str

The TM1 user name tests should log in as; admin unless set.

password

property
password: str

The password for username; empty unless set.

tm1_version

property
tm1_version: Tm1Version

The version the running server reports. Only available once started: a RuntimeError before.

configure

configure() -> None

Called by testcontainers before the container is created: in CAM security, passes Cognos's address, the namespace and the administrators to the image.

container_is_started

container_is_started() -> None

Called once the container is up: reads the server's version, and fails the start if it isn't the expected one.