Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tammy-baylis-swi committed Oct 10, 2024
1 parent b0a9efd commit 4dd9f73
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,32 @@ def test_compatible_build_version_psycopg_psycopg2_libpq(self):
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
)

def test_executemany_mysqlconnector_integration_comment(self):
connect_module = mock.MagicMock()
connect_module.__name__ = "mysql.connector"
connect_module.__version__ = "1.2.3"
connect_module.apilevel = 123
connect_module.threadsafety = 123
connect_module.paramstyle = "test"

db_integration = dbapi.DatabaseApiIntegration(
"testname",
"mysql",
enable_commenter=True,
commenter_options={"db_driver": True, "dbapi_level": False},
connect_module=connect_module,
)

mock_connection = db_integration.wrapped_connection(
mock_connect, {}, {}
)
cursor = mock_connection.cursor()
cursor.executemany("Select 1;")
self.assertRegex(
cursor.query,
r"Select 1 /\*db_driver='mysql.connector%%3A1.2.3',dbapi_threadsafety=123,driver_paramstyle='test',mysql_client_version='1.2.3',traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
)

def test_executemany_flask_integration_comment(self):
connect_module = mock.MagicMock()
connect_module.__name__ = "test"
Expand Down Expand Up @@ -335,6 +361,11 @@ def test_executemany_flask_integration_comment(self):
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',flask=1,libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
)

clear_context = context.set_value(
"SQLCOMMENTER_ORM_TAGS_AND_VALUES", {}, current_context
)
context.attach(clear_context)

def test_callproc(self):
db_integration = dbapi.DatabaseApiIntegration(
"testname", "testcomponent"
Expand Down Expand Up @@ -418,6 +449,12 @@ class MockCursor:
def __init__(self) -> None:
self.query = ""
self.params = None
# Mock mysql.connector modules and method
self._cnx = mock.MagicMock()
self._cnx._cmysql = mock.MagicMock()
self._cnx._cmysql.get_client_info = mock.MagicMock(
return_value="1.2.3"
)

# pylint: disable=unused-argument, no-self-use
def execute(self, query, params=None, throw_exception=False):
Expand Down

0 comments on commit 4dd9f73

Please sign in to comment.