Skip to content

Commit

Permalink
feat: add ExternalConfig.connection_id property to connect to exter…
Browse files Browse the repository at this point in the history
…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 d93986e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions google/cloud/bigquery/external_config.py
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_external_config.py
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down

0 comments on commit d93986e

Please sign in to comment.