Skip to content

Commit d1d2afc

Browse files
committed
Fix test_db2.py: update mocks and SQL assertions for TYPE column in table_exists()
table_exists() now SELECTs TABSCHEMA, TABNAME, TYPE (3 columns) instead of just TABSCHEMA, TABNAME (2 columns). Three unit test locations needed updating: 1. test_table_exists_found — mock tuple 2→3, SQL assertion updated 2. test_create_table_primary_key_not_null — SQL assertion updated 3. test_comments_on_table — SQL assertion updated
1 parent 5803c11 commit d1d2afc

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

tests/core/engine_adapter/test_db2.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,17 @@ def test_type_mapping_comprehensive(adapter: Db2EngineAdapter):
114114

115115

116116
def test_table_exists_found(adapter: Db2EngineAdapter):
117-
"""table_exists returns True and queries SYSCAT.TABLES with UPPER() wrapping."""
118-
adapter.cursor.fetchone.return_value = ("TEST_SCHEMA", "TEST_TABLE")
117+
"""table_exists returns True and queries SYSCAT.TABLES with UPPER() wrapping.
118+
TYPE column is now selected so the cache stores the correct DataObjectType.
119+
"""
120+
adapter.cursor.fetchone.return_value = ("TEST_SCHEMA", "TEST_TABLE", "T")
119121

120122
assert adapter.table_exists("test_schema.test_table") is True
121123

122124
# Exact SQL: identifiers are quoted by quote_identifiers=True in execute().
123125
# SYSCAT.TABLES is a catalog reference so it renders as "SYSCAT"."TABLES".
124126
assert to_sql_calls(adapter) == [
125-
'SELECT "TABSCHEMA", "TABNAME" FROM "SYSCAT"."TABLES" '
127+
'SELECT "TABSCHEMA", "TABNAME", "TYPE" FROM "SYSCAT"."TABLES" '
126128
"WHERE UPPER(\"TABSCHEMA\") = 'TEST_SCHEMA' AND UPPER(\"TABNAME\") = 'TEST_TABLE'"
127129
]
128130

@@ -189,7 +191,7 @@ def test_create_table_primary_key_not_null(adapter: Db2EngineAdapter):
189191
# omitting it would cause Db2 to raise SQL0542N at CREATE TABLE time.
190192
assert to_sql_calls(adapter) == [
191193
# table_exists check
192-
'SELECT "TABSCHEMA", "TABNAME" FROM "SYSCAT"."TABLES" '
194+
'SELECT "TABSCHEMA", "TABNAME", "TYPE" FROM "SYSCAT"."TABLES" '
193195
"WHERE UPPER(\"TABSCHEMA\") = 'TEST_SCHEMA' AND UPPER(\"TABNAME\") = 'TEST_TABLE'",
194196
# CREATE TABLE
195197
'CREATE TABLE "test_schema"."test_table" '
@@ -441,7 +443,7 @@ def test_comments_on_table(adapter: Db2EngineAdapter):
441443
)
442444

443445
assert to_sql_calls(adapter) == [
444-
'SELECT "TABSCHEMA", "TABNAME" FROM "SYSCAT"."TABLES" '
446+
'SELECT "TABSCHEMA", "TABNAME", "TYPE" FROM "SYSCAT"."TABLES" '
445447
"WHERE UPPER(\"TABSCHEMA\") = 'TEST_SCHEMA' AND UPPER(\"TABNAME\") = 'TEST_TABLE'",
446448
'CREATE TABLE "test_schema"."test_table" ("id" INTEGER, "name" VARCHAR(100))',
447449
'COMMENT ON TABLE "test_schema"."test_table" IS \'Test table\'',

0 commit comments

Comments
 (0)