Tm1EngineContainer
from skipcheck_tm1_testcontainers import Tm1EngineContainer A TM1 v12 engine (Planning Analytics 3.x) in Docker, for tests: the tm1-engine
image with TM1 from a Tm1EngineSource, and the MongoDB it keeps its metadata
in, on a network of their own. For TM1 11, use Tm1ServerContainer.
One engine holds instances, each holding databases. Most tests use the
one instance, tm1, and a database of their own: RequiresTm1Engine gives
each test class one. A container you make yourself has the databases you name with
with_database, or one called tm1:
# Entering the block starts the engine, and leaving it stops it
with Tm1EngineContainer(source).with_database("planning").with_user("analyst", "Analysts") as engine:
planning: Tm1Database = engine.database("planning")
# http://localhost:54321/tm1/api/v1/Databases('planning')/
url: str = planning.rest_url
analyst: Tm1Login = planning.login("analyst")
# ...
TM1 v12 has no passwords of its own. A test logs in through the instance's application
(Tm1Login), which this container creates and keeps the credentials of.
Starting takes about 40 seconds, and a database about 10 more to create
(create_database). The image exists for x86-64 only, as TM1 does; on Apple
Silicon it runs under Rosetta.
Members
DEFAULT_IMAGE | The tm1-engine image, without a tag. |
ENGINE_IMAGE | Overrides the tm1-engine image (not used with PrivateImage), e.g. |
DATASTORE_IMAGE | The MongoDB image the engine's datastore runs. |
PORT | The port of TM1's gateway inside the container. |
DEFAULT_INSTANCE | The instance databases are in unless one is named. |
DEFAULT_DATABASE | The database a container has when none is named. |
DATASTORE_ALIAS | The datastore's name on the engine's network. |
CACHE_VOLUME | The volume package installs are cached in, shared by every engine container on this Docker host. |
PASS_THROUGH_ALIAS | The name a TM1 server has on the engine's network when logins are passed to it (with_pass_through). |
OAUTH2_REALM | The Keycloak realm an engine with with_oauth2 takes tokens from. |
OAUTH2_CLIENT | The client of that realm a test asks for tokens as, and the audience its tokens carry. |
__init__ constructor | A container that gets TM1 from source, with the default image for it. |
with_network | Puts the engine, and its datastore with it, on a network. |
shared static | The engine most tests share. |
with_database | Adds a database. |
with_user | Adds a user to every database, in exactly these groups (created if missing). |
with_oauth2 | Takes OAuth 2.0 logins. |
with_pass_through | Passes logins on to a TM1 11 server ("pass-through"). |
pass_through property | The TM1 server logins are passed to, or None without with_pass_through. |
with_login | Gives a user a password to log in with through OAuth 2.0 (with_oauth2). |
keycloak property | The Keycloak the engine takes OAuth 2.0 tokens from, or None without with_oauth2. |
source property | Where TM1 comes from. |
datastore property | The MongoDB the engine keeps its metadata in, started and stopped with it. |
url property | The gateway as seen from the host, e.g. |
management_url property | The management API, which lists and creates instances, applications and databases, e.g. |
root_client_id property | The client ID of the engine's root credentials, for the management API. |
root_client_secret property | The client secret of the engine's root credentials. |
tm1_version property | The version of TM1 the engine runs. |
databases | The databases the engine has now, in every instance. |
database | A database. |
create_database | Creates a database in the running engine, with the users of with_user. |
drop_database | Deletes a database of the running engine, with everything in it. |
start | Starts the datastore, then the engine, and waits until TM1 is set up. |
configure | Called before the container is created. |
container_is_started | Called once the gateway answers. |
stop | Stops the engine, then its datastore, and removes the network if the engine made it. |
DEFAULT_IMAGE
DEFAULT_IMAGE: ClassVar[str]The tm1-engine image, without a tag.
ENGINE_IMAGE
ENGINE_IMAGE: ClassVar[str] Overrides the tm1-engine image (not used with
PrivateImage), e.g. tm1-engine:local for a local
build. Read as a system property, then an environment variable.
DATASTORE_IMAGE
DATASTORE_IMAGE: ClassVar[str]The MongoDB image the engine's datastore runs.
PORT
PORT: ClassVar[int]The port of TM1's gateway inside the container: the REST API, logins and management.
DEFAULT_INSTANCE
DEFAULT_INSTANCE: ClassVar[str]The instance databases are in unless one is named.
DEFAULT_DATABASE
DEFAULT_DATABASE: ClassVar[str]The database a container has when none is named.
DATASTORE_ALIAS
DATASTORE_ALIAS: ClassVar[str]The datastore's name on the engine's network. It's the same for every engine, so give each engine a network of its own, as it has unless you set one: two engines on one network would each find either's datastore under this name.
CACHE_VOLUME
CACHE_VOLUME: ClassVar[str]The volume package installs are cached in, shared by every engine container on this Docker host. Only the first container to see a package installs it. Remove the volume to clear it.
PASS_THROUGH_ALIAS
PASS_THROUGH_ALIAS: ClassVar[str] The name a TM1 server has on the engine's network when logins are passed to it
(with_pass_through).
OAUTH2_REALM
OAUTH2_REALM: ClassVar[str]The Keycloak realm an engine with with_oauth2 takes tokens from.
OAUTH2_CLIENT
OAUTH2_CLIENT: ClassVar[str]The client of that realm a test asks for tokens as, and the audience its tokens carry.
__init__
constructor__init__(source: Tm1EngineSource, image: str | None = None) -> None A container that gets TM1 from source, with the default image for it.
with_network
with_network(network: Any) -> SelfPuts the engine, and its datastore with it, on a network. They have one of their own unless this is called; a network that's given is never removed by the engine. A RuntimeError if the engine takes tokens from a Keycloak (with_oauth2), or passes logins to a TM1 server (with_pass_through), that's on another.
with_database
with_database(instance_or_name: str, name: str | None = None) -> SelfAdds a database: with_database(name) in the instance tm1, or with_database(instance, name) in a named instance, which is created with an application of its own. An instance's users, sessions and applications are separate from another's. Without any, the container has one database called tm1. A database's name is at least three letters, digits, _ or -, and an instance's at least one; Sales and sales are two databases.
with_user
with_user(name: str, *groups: str) -> SelfAdds a user to every database, in exactly these groups (created if missing). A new database has one user already: admin, in the ADMIN group.
with_oauth2
with_oauth2(keycloak: KeycloakContainer) -> SelfTakes OAuth 2.0 logins: tokens from a Keycloak, which gets a realm (tm1) with the users given a password by with_login. A test then logs in with Tm1Database.oauth2_login. Logins through the engine's application (Tm1Database.login) keep working beside it.
The Keycloak joins the engine's network, unless it has one already, which the engine then joins. It's yours to stop: the engine only starts it first, so give it one that isn't started yet, and stop it after the engine.
# A Keycloak that isn't started: the engine starts it first, with the users' passwords
keycloak = KeycloakContainer()
engine = Tm1EngineContainer(source).with_user("analyst", "Analysts").with_login("analyst", "analystpw").with_oauth2(keycloak)
# Entering the block starts Keycloak, then the engine; the Keycloak is yours to close
with closing(keycloak), engine:
db: Tm1Database = engine.database("tm1")
# A token from Keycloak, with the analyst's password, sent to TM1 as Bearer
headers = db.oauth2_login("analyst").authorize_with_token({})
response = httpx2.get(db.rest_url + "Cubes?$select=Name", headers=headers)with_pass_through
with_pass_through(server: Tm1ServerContainer) -> SelfPasses logins on to a TM1 11 server ("pass-through"): TM1 v12 asks it who a login is, so that server's users log in here with what they have there. A test logs in with Tm1Database.pass_through_login. Logins through the engine's application (Tm1Database.login) keep working beside it.
* A user has to be in the database too: add each with with_user. admin always is. * **A server in Cognos (CAM) security** (Tm1ServerContainer.with_cam_security) answers a login with the user's CAMID. The engine's users are then Cognos's test users, each made under its CAMID, and the server's administrators are administrators here too. TM1 v12 learns no groups from Cognos: a user has the groups with_user gives. * Not together with with_oauth2: with both, TM1 takes tokens and refuses the rest.
The server joins the engine's network, unless it has one already, which the engine and its datastore then join. Starting the engine starts the server first. Give it one that isn't started: it gets the name the engine reaches it by, PASS_THROUGH_ALIAS, so one network holds one such server. It's yours to stop, after the engine.
# A TM1 11 server that isn't started: the engine starts it first
server = Tm1ServerContainer(tm1).with_seed(Tm1Seed.SDATA)
engine = Tm1EngineContainer(source).with_pass_through(server)
# Entering the block starts the server, then the engine; the server is yours to close
with closing(server), engine:
db: Tm1Database = engine.database("tm1")
# The sample database's admin / apple, which TM1 v12 asks the server about
headers = db.pass_through_login().authorize({})
response = httpx2.get(db.rest_url + "Cubes?$select=Name", headers=headers)pass_through
propertypass_through: Tm1ServerContainer | NoneThe TM1 server logins are passed to, or None without with_pass_through.
with_login
with_login(user: str, password: str) -> SelfGives a user a password to log in with through OAuth 2.0 (with_oauth2). TM1 v12 keeps no passwords itself: it's the Keycloak's. The user is one added with with_user, or admin.
keycloak
propertykeycloak: KeycloakContainer | NoneThe Keycloak the engine takes OAuth 2.0 tokens from, or None without with_oauth2.
source
propertysource: Tm1EngineSourceWhere TM1 comes from.
datastore
propertydatastore: GenericContainerThe MongoDB the engine keeps its metadata in, started and stopped with it.
url
propertyurl: strThe gateway as seen from the host, e.g. http://localhost:54321/.
management_url
propertymanagement_url: strThe management API, which lists and creates instances, applications and databases, e.g. http://localhost:54321/manage/v1/. It takes the root credentials as Basic authentication (root_client_id, root_client_secret).
root_client_id
propertyroot_client_id: strThe client ID of the engine's root credentials, for the management API.
root_client_secret
propertyroot_client_secret: strThe client secret of the engine's root credentials.
tm1_version
propertytm1_version: Tm1VersionThe version of TM1 the engine runs. Only available once started: a RuntimeError before.
databases
databases() -> list[Tm1Database]The databases the engine has now, in every instance.
database
database(instance_or_name: str, name: str | None = None) -> Tm1DatabaseA database: database(name) of the instance tm1, or database(instance, name) of a named instance. A ValueError if there's no such database.
create_database
create_database(instance_or_name: str, name: str | None = None) -> Tm1DatabaseCreates a database in the running engine, with the users of with_user: create_database(name) in the instance tm1, or create_database(instance, name) in a named instance, which must exist. Takes about 10 seconds.
drop_database
drop_database(database: Tm1Database) -> NoneDeletes a database of the running engine, with everything in it. Takes about 7 seconds.
start
start() -> SelfStarts the datastore, then the engine, and waits until TM1 is set up.
configure
configure() -> NoneCalled before the container is created: passes the databases and the users to the image.
container_is_started
container_is_started() -> NoneCalled once the gateway answers: waits for the image to set TM1 up, and reads its version.
stop
stop(force: bool = True, delete_volume: bool = True) -> NoneStops the engine, then its datastore, and removes the network if the engine made it. A Keycloak or a TM1 server of yours that's still on that network keeps it until it's stopped, and removes it then.