From 62a6bb41a1ba1f2c80de09ce5cf6d03081a329bd Mon Sep 17 00:00:00 2001 From: surister Date: Fri, 9 Feb 2024 16:50:19 +0100 Subject: [PATCH] Add test from cratedb-toolkit + cratedb testcontainer dependencies. --- pyproject.toml | 2 ++ tests/conftest.py | 21 +++++++++++++++++++++ tests/test_schema.py | 25 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/conftest.py create mode 100644 tests/test_schema.py diff --git a/pyproject.toml b/pyproject.toml index 5645f116..5cdf9669 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,6 +111,8 @@ release = [ "twine<5", ] test = [ + "testcontainers", # Temporarily until cratedb-toolkit[testing] fix is live. + "cratedb-toolkit[testing]", "dask", "pandas<2.2", "pytest<8", diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..88b10d9d --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,21 @@ +# Copyright (c) 2021-2023, Crate.io Inc. +# Distributed under the terms of the AGPLv3 license, see LICENSE. +import pytest +from cratedb_toolkit.testing.testcontainers.cratedb import CrateDBTestAdapter + +# Use different schemas for storing the subsystem database tables, and the +# test/example data, so that they do not accidentally touch the default `doc` +# schema. +TESTDRIVE_EXT_SCHEMA = "testdrive-ext" +TESTDRIVE_DATA_SCHEMA = "testdrive-data" + + +@pytest.fixture(scope="session") +def cratedb_service(): + """ + Provide a CrateDB service instance to the test suite. + """ + db = CrateDBTestAdapter() + db.start() + yield db + db.stop() diff --git a/tests/test_schema.py b/tests/test_schema.py new file mode 100644 index 00000000..83eb3481 --- /dev/null +++ b/tests/test_schema.py @@ -0,0 +1,25 @@ +import sqlalchemy as sa + +from tests.conftest import TESTDRIVE_DATA_SCHEMA + + +def test_correct_schema(cratedb_service): + """ + Tests that the correct schema is being picked up. + """ + database = cratedb_service.database + + tablename = f'"{TESTDRIVE_DATA_SCHEMA}"."foobar"' + inspector: sa.Inspector = sa.inspect(database.engine) + database.run_sql(f"CREATE TABLE {tablename} AS SELECT 1") + + assert TESTDRIVE_DATA_SCHEMA in inspector.get_schema_names() + + table_names = inspector.get_table_names(schema=TESTDRIVE_DATA_SCHEMA) + assert table_names == ["foobar"] + + view_names = inspector.get_view_names(schema=TESTDRIVE_DATA_SCHEMA) + assert view_names == [] + + indexes = inspector.get_indexes(tablename) + assert indexes == []