pyrelukko.testcontainers module¶
Testcontainers to be used in PyTests, for an real life fixture see
tests/conftest.py (relukko_backend):
Example:
@pytest.fixture(scope="session")
def relukko_backend():
with Network() as rl_net:
with RelukkoDbContainer(net=rl_net,
image="postgres:16", hostname="relukkodb") as _db:
db_url = "postgresql://relukko:relukko@relukkodb/relukko"
with RelukkoContainer(rl_net, db_url=db_url) as backend:
relukko = RelukkoClient(
base_url=backend.get_api_url(), api_key="somekey")
yield relukko, backend
- class pyrelukko.testcontainers.PgWaitStrategy¶
Bases:
WaitStrategy- wait_until_ready(container)¶
Wait until the container is ready.
- class pyrelukko.testcontainers.RelukkoContainer(net, db_url, image='registry.gitlab.com/relukko/relukko:latest')¶
Bases:
ServerContainerStarts a “Relukko” container for testing.
Ensures the “Relukko” container is up, running and ready to use.
- Parameters:
net (Network) – The
testcontainersNetwork in which also the required PostgreSQL database is reachable.db_url (str,) – The URL where the PostgreSQL is reachable, defaults to None.
image (str, optional) – The Relukko container image to start, defaults to “registry.gitlab.com/relukko/relukko:latest”. The value in the env var
CI_RELUKKO_CONTAINER_IMAGEtakes precedence over the value given as argument.
- get_api_url()¶
Return the URL where the Relukko API server can be reached.
- Returns:
API Url
- Return type:
str
- class pyrelukko.testcontainers.RelukkoDbContainer(net, image='postgres:latest', port=5432, username=None, password=None, dbname=None, driver='psycopg2', **kwargs)¶
Bases:
PostgresContainerStarts a PostgreSQL container for the Relukko API server.
Ensures the PostgreSQL container is up, running and ready to use.
- Parameters:
net (Network) – The
testcontainersNetwork in which also the Relukko API container will run.image (str, optional) – The PostgreSQL container image to start, defaults to “postgres:latest”.
port (int, optional) – The listening port of the PostgreSQL db, defaults to 5432.
username (str | None, optional) – The username of the PostgreSQL db main user, defaults to None.
password (str | None, optional) – The password of the PostgreSQL db main user, defaults to None.
dbname (str | None, optional) – The database name of the PostgreSQL db main database, defaults to None.
driver (str | None, optional) – The name of the driver to append to the connection string returned by
get_connection_url(), defaults to “psycopg2”.