Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InterSystems IRIS support #381

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- core
- elasticsearch
- google
- iris
- kafka
- keycloak
- localstack
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# /core
/elasticsearch @nivm @daTokenizer
/google @tillahoffmann
/iris @daimor
/kafka @ash1425
/keycloak @timbmg
/localstack @ImFlog
Expand Down
1 change: 1 addition & 0 deletions iris/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. autoclass:: testcontainers.iris.IRISContainer
19 changes: 19 additions & 0 deletions iris/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from setuptools import setup, find_namespace_packages

description = "InterSystems IRIS component of testcontainers-python."

setup(
name="testcontainers-iris",
version="0.0.1rc1",
packages=find_namespace_packages(),
description=description,
long_description=description,
long_description_content_type="text/x-rst",
url="https://github.com/testcontainers/testcontainers-python",
install_requires=[
"testcontainers-core",
"sqlalchemy",
"sqlalchemy-iris",
],
python_requires=">=3.7",
)
61 changes: 61 additions & 0 deletions iris/testcontainers/iris/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
from typing import Optional
from testcontainers.core.config import TIMEOUT
from testcontainers.core.generic import DbContainer
from testcontainers.core.utils import raise_for_deprecated_parameter
from testcontainers.core.waiting_utils import wait_for_logs, wait_container_is_ready


class IRISContainer(DbContainer):
"""
InterSystems IRIS database container.

Example:

The example spins up a IRIS database and connects to it using the :code:`intersystems-iris`
driver.

.. doctest::

>>> from testcontainers.iris import IRISContainer
>>> import sqlalchemy

>>> iris_container = IRISContainer("intersystemsdc/iris-community:latest")
>>> with iris_container as iris:
... engine = sqlalchemy.create_engine(iris.get_connection_url())
... with engine.begin() as connection:
... result = connection.execute(sqlalchemy.text("select $zversion"))
... version, = result.fetchone()
>>> version
'IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2023.2 (Build 227U)...'
"""

def __init__(self, image: str = "intersystemsdc/iris-community:latest", port: int = 1972,
username: Optional[str] = None, password: Optional[str] = None,
dbname: Optional[str] = None, driver: str = "iris", **kwargs) -> None:
raise_for_deprecated_parameter(kwargs, "user", "username")
super(IRISContainer, self).__init__(image=image, **kwargs)
self.username = username or os.environ.get("IRIS_USERNAME", "test")
self.password = password or os.environ.get("IRIS_PASSWORD", "test")
self.dbname = dbname or os.environ.get("IRIS_NAMESPACE", "USER")
self.port = port
self.driver = driver

self.with_exposed_ports(self.port)

def _configure(self) -> None:
self.with_env("IRIS_USERNAME", self.username)
self.with_env("IRIS_PASSWORD", self.password)
self.with_env("IRIS_NAMESPACE", self.dbname)

def get_connection_url(self, host=None) -> str:
return super()._create_connection_url(
dialect=f"iris", username=self.username,
password=self.password, dbname=self.dbname, host=host,
port=self.port,
)

@wait_container_is_ready()
def _connect(self):
wait_for_logs(self, predicate="Enabling logons", timeout=TIMEOUT)
super()._connect()
12 changes: 12 additions & 0 deletions iris/tests/test_iris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sqlalchemy
from testcontainers.iris import IRISContainer


def test_docker_run_iris():
iris_container = IRISContainer("intersystemsdc/iris-community:2023.1.1.380.0-zpm")
with iris_container as iris:
engine = sqlalchemy.create_engine(iris.get_connection_url())
with engine.begin() as connection:
result = connection.execute(sqlalchemy.text("select $zversion"))
for row in result:
assert "2023.1.1 (Build 380U)" in row[0]
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-e file:compose
-e file:elasticsearch
-e file:google
-e file:iris
-e file:kafka
-e file:keycloak
-e file:localstack
Expand Down