Skip to content

Commit

Permalink
Add 'LoadTableConfig.destination_table_description' property.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Oct 17, 2018
1 parent 7c76fe3 commit 8a1d4fa
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
19 changes: 19 additions & 0 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,25 @@ def destination_encryption_configuration(self, value):
else:
self._del_sub_prop('destinationEncryptionConfiguration')

@property
def destination_table_description(self):
"""Union[str, None] name given to destination table.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.destinationTableProperties.description
"""
prop = self._get_sub_prop('destinationTableProperties')
if prop is not None:
return prop['description']

@destination_table_description.setter
def destination_table_description(self, value):
keys = [self._job_type, 'destinationTableProperties', 'description']
if value is not None:
_helpers._set_sub_prop(self._properties, keys, value)
else:
_helpers._del_sub_prop(self._properties, keys)

@property
def encoding(self):
"""google.cloud.bigquery.job.Encoding: The character encoding of the
Expand Down
53 changes: 53 additions & 0 deletions bigquery/tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,59 @@ def test_destination_encryption_configuration_setter_w_none(self):
self.assertNotIn(
'destinationEncryptionConfiguration', config._properties['load'])

def test_destination_table_description_missing(self):
config = self._get_target_class()()
self.assertIsNone(config.destination_table_description)

def test_destination_table_description_hit(self):
description = 'Description'
config = self._get_target_class()()
config._properties['load']['destinationTableProperties'] = {
'description': description,
}
self.assertEqual(
config.destination_table_description, description)

def test_destination_table_description_setter(self):
description = 'Description'
config = self._get_target_class()()
config.destination_table_description = description
expected = {
'description': description,
}
self.assertEqual(
config._properties['load']['destinationTableProperties'], expected)

def test_destination_table_description_setter_w_fn_already(self):
description = 'Description'
friendly_name = 'Friendly Name'
config = self._get_target_class()()
config._properties['load']['destinationTableProperties'] = {
'friendlyName': friendly_name,
}
config.destination_table_description = description
expected = {
'friendlyName': friendly_name,
'description': description,
}
self.assertEqual(
config._properties['load']['destinationTableProperties'], expected)

def test_destination_table_description_w_none(self):
description = 'Description'
friendly_name = 'Friendly Name'
config = self._get_target_class()()
config._properties['load']['destinationTableProperties'] = {
'description': description,
'friendlyName': friendly_name,
}
config.destination_table_description = None
expected = {
'friendlyName': friendly_name,
}
self.assertEqual(
config._properties['load']['destinationTableProperties'], expected)

def test_encoding_missing(self):
config = self._get_target_class()()
self.assertIsNone(config.encoding)
Expand Down

0 comments on commit 8a1d4fa

Please sign in to comment.