@@ -5822,3 +5822,95 @@ def test_table_reference_to_bqstorage_v1_stable(table_path):
58225822 for klass in (mut .TableReference , mut .Table , mut .TableListItem ):
58235823 got = klass .from_string (table_path ).to_bqstorage ()
58245824 assert got == expected
5825+
5826+
5827+ @pytest .fixture (scope = "class" )
5828+ def external_catalog_table_options ():
5829+ from google .cloud .bigquery .external_config import ExternalCatalogTableOptions
5830+
5831+ return ExternalCatalogTableOptions (
5832+ connection_id = "connection123" ,
5833+ parameters = {"key" : "value" },
5834+ storage_descriptor = "placeholder" ,
5835+ )
5836+
5837+
5838+ class TestExternalCatalogTableOptions :
5839+ PROJECT = "project_id"
5840+ DS_ID = "dataset_id"
5841+ TABLE_NAME = "table_name"
5842+
5843+ @staticmethod
5844+ def _get_target_class ():
5845+ from google .cloud .bigquery .table import Table
5846+
5847+ return Table
5848+
5849+ @classmethod
5850+ def _make_one (self , * args , ** kw ):
5851+ return self ._get_target_class ()(* args , ** kw )
5852+
5853+ def test_external_catalog_table_options_getter (
5854+ self , external_catalog_table_options
5855+ ):
5856+ from google .cloud .bigquery .external_config import ExternalCatalogTableOptions
5857+
5858+ # create objects for the test
5859+ dataset = DatasetReference (self .PROJECT , self .DS_ID )
5860+ table_ref = dataset .table (self .TABLE_NAME )
5861+ table = self ._make_one (table_ref )
5862+
5863+ # Confirm that external catalog table options have not been set
5864+ assert table .external_catalog_table_options is None
5865+
5866+ # Add an ExternalCatalogTableOptions object to the table.
5867+ table ._properties [
5868+ "externalCatalogTableOptions"
5869+ ] = external_catalog_table_options
5870+ table_repr = table .to_api_repr ()
5871+
5872+ # Extract the ecto object.
5873+ ecto_output = table_repr ["externalCatalogTableOptions" ]
5874+
5875+ # Confirm that external catalog table options are an
5876+ # ExternalCatalogTableOptions object
5877+ assert isinstance (ecto_output , ExternalCatalogTableOptions )
5878+
5879+ expected = {
5880+ "connectionId" : "connection123" ,
5881+ "parameters" : {"key" : "value" },
5882+ "storageDescriptor" : "placeholder" ,
5883+ }
5884+ result = ecto_output .to_api_repr ()
5885+
5886+ # Confirm that the api_repr of the ecto_output matches the inputs
5887+ assert result == expected
5888+
5889+ def test_external_catalog_table_options_setter (
5890+ self , external_catalog_table_options
5891+ ):
5892+ # from google.cloud.bigquery.external_config import ExternalCatalogTableOptions
5893+
5894+ # create objects for the test
5895+ dataset = DatasetReference (self .PROJECT , self .DS_ID )
5896+ table_ref = dataset .table (self .TABLE_NAME )
5897+ table = self ._make_one (table_ref )
5898+
5899+ # Add an ExternalCatalogTableOptions object to the table.
5900+ table .external_catalog_table_options = external_catalog_table_options
5901+ expected = {
5902+ "tableReference" : {
5903+ "projectId" : "project_id" ,
5904+ "datasetId" : "dataset_id" ,
5905+ "tableId" : "table_name" ,
5906+ },
5907+ "labels" : {},
5908+ "externalCatalogTableOptions" : {
5909+ "connectionId" : "connection123" ,
5910+ "parameters" : {"key" : "value" },
5911+ "storageDescriptor" : "placeholder" ,
5912+ },
5913+ }
5914+ # Confirm that the api_repr of the ecto_output matches the inputs
5915+ result = table .to_api_repr ()
5916+ assert result == expected
0 commit comments