Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tests/integration/dbapi/async/V2/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from random import randint
from random import choice, randint
from typing import Tuple

from pytest import fixture
Expand Down Expand Up @@ -79,13 +79,27 @@ async def engine_v2(
engine_name: str,
) -> str:
cursor = connection_system_engine_v2.cursor()
# randomize the db name to avoid conflicts
suffix = "".join(choice("0123456789") for _ in range(2))
engine_name = f"{engine_name}{suffix}_async"
await cursor.execute(f"CREATE ENGINE IF NOT EXISTS {engine_name}")
await cursor.execute(f"START ENGINE {engine_name}")
yield engine_name
await cursor.execute(f"STOP ENGINE {engine_name}")
await cursor.execute(f"DROP ENGINE IF EXISTS {engine_name}")


@fixture
async def setup_v2_db(connection_system_engine_v2: Connection, use_db_name: str):
use_db_name = use_db_name + "_async"
with connection_system_engine_v2.cursor() as cursor:
# randomize the db name to avoid conflicts
suffix = "".join(choice("0123456789") for _ in range(2))
await cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}")
yield f"{use_db_name}{suffix}"
await cursor.execute(f"DROP DATABASE {use_db_name}{suffix}")


@fixture
async def connection_system_engine_no_db(
auth: Auth,
Expand Down
15 changes: 2 additions & 13 deletions tests/integration/dbapi/async/V2/test_queries_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from datetime import date, datetime
from decimal import Decimal
from os import environ
from random import choice, randint
from random import randint
from typing import Callable, Generator, List

from pytest import fixture, mark, raises
from pytest import mark, raises

from firebolt.async_db import Binary, Connection, Cursor, OperationalError
from firebolt.async_db.connection import connect
Expand Down Expand Up @@ -434,17 +434,6 @@ async def test_bytea_roundtrip(
), "Invalid bytea data returned after roundtrip"


@fixture
async def setup_v2_db(connection_system_engine_v2: Connection, use_db_name: str):
use_db_name = use_db_name + "_async"
with connection_system_engine_v2.cursor() as cursor:
# randomize the db name to avoid conflicts
suffix = "".join(choice("0123456789") for _ in range(2))
await cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}")
yield f"{use_db_name}{suffix}"
await cursor.execute(f"DROP DATABASE {use_db_name}{suffix}")


