Skip to content
Permalink
Browse files
feat: add ExternalConfig.connection_id property to connect to exter…
…nal sources (#560)

* feat: add `ExternalConfig.connection_id` property to connect to external sources

* add tests

* fix unit tests
  • Loading branch information
tswast committed Mar 22, 2021
1 parent 97ee6ec commit d93986e0259952257f2571f60719b52099c29c0c
Showing with 25 additions and 0 deletions.
  1. +17 −0 google/cloud/bigquery/external_config.py
  2. +8 −0 tests/unit/test_external_config.py
@@ -760,6 +760,23 @@ def schema(self):
prop = self._properties.get("schema", {})
return [SchemaField.from_api_repr(field) for field in prop.get("fields", [])]

@property
def connection_id(self):
"""Optional[str]: [Experimental] ID of a BigQuery Connection API
resource.
.. WARNING::
This feature is experimental. Pre-GA features may have limited
support, and changes to pre-GA features may not be compatible with
other pre-GA versions.
"""
return self._properties.get("connectionId")

@connection_id.setter
def connection_id(self, value):
self._properties["connectionId"] = value

@schema.setter
def schema(self, value):
prop = value
@@ -74,6 +74,7 @@ def test_to_api_repr_base(self):
ec.autodetect = True
ec.ignore_unknown_values = False
ec.compression = "compression"
ec.connection_id = "path/to/connection"
ec.schema = [schema.SchemaField("full_name", "STRING", mode="REQUIRED")]

exp_schema = {
@@ -87,10 +88,17 @@ def test_to_api_repr_base(self):
"autodetect": True,
"ignoreUnknownValues": False,
"compression": "compression",
"connectionId": "path/to/connection",
"schema": exp_schema,
}
self.assertEqual(got_resource, exp_resource)

def test_connection_id(self):
ec = external_config.ExternalConfig("")
self.assertIsNone(ec.connection_id)
ec.connection_id = "path/to/connection"
self.assertEqual(ec.connection_id, "path/to/connection")

def test_schema_None(self):
ec = external_config.ExternalConfig("")
ec.schema = None

0 comments on commit d93986e

Please sign in to comment.