From 1240481a1ba2543d3ca03c522be7605c465479eb Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 12 Oct 2018 18:26:50 -0400 Subject: [PATCH] Add 'LoadTableConfig.destination_table_friendly_name' property. Closes #5093. --- bigquery/google/cloud/bigquery/job.py | 19 ++++++++++ bigquery/tests/unit/test_job.py | 53 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/bigquery/google/cloud/bigquery/job.py b/bigquery/google/cloud/bigquery/job.py index c293156a94e9..08205184bfcb 100644 --- a/bigquery/google/cloud/bigquery/job.py +++ b/bigquery/google/cloud/bigquery/job.py @@ -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 diff --git a/bigquery/tests/unit/test_job.py b/bigquery/tests/unit/test_job.py index a00823682969..33103fc75c62 100644 --- a/bigquery/tests/unit/test_job.py +++ b/bigquery/tests/unit/test_job.py @@ -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)