skipcheck

TM1 Testcontainers · Docs · Containers

CognosContainer

from skipcheck_tm1_testcontainers import CognosContainer

IBM Cognos Analytics in Docker, for tests, built on the cognos-server image: the security (CAM) a TM1 server in CAM mode takes its users from.

Give it test users, and the container builds an LDAP directory with them and a Cognos namespace (LDAP) for it. Then run a Tm1ServerContainer against it with Tm1ServerContainer.with_cam_security, and log in to TM1 as each test user:

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

Cognos is heavy: it takes about two minutes to start and uses about 8 GB of memory, so Docker needs at least 12 GB. Every user is a Cognos administrator (a new content store puts Everyone there); TM1's own security comes from the groups. The image contains no IBM software, so every container needs a CognosSource.

Members

DEFAULT_IMAGEThe cognos-server image, without a tag.
SERVER_IMAGEOverrides the cognos-server image (not used with PrivateImage), e.g.
DISPATCHER_PORTThe Cognos dispatcher's port inside the container.
NETWORK_ALIASThe container's host name and network alias, which Cognos's dispatcher URIs name.
NAMESPACEThe ID of the LDAP namespace the test users are in.
Namespace
User
__init__ constructorA container on the default cognos-server image (or COGNOS_SERVER_IMAGE), getting Cognos from source.
with_userAdds a test user to the LDAP namespace, in groups that are created as needed.
with_keycloakAdds an OIDC namespace backed by Keycloak, on one network with it.
keycloak propertyThe Keycloak set with with_keycloak, or None if there's no OIDC namespace.
users propertyThe test users, in the order they were added.
get_userA test user by name.
groups propertyEvery test user's groups, once each, in the order they were added.
source propertyWhere Cognos comes from.
url propertyCognos as seen from the host, such as http://localhost:54321/bi/, ending in /.
network_url propertyThe dispatcher, as other containers on the network reach it.
cam_authorizationA test user's CAMNamespace logon, for TM1 in CAM security.
passportA CAM passport for an OIDC ID token (from KeycloakContainer.id_token).
cam_authorization_for staticCAMNamespace with user:password:namespace.
users_specThe users as the image's COGNOS_USERS takes them.
configureCalled by testcontainers before the container is created.
container_is_startedCalled once the container is up.

DEFAULT_IMAGE

DEFAULT_IMAGE: ClassVar[str]

The cognos-server image, without a tag.

SERVER_IMAGE

SERVER_IMAGE: ClassVar[str]

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

DISPATCHER_PORT

DISPATCHER_PORT: ClassVar[int]

The Cognos dispatcher's port inside the container.

NETWORK_ALIAS

NETWORK_ALIAS: ClassVar[str]

The container's host name and network alias, which Cognos's dispatcher URIs name. Other containers on its network reach it at http://cognos:9300.

NAMESPACE

NAMESPACE: ClassVar[str]

The ID of the LDAP namespace the test users are in: the CAMNamespace.

Namespace

Namespace: ClassVar[type[Namespace]]

User

User: ClassVar[type[User]]

__init__

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

A container on the default cognos-server image (or COGNOS_SERVER_IMAGE), getting Cognos from source.

with_user

with_user(name: str, password: str, *groups: str) -> Self

Adds a test user to the LDAP namespace, in groups that are created as needed.

with_keycloak

with_keycloak(keycloak: KeycloakContainer) -> Self

Adds an OIDC namespace backed by Keycloak, on one network with it.

keycloak

property
keycloak: KeycloakContainer | None

The Keycloak set with with_keycloak, or None if there's no OIDC namespace.

users

property
users: list[User]

The test users, in the order they were added.

get_user

get_user(name: str) -> User

A test user by name. A ValueError if there's no such user.

groups

property
groups: list[str]

Every test user's groups, once each, in the order they were added.

source

property
source: CognosSource

Where Cognos comes from.

url

property
url: str

Cognos as seen from the host, such as http://localhost:54321/bi/, ending in /.

network_url

property
network_url: str

The dispatcher, as other containers on the network reach it.

cam_authorization

cam_authorization(user: str, namespace: Namespace = Namespace.LDAP) -> str

A test user's CAMNamespace logon, for TM1 in CAM security.

passport

passport(id_token: str) -> str

A CAM passport for an OIDC ID token (from KeycloakContainer.id_token).

cam_authorization_for

static
cam_authorization_for(user: str, password: str, namespace: str) -> str

CAMNamespace with user:password:namespace: Java's static camAuthorization.

users_spec

users_spec() -> str

The users as the image's COGNOS_USERS takes them.

configure

configure() -> None

Called by testcontainers before the container is created: passes the test users to the image as COGNOS_USERS.

container_is_started

container_is_started() -> None

Called once the container is up: logs where it is and what it came from.