Skip to content

Commit 52430b5

Browse files
Add tests
1 parent 385ea6c commit 52430b5

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from opentelemetry.test.test_base import TestBase
2525

2626

27+
# pylint: disable=too-many-public-methods
2728
class TestDBApiIntegration(TestBase):
2829
def setUp(self):
2930
super().setUp()
@@ -303,6 +304,59 @@ def test_compatible_build_version_psycopg_psycopg2_libpq(self):
303304
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}'\*/;",
304305
)
305306

307+
def test_executemany_psycopg2_integration_comment(self):
308+
connect_module = mock.MagicMock()
309+
connect_module.__name__ = "psycopg2"
310+
connect_module.__version__ = "1.2.3"
311+
connect_module.__libpq_version__ = 123
312+
connect_module.apilevel = 123
313+
connect_module.threadsafety = 123
314+
connect_module.paramstyle = "test"
315+
316+
db_integration = dbapi.DatabaseApiIntegration(
317+
"testname",
318+
"postgresql",
319+
enable_commenter=True,
320+
commenter_options={"db_driver": True, "dbapi_level": False},
321+
connect_module=connect_module,
322+
)
323+
mock_connection = db_integration.wrapped_connection(
324+
mock_connect, {}, {}
325+
)
326+
cursor = mock_connection.cursor()
327+
cursor.executemany("Select 1;")
328+
self.assertRegex(
329+
cursor.query,
330+
r"Select 1 /\*db_driver='psycopg2%%3A1.2.3',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}'\*/;",
331+
)
332+
333+
def test_executemany_psycopg_integration_comment(self):
334+
connect_module = mock.MagicMock()
335+
connect_module.__name__ = "psycopg"
336+
connect_module.__version__ = "1.2.3"
337+
connect_module.pq = mock.MagicMock()
338+
connect_module.pq.__build_version__ = 123
339+
connect_module.apilevel = 123
340+
connect_module.threadsafety = 123
341+
connect_module.paramstyle = "test"
342+
343+
db_integration = dbapi.DatabaseApiIntegration(
344+
"testname",
345+
"postgresql",
346+
enable_commenter=True,
347+
commenter_options={"db_driver": True, "dbapi_level": False},
348+
connect_module=connect_module,
349+
)
350+
mock_connection = db_integration.wrapped_connection(
351+
mock_connect, {}, {}
352+
)
353+
cursor = mock_connection.cursor()
354+
cursor.executemany("Select 1;")
355+
self.assertRegex(
356+
cursor.query,
357+
r"Select 1 /\*db_driver='psycopg%%3A1.2.3',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}'\*/;",
358+
)
359+
306360
def test_executemany_mysqlconnector_integration_comment(self):
307361
connect_module = mock.MagicMock()
308362
connect_module.__name__ = "mysql.connector"

0 commit comments

Comments
 (0)