@@ -52,3 +52,46 @@ def test_connection_closed(self):
5252 self .assertTrue (cursor .is_closed )
5353 with self .assertRaises (InterfaceError ):
5454 cursor .execute ("SELECT * FROM database" )
55+
56+ def test_executemany_on_closed_cursor (self ):
57+ with mock .patch (
58+ "google.cloud.spanner_v1.instance.Instance.exists" ,
59+ return_value = True ,
60+ ):
61+ with mock .patch (
62+ "google.cloud.spanner_v1.database.Database.exists" ,
63+ return_value = True ,
64+ ):
65+ connection = connect ("test-instance" , "test-database" )
66+
67+ cursor = connection .cursor ()
68+ cursor .close ()
69+
70+ with self .assertRaises (InterfaceError ):
71+ cursor .executemany (
72+ """SELECT * FROM table1 WHERE "col1" = @a1""" , ()
73+ )
74+
75+ def test_executemany (self ):
76+ operation = """SELECT * FROM table1 WHERE "col1" = @a1"""
77+ params_seq = ((1 ,), (2 ,))
78+
79+ with mock .patch (
80+ "google.cloud.spanner_v1.instance.Instance.exists" ,
81+ return_value = True ,
82+ ):
83+ with mock .patch (
84+ "google.cloud.spanner_v1.database.Database.exists" ,
85+ return_value = True ,
86+ ):
87+ connection = connect ("test-instance" , "test-database" )
88+
89+ cursor = connection .cursor ()
90+ with mock .patch (
91+ "google.cloud.spanner_dbapi.cursor.Cursor.execute"
92+ ) as execute_mock :
93+ cursor .executemany (operation , params_seq )
94+
95+ execute_mock .assert_has_calls (
96+ (mock .call (operation , (1 ,)), mock .call (operation , (2 ,)))
97+ )
0 commit comments