@@ -36,6 +36,7 @@ def test_constructor():
3636 "https://www.googleapis.com/auth/cloud-platform" ,
3737 "https://www.googleapis.com/auth/cloud-platform.read-only" ,
3838 ],
39+ api_audience = "foo2.googleapis.com" ,
3940 )
4041
4142 assert options .api_endpoint == "foo.googleapis.com"
@@ -46,6 +47,7 @@ def test_constructor():
4647 "https://www.googleapis.com/auth/cloud-platform" ,
4748 "https://www.googleapis.com/auth/cloud-platform.read-only" ,
4849 ]
50+ assert options .api_audience == "foo2.googleapis.com"
4951
5052
5153def test_constructor_with_encrypted_cert_source ():
@@ -72,6 +74,36 @@ def test_constructor_with_both_cert_sources():
7274 )
7375
7476
77+ def test_constructor_with_api_key ():
78+
79+ options = client_options .ClientOptions (
80+ api_endpoint = "foo.googleapis.com" ,
81+ client_cert_source = get_client_cert ,
82+ quota_project_id = "quote-proj" ,
83+ api_key = "api-key" ,
84+ scopes = [
85+ "https://www.googleapis.com/auth/cloud-platform" ,
86+ "https://www.googleapis.com/auth/cloud-platform.read-only" ,
87+ ],
88+ )
89+
90+ assert options .api_endpoint == "foo.googleapis.com"
91+ assert options .client_cert_source () == (b"cert" , b"key" )
92+ assert options .quota_project_id == "quote-proj"
93+ assert options .api_key == "api-key"
94+ assert options .scopes == [
95+ "https://www.googleapis.com/auth/cloud-platform" ,
96+ "https://www.googleapis.com/auth/cloud-platform.read-only" ,
97+ ]
98+
99+
100+ def test_constructor_with_both_api_key_and_credentials_file ():
101+ with pytest .raises (ValueError ):
102+ client_options .ClientOptions (
103+ api_key = "api-key" , credentials_file = "path/to/credentials.json" ,
104+ )
105+
106+
75107def test_from_dict ():
76108 options = client_options .from_dict (
77109 {
@@ -83,6 +115,7 @@ def test_from_dict():
83115 "https://www.googleapis.com/auth/cloud-platform" ,
84116 "https://www.googleapis.com/auth/cloud-platform.read-only" ,
85117 ],
118+ "api_audience" : "foo2.googleapis.com" ,
86119 }
87120 )
88121
@@ -94,6 +127,8 @@ def test_from_dict():
94127 "https://www.googleapis.com/auth/cloud-platform" ,
95128 "https://www.googleapis.com/auth/cloud-platform.read-only" ,
96129 ]
130+ assert options .api_key is None
131+ assert options .api_audience == "foo2.googleapis.com"
97132
98133
99134def test_from_dict_bad_argument ():
@@ -112,6 +147,6 @@ def test_repr():
112147
113148 assert (
114149 repr (options )
115- == "ClientOptions: {'api_endpoint': 'foo.googleapis.com', 'client_cert_source': None, 'client_encrypted_cert_source': None}"
116- or "ClientOptions: {'client_encrypted_cert_source': None, 'client_cert_source': None, 'api_endpoint': 'foo.googleapis.com'}"
150+ == "ClientOptions: {'api_endpoint': 'foo.googleapis.com', 'client_cert_source': None, 'client_encrypted_cert_source': None, 'api_key': None }"
151+ or "ClientOptions: {'client_encrypted_cert_source': None, 'client_cert_source': None, 'api_endpoint': 'foo.googleapis.com', 'api_key': None }"
117152 )
0 commit comments