@@ -63,6 +63,10 @@ def test_connector_config_invalid_types(self):
6363 dataconnect .ConnectorConfig (
6464 service_id = "starterproject" , location = 123 , connector = "my_connector"
6565 )
66+ with pytest .raises (ValueError , match = "connector must be a string" ):
67+ dataconnect .ConnectorConfig (
68+ service_id = "starterproject" , location = "us-east4" , connector = 456
69+ )
6670
6771
6872class TestDataConnect :
@@ -111,41 +115,15 @@ def test_client_successful(self, mock_get_client):
111115 mock_get_client .side_effect = lambda service , config : dataconnect .DataConnect (
112116 service ._app , config # pylint: disable=protected-access
113117 )
114- client_instance = dataconnect .client (self .config1 , app = self .app )
115- mock_get_client .assert_called_once_with (mock .ANY , self .config1 )
116- assert isinstance (client_instance , dataconnect .DataConnect )
117- assert client_instance .config is self .config1
118- assert client_instance .app is self .app
119-
120- @pytest .mark .parametrize ("config_a, config_b, expect_same" , [
121- (
122- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
123- dataconnect .ConnectorConfig ("s" , "l" , "c_diff" ),
124- False ,
125- ),
126- (
127- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
128- dataconnect .ConnectorConfig ("s" , "l_diff" , "c" ),
129- False ,
130- ),
131- (
132- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
133- dataconnect .ConnectorConfig ("s_diff" , "l" , "c" ),
134- False ,
135- ),
136- (
137- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
138- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
139- True ,
140- ),
141- ])
142- def test_client_caching_permutations (self , config_a , config_b , expect_same ):
143- client_a = dataconnect .client (config_a , app = self .app )
144- client_b = dataconnect .client (config_b , app = self .app )
145- if expect_same :
146- assert client_a is client_b
147- else :
148- assert client_a is not client_b
118+ client1 = dataconnect .client (self .config1 , app = self .app )
119+ client2 = dataconnect .client (self .config2 , app = self .app )
120+ assert mock_get_client .call_count == 2
121+ mock_get_client .assert_any_call (mock .ANY , self .config1 )
122+ mock_get_client .assert_any_call (mock .ANY , self .config2 )
123+ assert isinstance (client1 , dataconnect .DataConnect )
124+ assert client1 .config is self .config1
125+ assert client1 .app is self .app
126+ assert client2 .config is self .config2
149127
150128 def test_client_retrieval_different_apps_same_config (self ):
151129 app2 = firebase_admin .initialize_app (self .cred , name = "app2" )
@@ -163,7 +141,7 @@ def test_invalid_config_type(self):
163141 dataconnect .client ("not-a-config" , app = self .app )
164142
165143 def test_invalid_app_type (self ):
166- with pytest .raises (ValueError , match = "App must be of type firebase_admin.App " ):
144+ with pytest .raises (ValueError , match = "Illegal app argument " ):
167145 dataconnect .client (self .config1 , "not-a-app" )
168146
169147 def test_client_default_app (self ):
@@ -176,6 +154,16 @@ def test_client_none_config(self):
176154 with pytest .raises (ValueError , match = err_msg ):
177155 dataconnect .client (None , app = self .app )
178156
157+ @mock .patch .object (_utils , "get_app_service" , wraps = _utils .get_app_service )
158+ def test_uses_app_service_mechanism (self , mock_get_app_service ):
159+ """Ensures dataconnect.client uses the standard app service loader."""
160+ dataconnect .client (self .config1 , app = self .app )
161+ mock_get_app_service .assert_called_once ()
162+ args , _ = mock_get_app_service .call_args
163+ assert args [0 ] is self .app
164+ assert args [1 ] == "_data_connect_service"
165+ assert args [2 ] == dataconnect ._DataConnectService # pylint: disable=protected-access
166+
179167
180168class TestDataConnectService :
181169
@@ -204,28 +192,31 @@ def test_cache_miss_on_different_config(self):
204192 client2 = self .service .get_client (config2 )
205193 assert client1 is not client2
206194
207- @pytest .mark .parametrize ("config_a, config_b, expect_same" , [
208- (
209- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
210- dataconnect .ConnectorConfig ("s" , "l" , "c_diff" ),
211- False ,
212- ),
213- (
214- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
215- dataconnect .ConnectorConfig ("s" , "l_diff" , "c" ),
216- False ,
217- ),
218- (
219- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
220- dataconnect .ConnectorConfig ("s_diff" , "l" , "c" ),
221- False ,
222- ),
223- (
224- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
225- dataconnect .ConnectorConfig ("s" , "l" , "c" ),
226- True ,
227- ),
228- ])
195+ @pytest .mark .parametrize (
196+ "config_a, config_b, expect_same" ,
197+ [
198+ (
199+ dataconnect .ConnectorConfig ("s" , "l" , "c" ),
200+ dataconnect .ConnectorConfig ("s" , "l" , "c_diff" ),
201+ False ,
202+ ),
203+ (
204+ dataconnect .ConnectorConfig ("s" , "l" , "c" ),
205+ dataconnect .ConnectorConfig ("s" , "l_diff" , "c" ),
206+ False ,
207+ ),
208+ (
209+ dataconnect .ConnectorConfig ("s" , "l" , "c" ),
210+ dataconnect .ConnectorConfig ("s_diff" , "l" , "c" ),
211+ False ,
212+ ),
213+ (
214+ dataconnect .ConnectorConfig ("s" , "l" , "c" ),
215+ dataconnect .ConnectorConfig ("s" , "l" , "c" ),
216+ True ,
217+ ),
218+ ],
219+ )
229220 def test_complex_cache_key (self , config_a , config_b , expect_same ):
230221 client_a = self .service .get_client (config_a )
231222 client_b = self .service .get_client (config_b )
@@ -324,13 +315,3 @@ def test_overall_client_retrieval_and_caching(self):
324315 assert client1_app2 .app is self .app2
325316 assert client1_app2 .config is self .config1
326317 assert client1_app2 is not client1a
327-
328- @mock .patch .object (_utils , "get_app_service" , wraps = _utils .get_app_service )
329- def test_uses_app_service_mechanism (self , mock_get_app_service ):
330- """Ensures dataconnect.client uses the standard app service loader."""
331- dataconnect .client (self .config1 , app = self .app1 )
332- mock_get_app_service .assert_called_once ()
333- args , _ = mock_get_app_service .call_args
334- assert args [0 ] is self .app1
335- assert args [1 ] == "_data_connect_service"
336- assert args [2 ] == dataconnect ._DataConnectService # pylint: disable=protected-access
0 commit comments