Skip to content

Commit

Permalink
mark db_test
Browse files Browse the repository at this point in the history
  • Loading branch information
jx2lee committed Nov 24, 2024
1 parent 07fbc89 commit c733f2e
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions providers/tests/microsoft/mssql/hooks/test_mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
except ImportError:
pytest.skip("MSSQL not available", allow_module_level=True)

pytestmark = pytest.mark.db_test

PYMSSQL_CONN = Connection(
conn_type="mssql", host="ip", schema="share", login="username", password="password", port=8081
)
Expand All @@ -55,15 +57,6 @@
port=8081,
extra={"SQlalchemy_Scheme": "mssql+testdriver", "myparam": "5@-//*"},
)
PYMSSQL_CONN_WITH_EXTRA = Connection(
conn_type="mssql",
host="test-server",
schema="test-db",
login="test-user",
password="test-password",
port=8081,
extra={"login_timeout": 30, "charset": "utf8", "tds_version": "7.0", "appname": "airflow"},
)


def get_primary_keys(self, table: str) -> list[str]:
Expand All @@ -88,28 +81,6 @@ def test_get_conn_should_return_connection(self, get_connection, mssql_get_conn)
assert mssql_get_conn.return_value == conn
mssql_get_conn.assert_called_once()

@mock.patch("airflow.providers.microsoft.mssql.hooks.mssql.pymssql.connect")
@mock.patch("airflow.providers.common.sql.hooks.sql.DbApiHook.get_connection")
def test_get_conn_with_extra_parameters(self, mock_get_connection, mock_connect):
mock_get_connection.return_value = PYMSSQL_CONN_WITH_EXTRA

hook = MsSqlHook()
hook.get_conn()

mock_connect.assert_called_once_with(
server="test-server",
user="test-user",
password="test-password",
database="test-db",
port="8081",
login_timeout=30,
charset="utf8",
tds_version="7.0",
appname="airflow",
)

assert hook.sqlalchemy_scheme == hook.DEFAULT_SQLALCHEMY_SCHEME

@mock.patch("airflow.providers.microsoft.mssql.hooks.mssql.MsSqlHook.get_conn")
@mock.patch("airflow.providers.common.sql.hooks.sql.DbApiHook.get_connection")
def test_set_autocommit_should_invoke_autocommit(self, get_connection, mssql_get_conn):
Expand Down Expand Up @@ -296,3 +267,10 @@ def test_generate_insert_sql(self, get_connection):
replace=True,
)
assert sql == load_file("resources", "replace.sql")

@mock.patch("airflow.providers.microsoft.mssql.hooks.mssql.MsSqlHook.get_connection")
def test_get_extra(self, get_connection):
get_connection.return_value = PYMSSQL_CONN_ALT_2

hook = MsSqlHook()
assert hook.get_connection().extra

0 comments on commit c733f2e

Please sign in to comment.