Skip to content

Commit

Permalink
fix(test-db): removed attribute (apache#25525)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Oct 5, 2023
1 parent 4532079 commit 89b0599
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 79 deletions.
104 changes: 27 additions & 77 deletions superset/cli/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@
"tmp_superset_test_table_user_prefs",
metadata_obj,
Column("pref_id", Integer, primary_key=True),
Column("user_id", Integer, ForeignKey("user.user_id"), nullable=False),
Column(
"user_id",
Integer,
ForeignKey("tmp_superset_test_table_user.user_id"),
nullable=False,
),
Column("pref_name", String(40), nullable=False),
Column("pref_value", String(100)),
)
Expand Down Expand Up @@ -99,37 +104,30 @@ def get_tests(self, dialect: str) -> list[TestType]:
@registry.add("sqlite", "postgresql")
def test_datetime(console: Console, engine: Engine) -> None:
"""
Create a table with a timestamp column.
Create a table with a timestamp column and read value back.
"""
console.print("[bold]Testing datetime support...")

md = MetaData()
table = Table(
"test",
md,
Column("ts", DateTime),
)

try:
console.print("Creating a table with a timestamp column...")
md.create_all(engine)
console.print("[green]Table created!")
console.print("Creating a table with a timestamp column...")
md.create_all(engine)
console.print("[green]Table created!")

now = datetime.now()
now = datetime.now()

console.print("Inserting timestamp value...")
stmt = insert(table).values(ts=now)
engine.execute(stmt)
console.print("Inserting timestamp value...")
insert_stmt = insert(table).values(ts=now)
engine.execute(insert_stmt)

console.print("Reading timestamp value...")
stmt = select(table)
row = engine.execute(stmt).fetchone()
assert row[0] == now
console.print(":thumbs_up: [green]Success!")
except Exception as ex: # pylint: disable=broad-except
console.print(f"[red]Test failed: {ex}")
console.print("[bold]Exiting...")
sys.exit(1)
console.print("Reading timestamp value...")
select_stmt = select(table)
row = engine.execute(select_stmt).fetchone()
assert row[0] == now
console.print(":thumbs_up: [green]Success!")


@click.command()
Expand Down Expand Up @@ -355,63 +353,15 @@ def test_database_connectivity(console: Console, engine: Engine) -> None:
color = "green" if result == 1 else "red"
console.print(f"[{color}]> {result}")

console.print("[bold]Checking that we can create tables...")
try:
metadata_obj.create_all(engine)
console.print("[green]Tables created!")
except Exception as ex: # pylint: disable=broad-except
console.print(f"[red]Unable to create tables: {ex}")
console.print("[bold]Exiting...")
sys.exit(1)

console.print("[bold]Checking that we can insert data...")
stmt = insert(user).values(
user_name="beto",
email="[email protected]",
nickname="Beto",
)
try:
console.print(
"sql>",
stmt.compile(
dialect=engine.dialect,
compile_kwargs={"literal_binds": True},
),
)
engine.execute(stmt)
except Exception as ex: # pylint: disable=broad-except
console.print(f"[red]Unable to insert data: {ex}")
console.print("[bold]Exiting...")
sys.exit(1)

console.print("[bold]Checking that we can read data...")
stmt = select(user).where(user.c.user_name == "beto")
try:
console.print(
"sql>",
stmt.compile(
dialect=engine.dialect,
compile_kwargs={"literal_binds": True},
),
)
result = engine.execute(stmt).fetchall()
console.print(f"[green]> {result}")
except Exception as ex: # pylint: disable=broad-except
console.print(f"[red]Unable to read data: {ex}")
console.print("[bold]Exiting...")
sys.exit(1)

console.print("[bold]Checking that we can drop tables...")
try:
metadata_obj.drop_all(engine)
console.print("[green]Done!")
except Exception as ex: # pylint: disable=broad-except
console.print(f"[red]Unable to drop tables: {ex}")
console.print("[bold]Exiting...")
sys.exit(1)

# run engine-specific tests
if tests := registry.get_tests(engine.dialect.name):
console.print("[bold]Running engine-specific tests...")
for test in tests:
test(console, engine)
docstring = (test.__doc__ or test.__name__).strip().splitlines()[0]
try:
console.print(f"[bold]{docstring}...")
test(console, engine)
except Exception as ex: # pylint: disable=broad-except
console.print(f"[red]Test failed: {ex}")
console.print("[bold]Exiting...")
sys.exit(1)
2 changes: 0 additions & 2 deletions superset/db_engine_specs/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"subqueries": "Supports subqueries",
"alias_in_select": "Allows aliases in the SELECT statement",
"alias_in_orderby": "Allows referencing aliases in the ORDER BY statement",
"secondary_time_columns": "Supports secondary time columns",
"time_groupby_inline": (
"Allows omitting time filters from inline GROUP BYs"
), # E: line too long (80 > 79 characters)
Expand Down Expand Up @@ -230,7 +229,6 @@ def generate_table() -> list[list[Any]]:
"subqueries",
"alias_in_select",
"alias_in_orderby",
"secondary_time_columns",
"time_groupby_inline",
"alias_to_source_column",
"order_by_not_in_select",
Expand Down

0 comments on commit 89b0599

Please sign in to comment.