@@ -65,6 +65,11 @@ def test_transaction_tag(self):
65
65
from test .mockserver_tests .tags_model import Singer
66
66
67
67
add_singer_query_result ("SELECT singers.id, singers.name\n " + "FROM singers" )
68
+ add_single_singer_query_result (
69
+ "SELECT singers.id AS singers_id, singers.name AS singers_name\n "
70
+ "FROM singers\n "
71
+ "WHERE singers.id = @a0"
72
+ )
68
73
add_update_count ("INSERT INTO singers (id, name) VALUES (@a0, @a1)" , 1 )
69
74
engine = create_engine (
70
75
"spanner:///projects/p/instances/i/databases/d" ,
@@ -75,26 +80,32 @@ def test_transaction_tag(self):
75
80
engine .execution_options (transaction_tag = "my-transaction-tag" )
76
81
) as session :
77
82
# Execute a query and an insert statement in a read/write transaction.
83
+ session .get (Singer , 1 , execution_options = {"request_tag" : "my-tag-1" })
78
84
session .scalars (
79
- select (Singer ).execution_options (request_tag = "my-tag-1 " )
85
+ select (Singer ).execution_options (request_tag = "my-tag-2 " )
80
86
).all ()
87
+ session .connection ().execution_options (request_tag = "insert-singer" )
81
88
session .add (Singer (id = 1 , name = "Some Singer" ))
82
89
session .commit ()
83
90
84
91
# Verify the requests that we got.
85
92
requests = self .spanner_service .requests
86
- eq_ (5 , len (requests ))
93
+ eq_ (6 , len (requests ))
87
94
is_instance_of (requests [0 ], BatchCreateSessionsRequest )
88
95
is_instance_of (requests [1 ], BeginTransactionRequest )
89
96
is_instance_of (requests [2 ], ExecuteSqlRequest )
90
97
is_instance_of (requests [3 ], ExecuteSqlRequest )
91
- is_instance_of (requests [4 ], CommitRequest )
98
+ is_instance_of (requests [4 ], ExecuteSqlRequest )
99
+ is_instance_of (requests [5 ], CommitRequest )
92
100
for request in requests [2 :]:
93
101
eq_ ("my-transaction-tag" , request .request_options .transaction_tag )
102
+ eq_ ("my-tag-1" , requests [2 ].request_options .request_tag )
103
+ eq_ ("my-tag-2" , requests [3 ].request_options .request_tag )
104
+ eq_ ("insert-singer" , requests [4 ].request_options .request_tag )
94
105
95
106
96
- def add_singer_query_result ( sql : str ):
97
- result = result_set .ResultSet (
107
+ def empty_singer_result_set ( ):
108
+ return result_set .ResultSet (
98
109
dict (
99
110
metadata = result_set .ResultSetMetadata (
100
111
dict (
@@ -124,6 +135,10 @@ def add_singer_query_result(sql: str):
124
135
),
125
136
)
126
137
)
138
+
139
+
140
+ def add_singer_query_result (sql : str ):
141
+ result = empty_singer_result_set ()
127
142
result .rows .extend (
128
143
[
129
144
(
@@ -137,3 +152,16 @@ def add_singer_query_result(sql: str):
137
152
]
138
153
)
139
154
add_result (sql , result )
155
+
156
+
157
+ def add_single_singer_query_result (sql : str ):
158
+ result = empty_singer_result_set ()
159
+ result .rows .extend (
160
+ [
161
+ (
162
+ "1" ,
163
+ "Jane Doe" ,
164
+ ),
165
+ ]
166
+ )
167
+ add_result (sql , result )
0 commit comments