@@ -36,6 +36,7 @@ def test_constructor():
36
36
"https://www.googleapis.com/auth/cloud-platform" ,
37
37
"https://www.googleapis.com/auth/cloud-platform.read-only" ,
38
38
],
39
+ api_audience = "foo2.googleapis.com" ,
39
40
)
40
41
41
42
assert options .api_endpoint == "foo.googleapis.com"
@@ -46,6 +47,7 @@ def test_constructor():
46
47
"https://www.googleapis.com/auth/cloud-platform" ,
47
48
"https://www.googleapis.com/auth/cloud-platform.read-only" ,
48
49
]
50
+ assert options .api_audience == "foo2.googleapis.com"
49
51
50
52
51
53
def test_constructor_with_encrypted_cert_source ():
@@ -72,6 +74,36 @@ def test_constructor_with_both_cert_sources():
72
74
)
73
75
74
76
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
+
75
107
def test_from_dict ():
76
108
options = client_options .from_dict (
77
109
{
@@ -83,6 +115,7 @@ def test_from_dict():
83
115
"https://www.googleapis.com/auth/cloud-platform" ,
84
116
"https://www.googleapis.com/auth/cloud-platform.read-only" ,
85
117
],
118
+ "api_audience" : "foo2.googleapis.com" ,
86
119
}
87
120
)
88
121
@@ -94,6 +127,8 @@ def test_from_dict():
94
127
"https://www.googleapis.com/auth/cloud-platform" ,
95
128
"https://www.googleapis.com/auth/cloud-platform.read-only" ,
96
129
]
130
+ assert options .api_key is None
131
+ assert options .api_audience == "foo2.googleapis.com"
97
132
98
133
99
134
def test_from_dict_bad_argument ():
@@ -112,6 +147,6 @@ def test_repr():
112
147
113
148
assert (
114
149
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 }"
117
152
)
0 commit comments