@@ -1217,6 +1217,64 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_setter():
1217
1217
assert sent_config ["maximumBytesBilled" ] == "10203"
1218
1218
1219
1219
1220
+ @pytest .mark .usefixtures ("ipython_interactive" )
1221
+ @pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1222
+ def test_bigquery_magic_with_no_query_cache (monkeypatch ):
1223
+ ip = IPython .get_ipython ()
1224
+ ip .extension_manager .load_extension ("google.cloud.bigquery" )
1225
+ conn = make_connection ()
1226
+ monkeypatch .setattr (magics .context , "_connection" , conn )
1227
+ monkeypatch .setattr (magics .context , "project" , "project-from-context" )
1228
+
1229
+ # --no_query_cache option should override context.
1230
+ monkeypatch .setattr (
1231
+ magics .context .default_query_job_config , "use_query_cache" , True
1232
+ )
1233
+
1234
+ ip .run_cell_magic ("bigquery" , "--no_query_cache" , QUERY_STRING )
1235
+
1236
+ conn .api_request .assert_called_with (
1237
+ method = "POST" ,
1238
+ path = "/projects/project-from-context/jobs" ,
1239
+ data = mock .ANY ,
1240
+ timeout = DEFAULT_TIMEOUT ,
1241
+ )
1242
+ jobs_insert_call = [
1243
+ call
1244
+ for call in conn .api_request .call_args_list
1245
+ if call [1 ]["path" ] == "/projects/project-from-context/jobs"
1246
+ ][0 ]
1247
+ assert not jobs_insert_call [1 ]["data" ]["configuration" ]["query" ]["useQueryCache" ]
1248
+
1249
+
1250
+ @pytest .mark .usefixtures ("ipython_interactive" )
1251
+ @pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1252
+ def test_context_with_no_query_cache_from_context (monkeypatch ):
1253
+ ip = IPython .get_ipython ()
1254
+ ip .extension_manager .load_extension ("google.cloud.bigquery" )
1255
+ conn = make_connection ()
1256
+ monkeypatch .setattr (magics .context , "_connection" , conn )
1257
+ monkeypatch .setattr (magics .context , "project" , "project-from-context" )
1258
+ monkeypatch .setattr (
1259
+ magics .context .default_query_job_config , "use_query_cache" , False
1260
+ )
1261
+
1262
+ ip .run_cell_magic ("bigquery" , "" , QUERY_STRING )
1263
+
1264
+ conn .api_request .assert_called_with (
1265
+ method = "POST" ,
1266
+ path = "/projects/project-from-context/jobs" ,
1267
+ data = mock .ANY ,
1268
+ timeout = DEFAULT_TIMEOUT ,
1269
+ )
1270
+ jobs_insert_call = [
1271
+ call
1272
+ for call in conn .api_request .call_args_list
1273
+ if call [1 ]["path" ] == "/projects/project-from-context/jobs"
1274
+ ][0 ]
1275
+ assert not jobs_insert_call [1 ]["data" ]["configuration" ]["query" ]["useQueryCache" ]
1276
+
1277
+
1220
1278
@pytest .mark .usefixtures ("ipython_interactive" )
1221
1279
@pytest .mark .skipif (pandas is None , reason = "Requires `pandas`" )
1222
1280
def test_bigquery_magic_w_progress_bar_type_w_context_setter (monkeypatch ):
0 commit comments