skipcheck-tm1-testcontainers 0.1.0.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. skipcheck_tm1_testcontainers-0.1.0.dev0/.gitignore +49 -0
  2. skipcheck_tm1_testcontainers-0.1.0.dev0/PKG-INFO +123 -0
  3. skipcheck_tm1_testcontainers-0.1.0.dev0/README.md +108 -0
  4. skipcheck_tm1_testcontainers-0.1.0.dev0/hatch_build.py +24 -0
  5. skipcheck_tm1_testcontainers-0.1.0.dev0/pyproject.toml +39 -0
  6. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/__init__.py +41 -0
  7. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/_container.py +392 -0
  8. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/cognos.py +250 -0
  9. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/environment.py +302 -0
  10. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/paw-local.sh +275 -0
  11. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/paw.py +399 -0
  12. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/plugin.py +151 -0
  13. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/requires.py +53 -0
  14. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/sources.py +500 -0
  15. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/tm1.py +379 -0
  16. skipcheck_tm1_testcontainers-0.1.0.dev0/src/skipcheck_tm1_testcontainers/web.py +179 -0
  17. skipcheck_tm1_testcontainers-0.1.0.dev0/tests/test_java_parity.py +246 -0
  18. skipcheck_tm1_testcontainers-0.1.0.dev0/tests/test_other_sources.py +156 -0
  19. skipcheck_tm1_testcontainers-0.1.0.dev0/tests/test_tm1_server_container.py +45 -0
  20. skipcheck_tm1_testcontainers-0.1.0.dev0/tests/test_tm1_source.py +127 -0
  21. skipcheck_tm1_testcontainers-0.1.0.dev0/tests/test_web_and_paw_containers.py +85 -0
  22. skipcheck_tm1_testcontainers-0.1.0.dev0/tests/test_wiring.py +242 -0
  23. skipcheck_tm1_testcontainers-0.1.0.dev0/tests/tm1_web_session.py +69 -0
