Skip to content

Commit 00eca14

Browse files
authored
BigQuery: missing return value in LoadJobConfig.from_api_repr and LoadJobConfig Tests (#4727)
* BigQuery: missing return job config * BigQuery: LoadJobConfig tests
1 parent 879254e commit 00eca14

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

bigquery/google/cloud/bigquery/job.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ def from_api_repr(cls, resource):
674674
config._properties = copy.deepcopy(resource)
675675
config.schema = _parse_schema_resource(schema)
676676
config.skip_leading_rows = _int_or_none(slr)
677+
if config.skip_leading_rows is None:
678+
del config.skip_leading_rows
679+
return config
677680

678681

679682
class LoadJob(_AsyncJob):

bigquery/tests/unit/test_job.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,41 @@ def _verifyReadonlyResourceProperties(self, job, resource):
207207
self.assertIsNone(job.user_email)
208208

209209

210+
class TestLoadJobConfig(unittest.TestCase, _Base):
211+
JOB_TYPE = 'load'
212+
213+
def _make_resource(self, started=False, ended=False):
214+
resource = super(TestLoadJobConfig, self)._make_resource(
215+
started, ended)
216+
config = resource['configuration']['load']
217+
config['sourceUris'] = [self.SOURCE1]
218+
config['destinationTable'] = {
219+
'projectId': self.PROJECT,
220+
'datasetId': self.DS_ID,
221+
'tableId': self.TABLE_ID,
222+
}
223+
224+
return resource
225+
226+
@staticmethod
227+
def _get_target_class():
228+
from google.cloud.bigquery.job import LoadJobConfig
229+
return LoadJobConfig
230+
231+
def test_schema(self):
232+
from google.cloud.bigquery.schema import SchemaField
233+
config = self._get_target_class()()
234+
full_name = SchemaField('full_name', 'STRING', mode='REQUIRED')
235+
age = SchemaField('age', 'INTEGER', mode='REQUIRED')
236+
config.schema = [full_name, age]
237+
self.assertEqual(config.schema, [full_name, age])
238+
239+
def test_api_repr(self):
240+
resource = self._make_resource()
241+
config = self._get_target_class().from_api_repr(resource)
242+
self.assertEqual(config.to_api_repr(), resource)
243+
244+
210245
class TestLoadJob(unittest.TestCase, _Base):
211246
JOB_TYPE = 'load'
212247

0 commit comments

Comments
 (0)