Skip to content

Commit

Permalink
Add 'LoadTableConfig.destination_table_friendly_name' property.
Browse files Browse the repository at this point in the history
Closes #5093.
  • Loading branch information
tseaver committed Oct 17, 2018
1 parent 8a1d4fa commit 1240481
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 @@ -1006,6 +1006,25 @@ def destination_table_description(self, value):
else:
_helpers._del_sub_prop(self._properties, keys)

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

@destination_table_friendly_name.setter
def destination_table_friendly_name(self, value):
keys = [self._job_type, 'destinationTableProperties', 'friendlyName']
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 @@ -1339,6 +1339,59 @@ def test_destination_table_description_w_none(self):
self.assertEqual(
config._properties['load']['destinationTableProperties'], expected)

def test_destination_table_friendly_name_missing(self):
config = self._get_target_class()()
self.assertIsNone(config.destination_table_friendly_name)

def test_destination_table_friendly_name_hit(self):
friendly_name = 'Friendly Name'
config = self._get_target_class()()
config._properties['load']['destinationTableProperties'] = {
'friendlyName': friendly_name,
}
self.assertEqual(
config.destination_table_friendly_name, friendly_name)

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

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

def test_destination_table_friendly_name_w_none(self):
friendly_name = 'Friendly Name'
description = 'Description'
config = self._get_target_class()()
config._properties['load']['destinationTableProperties'] = {
'description': description,
'friendlyName': friendly_name,
}
config.destination_table_friendly_name = None
expected = {
'description': description,
}
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 1240481

Please sign in to comment.