@@ -0,0 +1,49 @@
1
+ HELP.md
2
+ .gradle
3
+ build/
4
+ !gradle/wrapper/gradle-wrapper.jar
5
+ !**/src/main/**/build/
6
+ !**/src/test/**/build/
7
+
8
+ ### STS ###
9
+ .apt_generated
10
+ .classpath
11
+ .factorypath
12
+ .project
13
+ .settings
14
+ .springBeans
15
+ .sts4-cache
16
+ bin/
17
+ !**/src/main/**/bin/
18
+ !**/src/test/**/bin/
19
+
20
+ ### IntelliJ IDEA ###
21
+ .idea
22
+ *.iws
23
+ *.iml
24
+ *.ipr
25
+ out/
26
+ !**/src/main/**/out/
27
+ !**/src/test/**/out/
28
+
29
+ ### NetBeans ###
30
+ /nbproject/private/
31
+ /nbbuild/
32
+ /dist/
33
+ /nbdist/
34
+ /.nb-gradle/
35
+
36
+ ### VS Code ###
37
+ .vscode/
38
+
39
+ ### Logs ###
40
+ logs/
41
+
42
+ ### macOS ###
43
+ .DS_Store
44
+
45
+ ### Kotlin (build-logic) ###
46
+ .kotlin/
47
+
48
+ ### Python ###
49
+ __pycache__/
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.5
2
+ Name: skipcheck-tm1-testcontainers
3
+ Version: 0.1.0.dev0
4
+ Summary: Testcontainers support for running IBM Planning Analytics (TM1) servers in tests
5
+ License-Expression: AGPL-3.0-only
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: httpx>=0.27
8
+ Requires-Dist: pytest>=8
9
+ Requires-Dist: skipcheck-tm1
10
+ Requires-Dist: testcontainers>=4.15
11
+ Requires-Dist: typing-extensions>=4.7
12
+ Provides-Extra: test
13
+ Requires-Dist: pytest>=8; extra == 'test'
14
+ Description-Content-Type: text/markdown
15
+
16
+ # skipcheck-tm1-testcontainers (Python)
17
+
18
+ Run tests against a real IBM Planning Analytics (TM1) server in Docker, with
19
+ [testcontainers-python](https://testcontainers-python.readthedocs.io). The Python port of the
20
+ Java [`tm1-testcontainers`](../../java/tm1-testcontainers/README.md) module: the same classes, sources,
21
+ settings, images, mounts and messages, named the Python way. Built on the
22
+ [`tm1-server`](../../docker/tm1-server) image.
23
+
24
+ > **No IBM software is included.** You supply your own licensed TM1 Server for Linux, and
25
+ > you're responsible for following your IBM license terms. Without it, tests that need TM1
26
+ > are skipped.
27
+
28
+ ```sh
29
+ pip install -e ./python/tm1-client -e ./python/tm1-testcontainers
30
+ ```
31
+
32
+ Requires Python 3.10+, testcontainers 4.15+ and [`skipcheck-tm1`](..).
33
+
34
+ ## Writing a test
35
+
36
+ Installing the package adds a pytest plugin, so a test needs only the fixture:
37
+
38
+ ```python
39
+ def test_lists_cubes(tm1_server):
40
+ url = tm1_server.rest_url # http://localhost:54321/api/v1/
41
+ user = tm1_server.username # admin, with no password
42
+ ...
43
+ ```
44
+
45
+ `tm1_server`, like Java's `@RequiresTm1`:
46
+
47
+ - **Skips** the test when Docker isn't running or no TM1 source is configured, so builds
48
+ without IBM software (such as GitHub CI) stay green. A source that's configured but wrong
49
+ fails instead of skipping.
50
+ - **Is** `Tm1ServerContainer.shared()`: one server per test process, started on first use and
51
+ shared by every test, removed when the session ends.
52
+
53
+ `@pytest.mark.requires_tm1` skips the same way without the fixture. `requires_cognos`,
54
+ `requires_tm1_web` and `requires_paw`, with the fixtures `cognos` (the configured
55
+ `CognosSource`), `tm1_web` and `paw`, are Java's `@RequiresCognos`, `@RequiresTm1Web` and
56
+ `@RequiresPaw`.
57
+
58
+ For a container of your own:
59
+
60
+ ```python
61
+ from skipcheck_tm1 import Tm1Version
62
+ from skipcheck_tm1_testcontainers import Tm1Seed, Tm1ServerContainer, Tm1Source
63
+
64
+ with Tm1ServerContainer(Tm1Source.InstallDir("/opt/ibm/tm1_64")).with_seed(Tm1Seed.SDATA).with_expected_version(Tm1Version.parse("11.8.03500.6")) as tm1:
65
+ ...
66
+ ```
67
+
68
+ ## Where TM1 comes from
69
+
70
+ The same settings as Java, in the same order (`Tm1Source.discover()`), as environment variables:
71
+
72
+ | Setting | Source |
73
+ |---|---|
74
+ | `TM1_PRIVATE_IMAGE` | `Tm1Source.PrivateImage`: an image with TM1 built in |
75
+ | `TM1_HOME_DIR` | `Tm1Source.InstallDir`: an installed `tm1_64` folder, mounted read-only |
76
+ | `TM1_INSTALL_VOLUME` | `Tm1Source.InstallVolume`: a Docker volume holding an install |
77
+ | `TM1_BUNDLE_DIR` (`TM1_BUNDLE`) | `Tm1Source.Bundle`: a folder holding IBM's bundle (the newest, or the one named) |
78
+ | `TM1_BUNDLE_URL` (`TM1_BUNDLE_SHA256`) | `Tm1Source.BundleUrl`: a link to the bundle |
79
+
80
+ A bundle is unpacked into the `tm1-testcontainers-cache` volume once, shared with the Java and
81
+ .NET tests. `TM1_SERVER_IMAGE` replaces the `tm1-server` image (default
82
+ `ghcr.io/ajmyers/tm1-server`, tagged `edge` for development versions). Cognos (`COGNOS_*`), TM1
83
+ Web (`TM1_WEB_*`) and PAW (`PAW_ZIP`, `PAW_BUNDLE_DIR`, `PAW_ACCEPT_LICENSE`) read Java's
84
+ settings too.
85
+
86
+ ## More than one server
87
+
88
+ ```python
89
+ env = PlanningAnalyticsEnvironment.builder().tm1("planning").tm1("reporting").tm1_web().cognos(lambda c: c.with_user("admin", "adminpw", "Admins")).build()
90
+ with env:
91
+ env.tm1("planning").rest_url
92
+ ```
93
+
94
+ Several servers share an Admin Server (`Tm1AdminServerContainer`); Cognos puts every server in
95
+ CAM security, and `keycloak()` with `cam_security(Namespace.OIDC, ...)` uses OIDC.
96
+
97
+ ## From the Java module
98
+
99
+ | Java | Python |
100
+ |---|---|
101
+ | `tm1.getRestUrl()`, `getUsername()`, `getTm1Version()`… | `tm1.rest_url`, `username`, `tm1_version`… (getters are properties) |
102
+ | `withSeed`, `withCamSecurity(cognos, Namespace.OIDC, "admin")`… | `with_seed`, `with_cam_security(cognos, Namespace.OIDC, "admin")`… |
103
+ | `CognosContainer.camAuthorization(user, password, namespace)` (static) | `CognosContainer.cam_authorization_for(...)` |
104
+ | `Optional<Tm1Source> discover()` | `discover()` returning the source or `None`; it also takes a lookup (`settings.get`) |
105
+ | `IllegalArgumentException`, `IllegalStateException` | `ValueError`, `RuntimeError` |
106
+ | `Network.newNetwork()` | `Network.new_network()`: created when a container first starts on it |
107
+ | `@RequiresTm1` and its `Tm1ServerContainer` parameter | `@pytest.mark.requires_tm1` and the `tm1_server` fixture |
108
+ | `withReuse(true)` | `with_reuse(True)`, honoured when `testcontainers.reuse.enable=true` (testcontainers-python has no reuse of its own) |
109
+
110
+ Containers are set up without Docker, as Java's are, so wiring is tested anywhere; they connect
111
+ when started. Java also reads each setting as a system property; Python reads environment
112
+ variables only.
113
+
114
+ ## Tests
115
+
116
+ ```sh
117
+ pytest python/tm1-testcontainers
118
+ ```
119
+
120
+ - `test_java_parity.py` reads the Java sources and requires every public class, constant and
121
+ member here, listing the few Java-only ones with the reason.
122
+ - The other tests port the Java tests. The configuration ones run without Docker; the ones that
123
+ start containers are skipped without a source, as in Java.
@@ -0,0 +1,108 @@
1
+ # skipcheck-tm1-testcontainers (Python)
2
+
3
+ Run tests against a real IBM Planning Analytics (TM1) server in Docker, with
4
+ [testcontainers-python](https://testcontainers-python.readthedocs.io). The Python port of the
5
+ Java [`tm1-testcontainers`](../../java/tm1-testcontainers/README.md) module: the same classes, sources,
6
+ settings, images, mounts and messages, named the Python way. Built on the
7
+ [`tm1-server`](../../docker/tm1-server) image.
8
+
9
+ > **No IBM software is included.** You supply your own licensed TM1 Server for Linux, and
10
+ > you're responsible for following your IBM license terms. Without it, tests that need TM1
11
+ > are skipped.
12
+
13
+ ```sh
14
+ pip install -e ./python/tm1-client -e ./python/tm1-testcontainers
15
+ ```
16
+
17
+ Requires Python 3.10+, testcontainers 4.15+ and [`skipcheck-tm1`](..).
18
+
19
+ ## Writing a test
20
+
21
+ Installing the package adds a pytest plugin, so a test needs only the fixture:
22
+
23
+ ```python
24
+ def test_lists_cubes(tm1_server):
25
+ url = tm1_server.rest_url # http://localhost:54321/api/v1/
26
+ user = tm1_server.username # admin, with no password
27
+ ...
28
+ ```
29
+
30
+ `tm1_server`, like Java's `@RequiresTm1`:
31
+
32
+ - **Skips** the test when Docker isn't running or no TM1 source is configured, so builds
33
+ without IBM software (such as GitHub CI) stay green. A source that's configured but wrong
34
+ fails instead of skipping.
35
+ - **Is** `Tm1ServerContainer.shared()`: one server per test process, started on first use and
36
+ shared by every test, removed when the session ends.
37
+
38
+ `@pytest.mark.requires_tm1` skips the same way without the fixture. `requires_cognos`,
39
+ `requires_tm1_web` and `requires_paw`, with the fixtures `cognos` (the configured
40
+ `CognosSource`), `tm1_web` and `paw`, are Java's `@RequiresCognos`, `@RequiresTm1Web` and
41
+ `@RequiresPaw`.
42
+
43
+ For a container of your own:
44
+
45
+ ```python
46
+ from skipcheck_tm1 import Tm1Version
47
+ from skipcheck_tm1_testcontainers import Tm1Seed, Tm1ServerContainer, Tm1Source
48
+
49
+ with Tm1ServerContainer(Tm1Source.InstallDir("/opt/ibm/tm1_64")).with_seed(Tm1Seed.SDATA).with_expected_version(Tm1Version.parse("11.8.03500.6")) as tm1:
50
+ ...
51
+ ```
52
+
53
+ ## Where TM1 comes from
54
+
55
+ The same settings as Java, in the same order (`Tm1Source.discover()`), as environment variables:
56
+
57
+ | Setting | Source |
58
+ |---|---|
59
+ | `TM1_PRIVATE_IMAGE` | `Tm1Source.PrivateImage`: an image with TM1 built in |
60
+ | `TM1_HOME_DIR` | `Tm1Source.InstallDir`: an installed `tm1_64` folder, mounted read-only |
61
+ | `TM1_INSTALL_VOLUME` | `Tm1Source.InstallVolume`: a Docker volume holding an install |
62
+ | `TM1_BUNDLE_DIR` (`TM1_BUNDLE`) | `Tm1Source.Bundle`: a folder holding IBM's bundle (the newest, or the one named) |
63
+ | `TM1_BUNDLE_URL` (`TM1_BUNDLE_SHA256`) | `Tm1Source.BundleUrl`: a link to the bundle |
64
+
65
+ A bundle is unpacked into the `tm1-testcontainers-cache` volume once, shared with the Java and
66
+ .NET tests. `TM1_SERVER_IMAGE` replaces the `tm1-server` image (default
67
+ `ghcr.io/ajmyers/tm1-server`, tagged `edge` for development versions). Cognos (`COGNOS_*`), TM1
68
+ Web (`TM1_WEB_*`) and PAW (`PAW_ZIP`, `PAW_BUNDLE_DIR`, `PAW_ACCEPT_LICENSE`) read Java's
69
+ settings too.
70
+
71
+ ## More than one server
72
+
73
+ ```python
74
+ env = PlanningAnalyticsEnvironment.builder().tm1("planning").tm1("reporting").tm1_web().cognos(lambda c: c.with_user("admin", "adminpw", "Admins")).build()
75
+ with env:
76
+ env.tm1("planning").rest_url
77
+ ```
78
+
79
+ Several servers share an Admin Server (`Tm1AdminServerContainer`); Cognos puts every server in
80
+ CAM security, and `keycloak()` with `cam_security(Namespace.OIDC, ...)` uses OIDC.
81
+
82
+ ## From the Java module
83
+
84
+ | Java | Python |
85
+ |---|---|
86
+ | `tm1.getRestUrl()`, `getUsername()`, `getTm1Version()`… | `tm1.rest_url`, `username`, `tm1_version`… (getters are properties) |
87
+ | `withSeed`, `withCamSecurity(cognos, Namespace.OIDC, "admin")`… | `with_seed`, `with_cam_security(cognos, Namespace.OIDC, "admin")`… |
88
+ | `CognosContainer.camAuthorization(user, password, namespace)` (static) | `CognosContainer.cam_authorization_for(...)` |
89
+ | `Optional<Tm1Source> discover()` | `discover()` returning the source or `None`; it also takes a lookup (`settings.get`) |
90
+ | `IllegalArgumentException`, `IllegalStateException` | `ValueError`, `RuntimeError` |
91
+ | `Network.newNetwork()` | `Network.new_network()`: created when a container first starts on it |
92
+ | `@RequiresTm1` and its `Tm1ServerContainer` parameter | `@pytest.mark.requires_tm1` and the `tm1_server` fixture |
93
+ | `withReuse(true)` | `with_reuse(True)`, honoured when `testcontainers.reuse.enable=true` (testcontainers-python has no reuse of its own) |
94
+
95
+ Containers are set up without Docker, as Java's are, so wiring is tested anywhere; they connect
96
+ when started. Java also reads each setting as a system property; Python reads environment
97
+ variables only.
98
+
99
+ ## Tests
100
+
101
+ ```sh
102
+ pytest python/tm1-testcontainers
103
+ ```
104
+
105
+ - `test_java_parity.py` reads the Java sources and requires every public class, constant and
106
+ member here, listing the few Java-only ones with the reason.
107
+ - The other tests port the Java tests. The configuration ones run without Docker; the ones that
108
+ start containers are skipped without a source, as in Java.
@@ -0,0 +1,24 @@
1
+ """Puts docker/paw/paw-local.sh in the package as it's built.
2
+
3
+ PawContainer runs that script in its runner container, so the package ships it, as the Java build
4
+ puts it in the jar. The script lives in the repository's docker/paw folder, which a build from the
5
+ repository reads; an sdist carries its own copy inside the package, so a wheel built from the sdist
6
+ (as pip builds one) finds it there and has nothing to add.
7
+ """
8
+
9
+ from pathlib import Path
10
+
11
+ from hatchling.builders.hooks.plugin.interface import BuildHookInterface
12
+
13
+ PACKAGE = "skipcheck_tm1_testcontainers"
14
+
15
+
16
+ class PawScriptHook(BuildHookInterface):
17
+ def initialize(self, version: str, build_data: dict) -> None:
18
+ in_repository = Path(self.root, "..", "..", "docker", "paw", "paw-local.sh").resolve()
19
+ if not in_repository.is_file():
20
+ if not Path(self.root, "src", PACKAGE, "paw-local.sh").is_file():
21
+ raise FileNotFoundError("paw-local.sh is neither in the repository's docker/paw nor in the package")
22
+ return
23
+ target = f"src/{PACKAGE}/paw-local.sh" if self.target_name == "sdist" else f"{PACKAGE}/paw-local.sh"
24
+ build_data["force_include"][str(in_repository)] = target
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "skipcheck-tm1-testcontainers"
7
+ version = "0.1.0.dev0"
8
+ description = "Testcontainers support for running IBM Planning Analytics (TM1) servers in tests"
9
+ readme = "README.md"
10
+ license = "AGPL-3.0-only"
11
+ requires-python = ">=3.10"
12
+ dependencies = [
13
+ # Tm1Version is part of this package's API (Tm1ServerContainer.with_expected_version)
14
+ "skipcheck-tm1",
15
+ "testcontainers>=4.15",
16
+ "httpx>=0.27",
17
+ "typing-extensions>=4.7",
18
+ # The markers and fixtures are a pytest plugin, as Java's are JUnit extensions
19
+ "pytest>=8",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ test = ["pytest>=8"]
24
+
25
+ [project.entry-points.pytest11]
26
+ skipcheck_tm1_testcontainers = "skipcheck_tm1_testcontainers.plugin"
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["src/skipcheck_tm1_testcontainers"]
30
+
31
+ [tool.hatch.build.hooks.custom]
32
+ # hatch_build.py ships docker/paw/paw-local.sh in the package: PawContainer runs it in its runner
33
+ # container, as the Java build puts it in the jar. An editable install reads it from the repository.
34
+
35
+ [tool.hatch.build.targets.sdist]
36
+ include = ["src", "tests", "README.md", "hatch_build.py"]
37
+
38
+ [tool.pytest.ini_options]
39
+ testpaths = ["tests"]
@@ -0,0 +1,41 @@
1
+ """Testcontainers for IBM Planning Analytics (TM1): TM1 Server, the Admin Server, TM1 Web,
2
+ Planning Analytics Workspace, Cognos Analytics and Keycloak in Docker, for tests. The Python port
3
+ of the Java ``tm1-testcontainers`` module, on testcontainers-python.
4
+
5
+ No IBM software is included: a source (:class:`Tm1Source` and the others) supplies it.
6
+ """
7
+
8
+ from ._container import GenericContainer, Network, docker_available, reuse_enabled
9
+ from .cognos import CognosContainer, KeycloakContainer, Namespace, User
10
+ from .environment import PlanningAnalyticsEnvironment
11
+ from .paw import PawContainer, PawSession
12
+ from .requires import RequiresCognos, RequiresPaw, RequiresTm1, RequiresTm1Web
13
+ from .sources import CognosSource, PawSource, Tm1Source, Tm1WebSource
14
+ from .tm1 import Tm1AdminServerContainer, Tm1Seed, Tm1ServerContainer
15
+ from .web import Tm1WebContainer
16
+
17
+ __all__ = [
18
+ "CognosContainer",
19
+ "CognosSource",
20
+ "GenericContainer",
21
+ "KeycloakContainer",
22
+ "Namespace",
23
+ "Network",
24
+ "PawContainer",
25
+ "PawSession",
26
+ "PawSource",
27
+ "PlanningAnalyticsEnvironment",
28
+ "RequiresCognos",
29
+ "RequiresPaw",
30
+ "RequiresTm1",
31
+ "RequiresTm1Web",
32
+ "Tm1AdminServerContainer",
33
+ "Tm1Seed",
34
+ "Tm1ServerContainer",
35
+ "Tm1Source",
36
+ "Tm1WebContainer",
37
+ "Tm1WebSource",
38
+ "User",
39
+ "docker_available",
40
+ "reuse_enabled",
41
+ ]