-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test from cratedb-toolkit + cratedb testcontainer dependencies.
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 == [] |