diff --git a/tests/clients/test_psycopg2.py b/tests/clients/test_psycopg2.py index 87bc1b08e..fe3820c89 100644 --- a/tests/clients/test_psycopg2.py +++ b/tests/clients/test_psycopg2.py @@ -17,9 +17,15 @@ class TestPsycoPG2(unittest.TestCase): def setUp(self): - self.db = psycopg2.connect(host=testenv['postgresql_host'], port=testenv['postgresql_port'], - user=testenv['postgresql_user'], password=testenv['postgresql_pw'], - database=testenv['postgresql_db']) + deprecated_param_name = self.shortDescription() == 'test_deprecated_parameter_database' + kwargs = { + 'host': testenv['postgresql_host'], + 'port': testenv['postgresql_port'], + 'user': testenv['postgresql_user'], + 'password': testenv['postgresql_pw'], + 'dbname' if not deprecated_param_name else 'database': testenv['postgresql_db'], + } + self.db = psycopg2.connect(**kwargs) database_setup_query = """ DROP TABLE IF EXISTS users; @@ -330,3 +336,29 @@ def test_cursor_ctx_mgr(self): self.assertEqual(db_span.data["pg"]["stmt"], "SELECT * from users") self.assertEqual(db_span.data["pg"]["host"], testenv["postgresql_host"]) self.assertEqual(db_span.data["pg"]["port"], testenv["postgresql_port"]) + + def test_deprecated_parameter_database(self): + """test_deprecated_parameter_database""" + + with tracer.start_active_span('test'): + self.cursor.execute("""SELECT * from users""") + affected_rows = self.cursor.rowcount + result = self.cursor.fetchone() + self.db.commit() + + self.assertEqual(1, affected_rows) + self.assertEqual(6, len(result)) + + spans = self.recorder.queued_spans() + self.assertEqual(2, len(spans)) + + db_span, test_span = spans + + self.assertEqual("test", test_span.data["sdk"]["name"]) + self.assertEqual(test_span.t, db_span.t) + self.assertEqual(db_span.p, test_span.s) + + self.assertIsNone(db_span.ec) + + self.assertEqual(db_span.n, "postgres") + self.assertEqual(db_span.data["pg"]["db"], testenv['postgresql_db']) diff --git a/tests/clients/test_pymysql.py b/tests/clients/test_pymysql.py index a92dd0e66..e80f3ade5 100644 --- a/tests/clients/test_pymysql.py +++ b/tests/clients/test_pymysql.py @@ -15,9 +15,16 @@ class TestPyMySQL(unittest.TestCase): def setUp(self): - self.db = pymysql.connect(host=testenv['mysql_host'], port=testenv['mysql_port'], - user=testenv['mysql_user'], passwd=testenv['mysql_pw'], - db=testenv['mysql_db']) + deprecated_param_name = self.shortDescription() == 'test_deprecated_parameter_db' + kwargs = { + 'host': testenv['mysql_host'], + 'port': testenv['mysql_port'], + 'user': testenv['mysql_user'], + 'passwd': testenv['mysql_pw'], + 'database' if not deprecated_param_name else 'db': testenv['mysql_db'], + } + self.db = pymysql.connect(**kwargs) + database_setup_query = """ DROP TABLE IF EXISTS users; | CREATE TABLE users( @@ -286,3 +293,27 @@ def test_cursor_ctx_mgr(self): self.assertEqual(db_span.data["mysql"]["stmt"], "SELECT * from users") self.assertEqual(db_span.data["mysql"]["host"], testenv["mysql_host"]) self.assertEqual(db_span.data["mysql"]["port"], testenv["mysql_port"]) + + def test_deprecated_parameter_db(self): + """test_deprecated_parameter_db""" + + with tracer.start_active_span('test'): + affected_rows = self.cursor.execute("""SELECT * from users""") + result = self.cursor.fetchone() + + self.assertEqual(1, affected_rows) + self.assertEqual(3, len(result)) + + spans = self.recorder.queued_spans() + self.assertEqual(2, len(spans)) + + db_span, test_span = spans + + self.assertEqual("test", test_span.data["sdk"]["name"]) + self.assertEqual(test_span.t, db_span.t) + self.assertEqual(db_span.p, test_span.s) + + self.assertIsNone(db_span.ec) + + self.assertEqual(db_span.n, "mysql") + self.assertEqual(db_span.data["mysql"]["db"], testenv['mysql_db']) \ No newline at end of file