@@ -1331,11 +1331,6 @@ def _verifyBooleanResourceProperties(self, job, config):
1331
1331
config ['useLegacySql' ])
1332
1332
else :
1333
1333
self .assertIsNone (job .use_legacy_sql )
1334
- if 'dryRun' in config :
1335
- self .assertEqual (job .dry_run ,
1336
- config ['dryRun' ])
1337
- else :
1338
- self .assertIsNone (job .dry_run )
1339
1334
1340
1335
def _verifyIntegerResourceProperties (self , job , config ):
1341
1336
if 'maximumBillingTier' in config :
@@ -1366,48 +1361,58 @@ def _verifyQueryParameters(self, job, config):
1366
1361
for found , expected in zip (job .query_parameters , query_parameters ):
1367
1362
self .assertEqual (found .to_api_repr (), expected )
1368
1363
1364
+ def _verify_configuration_properties (self , job , configuration ):
1365
+ if 'dryRun' in configuration :
1366
+ self .assertEqual (job .dry_run ,
1367
+ configuration ['dryRun' ])
1368
+ else :
1369
+ self .assertIsNone (job .dry_run )
1370
+
1369
1371
def _verifyResourceProperties (self , job , resource ):
1370
1372
self ._verifyReadonlyResourceProperties (job , resource )
1371
1373
1372
- config = resource .get ('configuration' , {}).get ('query' )
1373
- self ._verifyBooleanResourceProperties (job , config )
1374
- self ._verifyIntegerResourceProperties (job , config )
1375
- self ._verify_udf_resources (job , config )
1376
- self ._verifyQueryParameters (job , config )
1374
+ configuration = resource .get ('configuration' , {})
1375
+ self ._verify_configuration_properties (job , configuration )
1377
1376
1378
- self .assertEqual (job .query , config ['query' ])
1379
- if 'createDisposition' in config :
1377
+ query_config = resource .get ('configuration' , {}).get ('query' )
1378
+ self ._verifyBooleanResourceProperties (job , query_config )
1379
+ self ._verifyIntegerResourceProperties (job , query_config )
1380
+ self ._verify_udf_resources (job , query_config )
1381
+ self ._verifyQueryParameters (job , query_config )
1382
+
1383
+ self .assertEqual (job .query , query_config ['query' ])
1384
+ if 'createDisposition' in query_config :
1380
1385
self .assertEqual (job .create_disposition ,
1381
- config ['createDisposition' ])
1386
+ query_config ['createDisposition' ])
1382
1387
else :
1383
1388
self .assertIsNone (job .create_disposition )
1384
- if 'defaultDataset' in config :
1389
+ if 'defaultDataset' in query_config :
1385
1390
dataset = job .default_dataset
1386
1391
ds_ref = {
1387
1392
'projectId' : dataset .project ,
1388
1393
'datasetId' : dataset .name ,
1389
1394
}
1390
- self .assertEqual (ds_ref , config ['defaultDataset' ])
1395
+ self .assertEqual (ds_ref , query_config ['defaultDataset' ])
1391
1396
else :
1392
1397
self .assertIsNone (job .default_dataset )
1393
- if 'destinationTable' in config :
1398
+ if 'destinationTable' in query_config :
1394
1399
table = job .destination
1395
1400
tb_ref = {
1396
1401
'projectId' : table .project ,
1397
1402
'datasetId' : table .dataset_name ,
1398
1403
'tableId' : table .name
1399
1404
}
1400
- self .assertEqual (tb_ref , config ['destinationTable' ])
1405
+ self .assertEqual (tb_ref , query_config ['destinationTable' ])
1401
1406
else :
1402
1407
self .assertIsNone (job .destination )
1403
- if 'priority' in config :
1408
+ if 'priority' in query_config :
1404
1409
self .assertEqual (job .priority ,
1405
- config ['priority' ])
1410
+ query_config ['priority' ])
1406
1411
else :
1407
1412
self .assertIsNone (job .priority )
1408
- if 'writeDisposition' in config :
1413
+ if 'writeDisposition' in query_config :
1409
1414
self .assertEqual (job .write_disposition ,
1410
- config ['writeDisposition' ])
1415
+ query_config ['writeDisposition' ])
1411
1416
else :
1412
1417
self .assertIsNone (job .write_disposition )
1413
1418
@@ -1575,7 +1580,6 @@ def test_begin_w_alternate_client(self):
1575
1580
'priority' : 'INTERACTIVE' ,
1576
1581
'useQueryCache' : True ,
1577
1582
'useLegacySql' : True ,
1578
- 'dryRun' : True ,
1579
1583
'writeDisposition' : 'WRITE_TRUNCATE' ,
1580
1584
'maximumBillingTier' : 4 ,
1581
1585
'maximumBytesBilled' : 123456
@@ -1599,6 +1603,7 @@ def test_begin_w_alternate_client(self):
1599
1603
job .use_query_cache = True
1600
1604
job .use_legacy_sql = True
1601
1605
job .dry_run = True
1606
+ RESOURCE ['configuration' ]['dryRun' ] = True
1602
1607
job .write_disposition = 'WRITE_TRUNCATE'
1603
1608
job .maximum_billing_tier = 4
1604
1609
job .maximum_bytes_billed = 123456
@@ -1616,6 +1621,7 @@ def test_begin_w_alternate_client(self):
1616
1621
'jobId' : self .JOB_NAME ,
1617
1622
},
1618
1623
'configuration' : {
1624
+ 'dryRun' : True ,
1619
1625
'query' : QUERY_CONFIGURATION ,
1620
1626
},
1621
1627
}
@@ -1775,6 +1781,41 @@ def test_begin_w_positional_query_parameter(self):
1775
1781
self .assertEqual (req ['data' ], SENT )
1776
1782
self ._verifyResourceProperties (job , RESOURCE )
1777
1783
1784
+ def test_dry_run_query (self ):
1785
+ PATH = '/projects/%s/jobs' % (self .PROJECT ,)
1786
+ RESOURCE = self ._makeResource ()
1787
+ # Ensure None for missing server-set props
1788
+ del RESOURCE ['statistics' ]['creationTime' ]
1789
+ del RESOURCE ['etag' ]
1790
+ del RESOURCE ['selfLink' ]
1791
+ del RESOURCE ['user_email' ]
1792
+ conn = _Connection (RESOURCE )
1793
+ client = _Client (project = self .PROJECT , connection = conn )
1794
+ job = self ._make_one (self .JOB_NAME , self .QUERY , client )
1795
+ job .dry_run = True
1796
+ RESOURCE ['configuration' ]['dryRun' ] = True
1797
+
1798
+ job .begin ()
1799
+ self .assertEqual (job .udf_resources , [])
1800
+ self .assertEqual (len (conn ._requested ), 1 )
1801
+ req = conn ._requested [0 ]
1802
+ self .assertEqual (req ['method' ], 'POST' )
1803
+ self .assertEqual (req ['path' ], PATH )
1804
+ SENT = {
1805
+ 'jobReference' : {
1806
+ 'projectId' : self .PROJECT ,
1807
+ 'jobId' : self .JOB_NAME ,
1808
+ },
1809
+ 'configuration' : {
1810
+ 'query' : {
1811
+ 'query' : self .QUERY
1812
+ },
1813
+ 'dryRun' : True ,
1814
+ },
1815
+ }
1816
+ self .assertEqual (req ['data' ], SENT )
1817
+ self ._verifyResourceProperties (job , RESOURCE )
1818
+
1778
1819
def test_exists_miss_w_bound_client (self ):
1779
1820
PATH = '/projects/%s/jobs/%s' % (self .PROJECT , self .JOB_NAME )
1780
1821
conn = _Connection ()
0 commit comments