1414
1515import datetime
1616import unittest
17+ import grpc
1718
1819import mock
1920
@@ -67,10 +68,11 @@ def test__firestore_api_property(self, mock_channel, mock_client):
6768 return_value = mock .sentinel .firestore_api ,
6869 )
6970 @mock .patch (
70- "grpc.insecure_channel" , autospec = True ,
71+ "google.cloud.firestore_v1.base_client.BaseClient._emulator_channel" ,
72+ autospec = True ,
7173 )
7274 def test__firestore_api_property_with_emulator (
73- self , mock_insecure_channel , mock_client
75+ self , mock_emulator_channel , mock_client
7476 ):
7577 emulator_host = "localhost:8081"
7678 with mock .patch ("os.getenv" ) as getenv :
@@ -82,7 +84,7 @@ def test__firestore_api_property_with_emulator(
8284 self .assertIs (firestore_api , mock_client .return_value )
8385 self .assertIs (firestore_api , client ._firestore_api_internal )
8486
85- mock_insecure_channel . assert_called_once_with ( emulator_host )
87+ mock_emulator_channel . assert_called_once ( )
8688
8789 # Call again to show that it is cached, but call count is still 1.
8890 self .assertIs (client ._firestore_api , mock_client .return_value )
@@ -135,6 +137,36 @@ def test__rpc_metadata_property_with_emulator(self):
135137 ],
136138 )
137139
140+ def test_emulator_channel (self ):
141+ emulator_host = "localhost:8081"
142+ with mock .patch ("os.getenv" ) as getenv :
143+ getenv .return_value = emulator_host
144+
145+ credentials = _make_credentials ()
146+ database = "quanta"
147+ client = self ._make_one (
148+ project = self .PROJECT , credentials = credentials , database = database
149+ )
150+
151+ # checks that a channel is created
152+ channel = client ._emulator_channel ()
153+ self .assertTrue (isinstance (channel , grpc ._channel .Channel ))
154+ # checks that the credentials are composite ones using a local channel from grpc
155+ composite_credentials = client ._local_composite_credentials ()
156+ self .assertTrue (isinstance (composite_credentials , grpc .ChannelCredentials ))
157+ self .assertTrue (
158+ isinstance (
159+ composite_credentials ._credentials ._call_credentialses [0 ],
160+ grpc ._cython .cygrpc .MetadataPluginCallCredentials ,
161+ )
162+ )
163+ self .assertTrue (
164+ isinstance (
165+ composite_credentials ._credentials ._channel_credentials ,
166+ grpc ._cython .cygrpc .LocalChannelCredentials ,
167+ )
168+ )
169+
138170 def test_field_path (self ):
139171 klass = self ._get_target_class ()
140172 self .assertEqual (klass .field_path ("a" , "b" , "c" ), "a.b.c" )
0 commit comments