Skip to content

Commit

Permalink
Add test from cratedb-toolkit + cratedb testcontainer dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
surister committed Feb 12, 2024
1 parent 43c45fb commit 62a6bb4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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()
25 changes: 25 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -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 == []

0 comments on commit 62a6bb4

Please sign in to comment.