Skip to content

Commit

Permalink
get_table_names(): Add software test from cratedb-toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
surister authored and amotl committed Jun 10, 2024
1 parent edc6f4d commit 8d8e732
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ release = [
"twine<6",
]
test = [
"cratedb-toolkit[testing]",
"dask[dataframe]",
"pandas<2.3",
"pueblo>=0.0.7",
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 8d8e732

Please sign in to comment.