Skip to content

Commit 6d55edc

Browse files
suristeramotl
authored andcommitted
get_table_names(): Add software test from cratedb-toolkit
1 parent 91bc8de commit 6d55edc

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ release = [
112112
"twine<6",
113113
]
114114
test = [
115+
"cratedb-toolkit[testing]",
115116
"dask[dataframe]",
116117
"pandas<2.3",
117118
"pueblo>=0.0.7",

tests/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2021-2023, Crate.io Inc.
2+
# Distributed under the terms of the AGPLv3 license, see LICENSE.
3+
import pytest
4+
from cratedb_toolkit.testing.testcontainers.cratedb import CrateDBTestAdapter
5+
6+
# Use different schemas for storing the subsystem database tables, and the
7+
# test/example data, so that they do not accidentally touch the default `doc`
8+
# schema.
9+
TESTDRIVE_EXT_SCHEMA = "testdrive-ext"
10+
TESTDRIVE_DATA_SCHEMA = "testdrive-data"
11+
12+
13+
@pytest.fixture(scope="session")
14+
def cratedb_service():
15+
"""
16+
Provide a CrateDB service instance to the test suite.
17+
"""
18+
db = CrateDBTestAdapter()
19+
db.start()
20+
yield db
21+
db.stop()

tests/test_schema.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sqlalchemy as sa
2+
3+
from tests.conftest import TESTDRIVE_DATA_SCHEMA
4+
5+
6+
def test_correct_schema(cratedb_service):
7+
"""
8+
Tests that the correct schema is being picked up.
9+
"""
10+
database = cratedb_service.database
11+
12+
tablename = f'"{TESTDRIVE_DATA_SCHEMA}"."foobar"'
13+
inspector: sa.Inspector = sa.inspect(database.engine)
14+
database.run_sql(f"CREATE TABLE {tablename} AS SELECT 1")
15+
16+
assert TESTDRIVE_DATA_SCHEMA in inspector.get_schema_names()
17+
18+
table_names = inspector.get_table_names(schema=TESTDRIVE_DATA_SCHEMA)
19+
assert table_names == ["foobar"]
20+
21+
view_names = inspector.get_view_names(schema=TESTDRIVE_DATA_SCHEMA)
22+
assert view_names == []
23+
24+
indexes = inspector.get_indexes(tablename)
25+
assert indexes == []

0 commit comments

Comments
 (0)