@mark.xfail("dev" not in environ[API_ENDPOINT_ENV], reason="Only works on dev")
async def test_use_database(
setup_v2_db,
Expand Down
17 changes: 8 additions & 9 deletions tests/integration/dbapi/async/V2/test_system_engine_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,17 @@ async def test_system_engine_v2_account(connection_system_engine_v2: Connection)


async def test_system_engine_use_engine(
connection_system_engine_v2: Connection, database_name: str, engine_name: str
connection_system_engine_v2: Connection, setup_v2_db: str, engine_v2: str
):
table_name = "test_table_async"
with connection_system_engine_v2.cursor() as cursor:
await cursor.execute(f"CREATE DATABASE IF NOT EXISTS {database_name}")
await cursor.execute(f"USE DATABASE {database_name}")
await cursor.execute(f"CREATE ENGINE IF NOT EXISTS {engine_name}")
await cursor.execute(f"USE ENGINE {engine_name}")
await cursor.execute("CREATE TABLE IF NOT EXISTS test_table (id int)")
await cursor.execute(f"USE DATABASE {setup_v2_db}")
await cursor.execute(f"USE ENGINE {engine_v2}")
await cursor.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (id int)")
# This query fails if we're not on a user engine
await cursor.execute("INSERT INTO test_table VALUES (1)")
await cursor.execute(f"INSERT INTO {table_name} VALUES (1)")
await cursor.execute("USE ENGINE system")
# Werify we've switched to system by making previous query fail
with raises(OperationalError):
await cursor.execute("INSERT INTO test_table VALUES (1)")
await cursor.execute("DROP TABLE IF EXISTS test_table")
await cursor.execute(f"INSERT INTO {table_name} VALUES (1)")
await cursor.execute(f"DROP TABLE IF EXISTS {table_name}")
16 changes: 15 additions & 1 deletion tests/integration/dbapi/sync/V2/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from random import randint
from random import choice, randint
from typing import Tuple

from pytest import fixture
Expand Down Expand Up @@ -78,6 +78,9 @@ def engine_v2(
connection_system_engine_v2: Connection,
engine_name: str,
) -> str:
# randomize the db name to avoid conflicts
suffix = "".join(choice("0123456789") for _ in range(2))
engine_name = f"{engine_name}{suffix}_sync"
cursor = connection_system_engine_v2.cursor()
cursor.execute(f"CREATE ENGINE IF NOT EXISTS {engine_name}")
cursor.execute(f"START ENGINE {engine_name}")
Expand All @@ -86,6 +89,17 @@ def engine_v2(
cursor.execute(f"DROP ENGINE IF EXISTS {engine_name}")


@fixture(scope="session")
def setup_v2_db(connection_system_engine_v2, use_db_name):
use_db_name = f"{use_db_name}_sync"
with connection_system_engine_v2.cursor() as cursor:
# randomize the db name to avoid conflicts
suffix = "".join(choice("0123456789") for _ in range(2))
cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}")
yield f"{use_db_name}{suffix}"
cursor.execute(f"DROP DATABASE {use_db_name}{suffix}")


@fixture
def connection_system_engine_no_db(
auth: Auth,
Expand Down
15 changes: 2 additions & 13 deletions tests/integration/dbapi/sync/V2/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from datetime import date, datetime
from decimal import Decimal
from os import environ
from random import choice, randint
from random import randint
from threading import Thread
from typing import Any, Callable, Generator, List

from pytest import fixture, mark, raises
from pytest import mark, raises

from firebolt.async_db.cursor import QueryStatus
from firebolt.client.auth import Auth
Expand Down Expand Up @@ -514,17 +514,6 @@ def test_bytea_roundtrip(
), "Invalid bytea data returned after roundtrip"


@fixture(scope="module")
def setup_v2_db(connection_system_engine_v2, use_db_name):
use_db_name = f"{use_db_name}_sync"
with connection_system_engine_v2.cursor() as cursor:
# randomize the db name to avoid conflicts
suffix = "".join(choice("0123456789") for _ in range(2))
cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}")
yield f"{use_db_name}{suffix}"
cursor.execute(f"DROP DATABASE {use_db_name}{suffix}")


@mark.xfail("dev" not in environ[API_ENDPOINT_ENV], reason="Only works on dev")
def test_use_database(
setup_v2_db,
Expand Down
17 changes: 8 additions & 9 deletions tests/integration/dbapi/sync/V2/test_system_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,17 @@ def test_system_engine_v2_account(connection_system_engine_v2: Connection):


def test_system_engine_use_engine(
connection_system_engine_v2: Connection, database_name: str, engine_name: str
connection_system_engine_v2: Connection, setup_v2_db: str, engine_v2: str
):
table_name = "test_table_sync"
with connection_system_engine_v2.cursor() as cursor:
cursor.execute(f"CREATE DATABASE IF NOT EXISTS {database_name}")
cursor.execute(f"USE DATABASE {database_name}")
cursor.execute(f"CREATE ENGINE IF NOT EXISTS {engine_name}")
cursor.execute(f"USE ENGINE {engine_name}")
cursor.execute("CREATE TABLE IF NOT EXISTS test_table (id int)")
cursor.execute(f"USE DATABASE {setup_v2_db}")
cursor.execute(f"USE ENGINE {engine_v2}")
cursor.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (id int)")
# This query fails if we're not on a user engine
cursor.execute("INSERT INTO test_table VALUES (1)")
cursor.execute(f"INSERT INTO {table_name} VALUES (1)")
cursor.execute("USE ENGINE system")
# Werify we've switched to system by making previous query fail
with raises(OperationalError):
cursor.execute("INSERT INTO test_table VALUES (1)")
cursor.execute("DROP TABLE IF EXISTS test_table")
cursor.execute(f"INSERT INTO {table_name} VALUES (1)")
cursor.execute(f"DROP TABLE IF EXISTS {table_name}")