@@ -606,8 +606,9 @@ def test_create_table_w_schema_and_query(self):
606606 self .assertEqual (got .view_query , query )
607607
608608 def test_create_table_w_external (self ):
609- from google .cloud .bigquery .table import Table
610609 from google .cloud .bigquery .external_config import ExternalConfig
610+ from google .cloud .bigquery .job import SourceFormat
611+ from google .cloud .bigquery .table import Table
611612
612613 path = 'projects/%s/datasets/%s/tables' % (
613614 self .PROJECT , self .DS_ID )
@@ -621,7 +622,7 @@ def test_create_table_w_external(self):
621622 'tableId' : self .TABLE_ID
622623 },
623624 'externalDataConfiguration' : {
624- 'sourceFormat' : ' CSV' ,
625+ 'sourceFormat' : SourceFormat . CSV ,
625626 'autodetect' : True ,
626627 },
627628 }
@@ -644,7 +645,7 @@ def test_create_table_w_external(self):
644645 'tableId' : self .TABLE_ID ,
645646 },
646647 'externalDataConfiguration' : {
647- 'sourceFormat' : ' CSV' ,
648+ 'sourceFormat' : SourceFormat . CSV ,
648649 'autodetect' : True ,
649650 },
650651 'labels' : {},
@@ -653,7 +654,8 @@ def test_create_table_w_external(self):
653654 self .assertEqual (got .table_id , self .TABLE_ID )
654655 self .assertEqual (got .project , self .PROJECT )
655656 self .assertEqual (got .dataset_id , self .DS_ID )
656- self .assertEqual (got .external_data_configuration .source_format , 'CSV' )
657+ self .assertEqual (got .external_data_configuration .source_format ,
658+ SourceFormat .CSV )
657659 self .assertEqual (got .external_data_configuration .autodetect , True )
658660
659661 def test_get_table (self ):
@@ -1228,7 +1230,9 @@ def test_get_job_miss_w_explict_project(self):
12281230 self .assertEqual (req ['query_params' ], {'projection' : 'full' })
12291231
12301232 def test_get_job_hit (self ):
1233+ from google .cloud .bigquery .job import CreateDisposition
12311234 from google .cloud .bigquery .job import QueryJob
1235+ from google .cloud .bigquery .job import WriteDisposition
12321236
12331237 JOB_ID = 'query_job'
12341238 QUERY_DESTINATION_TABLE = 'query_destination_table'
@@ -1248,8 +1252,8 @@ def test_get_job_hit(self):
12481252 'datasetId' : self .DS_ID ,
12491253 'tableId' : QUERY_DESTINATION_TABLE ,
12501254 },
1251- 'createDisposition' : ' CREATE_IF_NEEDED' ,
1252- 'writeDisposition' : ' WRITE_TRUNCATE' ,
1255+ 'createDisposition' : CreateDisposition . CREATE_IF_NEEDED ,
1256+ 'writeDisposition' : WriteDisposition . WRITE_TRUNCATE ,
12531257 }
12541258 },
12551259 }
@@ -1261,8 +1265,10 @@ def test_get_job_hit(self):
12611265
12621266 self .assertIsInstance (job , QueryJob )
12631267 self .assertEqual (job .job_id , JOB_ID )
1264- self .assertEqual (job .create_disposition , 'CREATE_IF_NEEDED' )
1265- self .assertEqual (job .write_disposition , 'WRITE_TRUNCATE' )
1268+ self .assertEqual (job .create_disposition ,
1269+ CreateDisposition .CREATE_IF_NEEDED )
1270+ self .assertEqual (job .write_disposition ,
1271+ WriteDisposition .WRITE_TRUNCATE )
12661272
12671273 self .assertEqual (len (conn ._requested ), 1 )
12681274 req = conn ._requested [0 ]
@@ -1328,10 +1334,12 @@ def test_cancel_job_hit(self):
13281334 self .assertEqual (req ['query_params' ], {'projection' : 'full' })
13291335
13301336 def test_list_jobs_defaults (self ):
1331- from google .cloud .bigquery .job import LoadJob
13321337 from google .cloud .bigquery .job import CopyJob
1338+ from google .cloud .bigquery .job import CreateDisposition
13331339 from google .cloud .bigquery .job import ExtractJob
1340+ from google .cloud .bigquery .job import LoadJob
13341341 from google .cloud .bigquery .job import QueryJob
1342+ from google .cloud .bigquery .job import WriteDisposition
13351343
13361344 SOURCE_TABLE = 'source_table'
13371345 DESTINATION_TABLE = 'destination_table'
@@ -1362,8 +1370,8 @@ def test_list_jobs_defaults(self):
13621370 'datasetId' : self .DS_ID ,
13631371 'tableId' : QUERY_DESTINATION_TABLE ,
13641372 },
1365- 'createDisposition' : ' CREATE_IF_NEEDED' ,
1366- 'writeDisposition' : ' WRITE_TRUNCATE' ,
1373+ 'createDisposition' : CreateDisposition . CREATE_IF_NEEDED ,
1374+ 'writeDisposition' : WriteDisposition . WRITE_TRUNCATE ,
13671375 }
13681376 },
13691377 }
@@ -1608,7 +1616,9 @@ def _initiate_resumable_upload_helper(self, num_retries=None):
16081616 from google .cloud .bigquery .client import _DEFAULT_CHUNKSIZE
16091617 from google .cloud .bigquery .client import _GENERIC_CONTENT_TYPE
16101618 from google .cloud .bigquery .client import _get_upload_headers
1611- from google .cloud .bigquery .job import LoadJob , LoadJobConfig
1619+ from google .cloud .bigquery .job import LoadJob
1620+ from google .cloud .bigquery .job import LoadJobConfig
1621+ from google .cloud .bigquery .job import SourceFormat
16121622
16131623 # Create mocks to be checked for doing transport.
16141624 resumable_url = 'http://test.invalid?upload_id=hey-you'
@@ -1622,7 +1632,7 @@ def _initiate_resumable_upload_helper(self, num_retries=None):
16221632 data = b'goodbye gudbi gootbee'
16231633 stream = io .BytesIO (data )
16241634 config = LoadJobConfig ()
1625- config .source_format = ' CSV'
1635+ config .source_format = SourceFormat . CSV
16261636 job = LoadJob (None , None , self .TABLE_REF , client , job_config = config )
16271637 metadata = job ._build_resource ()
16281638 upload , transport = client ._initiate_resumable_upload (
@@ -1675,7 +1685,9 @@ def test__initiate_resumable_upload_with_retry(self):
16751685 def _do_multipart_upload_success_helper (
16761686 self , get_boundary , num_retries = None ):
16771687 from google .cloud .bigquery .client import _get_upload_headers
1678- from google .cloud .bigquery .job import LoadJob , LoadJobConfig
1688+ from google .cloud .bigquery .job import LoadJob
1689+ from google .cloud .bigquery .job import LoadJobConfig
1690+ from google .cloud .bigquery .job import SourceFormat
16791691
16801692 fake_transport = self ._mock_transport (http_client .OK , {})
16811693 client = self ._make_one (project = self .PROJECT , _http = fake_transport )
@@ -1685,7 +1697,7 @@ def _do_multipart_upload_success_helper(
16851697 data = b'Bzzzz-zap \x00 \x01 \xf4 '
16861698 stream = io .BytesIO (data )
16871699 config = LoadJobConfig ()
1688- config .source_format = ' CSV'
1700+ config .source_format = SourceFormat . CSV
16891701 job = LoadJob (None , None , self .TABLE_REF , client , job_config = config )
16901702 metadata = job ._build_resource ()
16911703 size = len (data )
@@ -2838,7 +2850,7 @@ class TestClientUpload(object):
28382850 # NOTE: This is a "partner" to `TestClient` meant to test some of the
28392851 # "load_table_from_file" portions of `Client`. It also uses
28402852 # `pytest`-style tests rather than `unittest`-style.
2841-
2853+ from google . cloud . bigquery . job import SourceFormat
28422854 TABLE_REF = DatasetReference (
28432855 'project_id' , 'test_dataset' ).table ('test_table' )
28442856
@@ -2881,7 +2893,7 @@ def _make_do_upload_patch(cls, client, method,
28812893 'jobReference' : {'projectId' : 'project_id' , 'jobId' : 'job_id' },
28822894 'configuration' : {
28832895 'load' : {
2884- 'sourceFormat' : ' CSV' ,
2896+ 'sourceFormat' : SourceFormat . CSV ,
28852897 'destinationTable' : {
28862898 'projectId' : 'project_id' ,
28872899 'datasetId' : 'test_dataset' ,
@@ -2898,9 +2910,10 @@ def _make_file_obj():
28982910 @staticmethod
28992911 def _make_config ():
29002912 from google .cloud .bigquery .job import LoadJobConfig
2913+ from google .cloud .bigquery .job import SourceFormat
29012914
29022915 config = LoadJobConfig ()
2903- config .source_format = ' CSV'
2916+ config .source_format = SourceFormat . CSV
29042917 return config
29052918
29062919 # High-level tests
@@ -2925,21 +2938,23 @@ def test_load_table_from_file_resumable(self):
29252938
29262939 def test_load_table_from_file_resumable_metadata (self ):
29272940 from google .cloud .bigquery .client import _DEFAULT_NUM_RETRIES
2941+ from google .cloud .bigquery .job import CreateDisposition
2942+ from google .cloud .bigquery .job import WriteDisposition
29282943
29292944 client = self ._make_client ()
29302945 file_obj = self ._make_file_obj ()
29312946
29322947 config = self ._make_config ()
29332948 config .allow_jagged_rows = False
29342949 config .allow_quoted_newlines = False
2935- config .create_disposition = ' CREATE_IF_NEEDED'
2950+ config .create_disposition = CreateDisposition . CREATE_IF_NEEDED
29362951 config .encoding = 'utf8'
29372952 config .field_delimiter = ','
29382953 config .ignore_unknown_values = False
29392954 config .max_bad_records = 0
29402955 config .quote_character = '"'
29412956 config .skip_leading_rows = 1
2942- config .write_disposition = ' WRITE_APPEND'
2957+ config .write_disposition = WriteDisposition . WRITE_APPEND
29432958 config .null_marker = r'\N'
29442959
29452960 expected_config = {
0 commit comments