@@ -37,6 +37,46 @@ def _make_default_one(self):
3737 credentials = _make_credentials ()
3838 return self ._make_one (project = self .PROJECT , credentials = credentials )
3939
40+ def test_constructor_with_emulator_host_defaults (self ):
41+ from google .auth .credentials import AnonymousCredentials
42+ from google .cloud .firestore_v1 .base_client import _DEFAULT_EMULATOR_PROJECT
43+ from google .cloud .firestore_v1 .base_client import _FIRESTORE_EMULATOR_HOST
44+
45+ emulator_host = "localhost:8081"
46+
47+ with mock .patch ("os.environ" , {_FIRESTORE_EMULATOR_HOST : emulator_host }):
48+ client = self ._make_one ()
49+
50+ self .assertEqual (client ._emulator_host , emulator_host )
51+ self .assertIsInstance (client ._credentials , AnonymousCredentials )
52+ self .assertEqual (client .project , _DEFAULT_EMULATOR_PROJECT )
53+
54+ def test_constructor_with_emulator_host_w_project (self ):
55+ from google .auth .credentials import AnonymousCredentials
56+ from google .cloud .firestore_v1 .base_client import _FIRESTORE_EMULATOR_HOST
57+
58+ emulator_host = "localhost:8081"
59+
60+ with mock .patch ("os.environ" , {_FIRESTORE_EMULATOR_HOST : emulator_host }):
61+ client = self ._make_one (project = self .PROJECT )
62+
63+ self .assertEqual (client ._emulator_host , emulator_host )
64+ self .assertIsInstance (client ._credentials , AnonymousCredentials )
65+
66+ def test_constructor_with_emulator_host_w_creds (self ):
67+ from google .cloud .firestore_v1 .base_client import _DEFAULT_EMULATOR_PROJECT
68+ from google .cloud .firestore_v1 .base_client import _FIRESTORE_EMULATOR_HOST
69+
70+ credentials = _make_credentials ()
71+ emulator_host = "localhost:8081"
72+
73+ with mock .patch ("os.environ" , {_FIRESTORE_EMULATOR_HOST : emulator_host }):
74+ client = self ._make_one (credentials = credentials )
75+
76+ self .assertEqual (client ._emulator_host , emulator_host )
77+ self .assertIs (client ._credentials , credentials )
78+ self .assertEqual (client .project , _DEFAULT_EMULATOR_PROJECT )
79+
4080 @mock .patch (
4181 "google.cloud.firestore_v1.services.firestore.client.FirestoreClient" ,
4282 autospec = True ,
0 commit comments