@@ -84,6 +84,14 @@ def setUp(self):
8484 "priority" : "batch" ,
8585 "maximum_bytes_billed" : 0 ,
8686 },
87+ "api_endpoint" : {
88+ "type" : "bigquery" ,
89+ "method" : "oauth" ,
90+ "project" : "dbt-unit-000000" ,
91+ "schema" : "dummy_schema" ,
92+ "threads" : 1 ,
93+ "api_endpoint" : "https://localhost:3001" ,
94+ },
8795 "impersonate" : {
8896 "type" : "bigquery" ,
8997 "method" : "oauth" ,
@@ -419,7 +427,7 @@ def test_cancel_open_connections_single(self):
419427 self .assertEqual (len (list (adapter .cancel_open_connections ())), 1 )
420428
421429 @patch ("dbt.adapters.bigquery.clients.ClientOptions" )
422- @patch ("dbt.adapters.bigquery.credentials.default " )
430+ @patch ("dbt.adapters.bigquery.credentials._create_bigquery_defaults " )
423431 @patch ("dbt.adapters.bigquery.clients.BigQueryClient" )
424432 def test_location_user_agent (self , MockClient , mock_auth_default , MockClientOptions ):
425433 creds = MagicMock ()
@@ -439,6 +447,28 @@ def test_location_user_agent(self, MockClient, mock_auth_default, MockClientOpti
439447 client_options = mock_client_options ,
440448 )
441449
450+ @patch ("dbt.adapters.bigquery.clients.ClientOptions" )
451+ @patch ("dbt.adapters.bigquery.credentials._create_bigquery_defaults" )
452+ @patch ("dbt.adapters.bigquery.clients.BigQueryClient" )
453+ def test_api_endpoint_settable (self , MockClient , mock_auth_default , MockClientOptions ):
454+ """Ensure api_endpoint is set on ClientOptions and passed to BigQueryClient."""
455+
456+ creds = MagicMock ()
457+ mock_auth_default .return_value = (creds , MagicMock ())
458+ mock_client_options = MockClientOptions .return_value
459+
460+ adapter = self .get_adapter ("api_endpoint" )
461+ connection = adapter .acquire_connection ("dummy" )
462+ MockClient .assert_not_called ()
463+ connection .handle
464+
465+ MockClientOptions .assert_called_once ()
466+ kwargs = MockClientOptions .call_args .kwargs
467+ assert kwargs .get ("api_endpoint" ) == "https://localhost:3001"
468+
469+ MockClient .assert_called_once ()
470+ assert MockClient .call_args .kwargs ["client_options" ] is mock_client_options
471+
442472
443473class HasUserAgent :
444474 PAT = re .compile (r"dbt-bigquery-\d+\.\d+\.\d+((a|b|rc)\d+)?" )
0 commit comments