@@ -72,6 +72,36 @@ def test_constructor_with_both_cert_sources():
72
72
)
73
73
74
74
75
+ def test_constructor_with_api_key ():
76
+
77
+ options = client_options .ClientOptions (
78
+ api_endpoint = "foo.googleapis.com" ,
79
+ client_cert_source = get_client_cert ,
80
+ quota_project_id = "quote-proj" ,
81
+ api_key = "api-key" ,
82
+ scopes = [
83
+ "https://www.googleapis.com/auth/cloud-platform" ,
84
+ "https://www.googleapis.com/auth/cloud-platform.read-only" ,
85
+ ],
86
+ )
87
+
88
+ assert options .api_endpoint == "foo.googleapis.com"
89
+ assert options .client_cert_source () == (b"cert" , b"key" )
90
+ assert options .quota_project_id == "quote-proj"
91
+ assert options .api_key == "api-key"
92
+ assert options .scopes == [
93
+ "https://www.googleapis.com/auth/cloud-platform" ,
94
+ "https://www.googleapis.com/auth/cloud-platform.read-only" ,
95
+ ]
96
+
97
+
98
+ def test_constructor_with_both_api_key_and_credentials_file ():
99
+ with pytest .raises (ValueError ):
100
+ client_options .ClientOptions (
101
+ api_key = "api-key" , credentials_file = "path/to/credentials.json" ,
102
+ )
103
+
104
+
75
105
def test_from_dict ():
76
106
options = client_options .from_dict (
77
107
{
@@ -94,6 +124,7 @@ def test_from_dict():
94
124
"https://www.googleapis.com/auth/cloud-platform" ,
95
125
"https://www.googleapis.com/auth/cloud-platform.read-only" ,
96
126
]
127
+ assert options .api_key is None
97
128
98
129
99
130
def test_from_dict_bad_argument ():
@@ -112,6 +143,6 @@ def test_repr():
112
143
113
144
assert (
114
145
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'}"
146
+ == "ClientOptions: {'api_endpoint': 'foo.googleapis.com', 'client_cert_source': None, 'client_encrypted_cert_source': None, 'api_key': None }"
147
+ or "ClientOptions: {'client_encrypted_cert_source': None, 'client_cert_source': None, 'api_endpoint': 'foo.googleapis.com', 'api_key': None }"
117
148
)
0 commit comments