Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mysql DBA tests #101

Merged
merged 1 commit into from
Nov 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,17 @@ async def _execute_by_steps(self, db_adapter_query: DBAdapterQuery) -> AsyncIter

chunk_size = db_adapter_query.get_effective_chunk_size(self._default_chunk_size)
query = db_adapter_query.query
debug_compiled_query = db_adapter_query.debug_compiled_query
escape_percent = not db_adapter_query.is_dashsql_query # DON'T escape only for dashsql
compiled_query, compiled_query_parameters = compile_mysql_query(
query, dialect=self._dialect, escape_percent=escape_percent
)
debug_query = query if isinstance(query, str) else compile_query_for_debug(query, self._dialect)
debug_query = None
if self._target_dto.pass_db_query_to_user:
if debug_compiled_query is not None:
debug_query = debug_compiled_query
else:
debug_query = query if isinstance(query, str) else compile_query_for_debug(query, self._dialect)

with self.handle_execution_error(debug_query):
async with self._get_connection(db_adapter_query.db_name) as conn:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def _(exc: Exception) -> bool:
return _


def is_source_connect_async_error() -> ExcMatchCondition:
def _(exc: Exception) -> bool:
if isinstance(exc, pymysql.OperationalError):
if len(exc.args) >= 2 and exc.args[0] == 2003:
return True
return False

return _


class AsyncMysqlChainedDbErrorTransformer(error_transformer.ChainedDbErrorTransformer):
@staticmethod
def _get_error_kw(
Expand All @@ -53,6 +63,10 @@ def _get_error_kw(

async_mysql_db_error_transformer: DbErrorTransformer = AsyncMysqlChainedDbErrorTransformer(
(
Rule(
when=is_source_connect_async_error(),
then_raise=exc.SourceConnectError,
),
Rule(
when=is_table_does_not_exist_async_error(),
then_raise=MysqlSourceDoesNotExistError,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from dl_core_testing.testcases.adapter import BaseAsyncAdapterTestClass
from dl_testing.regulated_test import RegulatedTestParams

from dl_connector_mysql.core.async_adapters_mysql import AsyncMySQLAdapter
from dl_connector_mysql.core.target_dto import MySQLConnTargetDTO
from dl_connector_mysql_tests.db.core.base import BaseMySQLTestClass


class TestAsyncMySQLAdapter(
BaseMySQLTestClass,
BaseAsyncAdapterTestClass[MySQLConnTargetDTO],
):
test_params = RegulatedTestParams(
mark_tests_skipped={
BaseAsyncAdapterTestClass.test_default_pass_db_query_to_user: "Not relevant",
},
)

ASYNC_ADAPTER_CLS = AsyncMySQLAdapter
Loading