Tm1ServerContainer
from skipcheck_tm1_testcontainers import Tm1ServerContainerUsed 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_IMAGE | The tm1-server image, without a tag. |
SERVER_IMAGE | Overrides the tm1-server image (not used with PrivateImage), e.g. |
REST_PORT | The REST API's port inside the container. |
CACHE_VOLUME | The volume bundle installs are cached in, shared by every container on this Docker host. |
__init__ constructor | A container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source. |
default_image static | The image a server from this source runs in. |
image_tag static | The image tag for a library version. |
library_version static | This library's version, which picks the image's tag. |
shared static | One server for every test in this process, from the settings (Tm1Source.discover), started on first use and marked for reuse. |
with_seed | Starts from a seed database instead of an empty one, and logs in as its user. |
with_data | Copies a database folder in, as the server's data directory. |
with_credentials | The login for the database the server starts with. |
with_cam_security | Runs TM1 in CAM security (mode 5) against a CognosContainer, with the named test users as administrators, logging in as the first. |
with_admin_server | Registers with a shared Admin Server instead of the server's own. |
with_expected_version | Fails to start unless the server reports this version. |
admin_server property | The Admin Server set with with_admin_server, or None if this container runs its own. |
cognos property | The Cognos set with with_cam_security, or None if TM1 uses its own (native) security. |
cam_namespace property | 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 | The Authorization header to log in with. |
source property | Where TM1 comes from. |
rest_url property | The REST API's root, such as http://localhost:54321/api/v1/. |
username property | The TM1 user name tests should log in as; admin unless set. |
password property | The password for username; empty unless set. |
tm1_version property | The version the running server reports. |
configure | Called by testcontainers before the container is created. |
container_is_started | Called 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
staticdefault_image(source: Tm1Source) -> strThe 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
staticimage_tag(library_version: str) -> strThe image tag for a library version: edge for snapshots and development releases.
library_version
staticlibrary_version() -> strThis library's version, which picks the image's tag.
with_seed
with_seed(seed: Tm1Seed) -> SelfStarts from a seed database instead of an empty one, and logs in as its user.
with_data
with_data(data_dir: Path | str) -> SelfCopies a database folder in, as the server's data directory.
with_credentials
with_credentials(username: str, password: str) -> SelfThe login for the database the server starts with.
with_cam_security
with_cam_security(cognos: CognosContainer, *admins: Any) -> SelfRuns 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) -> SelfRegisters with a shared Admin Server instead of the server's own.
with_expected_version
with_expected_version(version: Tm1Version | str) -> SelfFails to start unless the server reports this version.
admin_server
propertyadmin_server: Tm1AdminServerContainer | NoneThe Admin Server set with with_admin_server, or None if this container runs its own.
cognos
propertycognos: CognosContainer | NoneThe Cognos set with with_cam_security, or None if TM1 uses its own (native) security.
cam_namespace
propertycam_namespace: Namespace | NoneThe Cognos namespace TM1's users log on through, set with with_cam_security, or None if TM1 uses its own (native) security.
authorization
propertyauthorization: strThe Authorization header to log in with: Basic, or CAMNamespace in CAM security.
source
propertysource: Tm1SourceWhere TM1 comes from.
rest_url
propertyrest_url: strThe REST API's root, such as http://localhost:54321/api/v1/.
username
propertyusername: strThe TM1 user name tests should log in as; admin unless set.
password
propertypassword: strThe password for username; empty unless set.
tm1_version
propertytm1_version: Tm1VersionThe version the running server reports. Only available once started: a RuntimeError before.
configure
configure() -> NoneCalled 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() -> NoneCalled once the container is up: reads the server's version, and fails the start if it isn't the expected one.