Skip to content

Commit f112a85

Browse files
committed
chore(tests): improve client mocking in unit tests
1 parent 27af228 commit f112a85

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

tests/unit/v1/test_async_pipeline.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from google.cloud.firestore_v1 import pipeline_stages as stages
1919
from google.cloud.firestore_v1.pipeline_expressions import Field
2020

21+
from tests.unit.v1._test_helpers import make_async_client
22+
2123

2224
def _make_async_pipeline(*args, client=mock.Mock()):
2325
from google.cloud.firestore_v1.async_pipeline import AsyncPipeline
@@ -189,11 +191,10 @@ async def test_async_pipeline_stream_populated():
189191
from google.cloud.firestore_v1.types import ExecutePipelineResponse
190192
from google.cloud.firestore_v1.types import ExecutePipelineRequest
191193
from google.cloud.firestore_v1.types import Value
192-
from google.cloud.firestore_v1.client import Client
193-
from google.cloud.firestore_v1.document import DocumentReference
194+
from google.cloud.firestore_v1.async_document import AsyncDocumentReference
194195
from google.cloud.firestore_v1.pipeline_result import PipelineResult
195196

196-
real_client = Client()
197+
real_client = make_async_client()
197198
client = mock.Mock()
198199
client.project = "A"
199200
client._database = "B"
@@ -228,7 +229,7 @@ async def test_async_pipeline_stream_populated():
228229

229230
response = results[0]
230231
assert isinstance(response, PipelineResult)
231-
assert isinstance(response.ref, DocumentReference)
232+
assert isinstance(response.ref, AsyncDocumentReference)
232233
assert response.ref.path == "test/my_doc"
233234
assert response.id == "my_doc"
234235
assert response.create_time.seconds == 1
@@ -246,10 +247,9 @@ async def test_async_pipeline_stream_multiple():
246247
from google.cloud.firestore_v1.types import ExecutePipelineResponse
247248
from google.cloud.firestore_v1.types import ExecutePipelineRequest
248249
from google.cloud.firestore_v1.types import Value
249-
from google.cloud.firestore_v1.client import Client
250250
from google.cloud.firestore_v1.pipeline_result import PipelineResult
251251

252-
real_client = Client()
252+
real_client = make_async_client()
253253
client = mock.Mock()
254254
client.project = "A"
255255
client._database = "B"
@@ -358,9 +358,8 @@ async def test_async_pipeline_stream_stream_equivalence():
358358
from google.cloud.firestore_v1.types import Document
359359
from google.cloud.firestore_v1.types import ExecutePipelineResponse
360360
from google.cloud.firestore_v1.types import Value
361-
from google.cloud.firestore_v1.client import Client
362361

363-
real_client = Client()
362+
real_client = make_async_client()
364363
client = mock.Mock()
365364
client.project = "A"
366365
client._database = "B"

tests/unit/v1/test_pipeline.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from google.cloud.firestore_v1 import pipeline_stages as stages
1919
from google.cloud.firestore_v1.pipeline_expressions import Field
2020

21+
from tests.unit.v1._test_helpers import make_client
22+
2123

2224
def _make_pipeline(*args, client=mock.Mock()):
2325
from google.cloud.firestore_v1.pipeline import Pipeline
@@ -190,11 +192,10 @@ def test_pipeline_stream_populated():
190192
from google.cloud.firestore_v1.types import ExecutePipelineResponse
191193
from google.cloud.firestore_v1.types import ExecutePipelineRequest
192194
from google.cloud.firestore_v1.types import Value
193-
from google.cloud.firestore_v1.client import Client
194195
from google.cloud.firestore_v1.document import DocumentReference
195196
from google.cloud.firestore_v1.pipeline_result import PipelineResult
196197

197-
real_client = Client()
198+
real_client = make_client()
198199
client = mock.Mock()
199200
client.project = "A"
200201
client._database = "B"
@@ -244,10 +245,9 @@ def test_pipeline_stream_multiple():
244245
from google.cloud.firestore_v1.types import ExecutePipelineResponse
245246
from google.cloud.firestore_v1.types import ExecutePipelineRequest
246247
from google.cloud.firestore_v1.types import Value
247-
from google.cloud.firestore_v1.client import Client
248248
from google.cloud.firestore_v1.pipeline_result import PipelineResult
249249

250-
real_client = Client()
250+
real_client = make_client()
251251
client = mock.Mock()
252252
client.project = "A"
253253
client._database = "B"
@@ -348,9 +348,8 @@ def test_pipeline_execute_stream_equivalence():
348348
from google.cloud.firestore_v1.types import Document
349349
from google.cloud.firestore_v1.types import ExecutePipelineResponse
350350
from google.cloud.firestore_v1.types import Value
351-
from google.cloud.firestore_v1.client import Client
352351

353-
real_client = Client()
352+
real_client = make_client()
354353
client = mock.Mock()
355354
client.project = "A"
356355
client._database = "B"

tests/unit/v1/test_pipeline_source.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
from google.cloud.firestore_v1.query import Query
2424
from google.cloud.firestore_v1.async_query import AsyncQuery
2525

26+
from tests.unit.v1._test_helpers import make_async_client
27+
from tests.unit.v1._test_helpers import make_client
2628

2729
class TestPipelineSource:
2830
_expected_pipeline_type = Pipeline
2931

3032
def _make_client(self):
31-
return Client()
33+
return make_client()
3234

3335
def _make_query(self):
3436
return Query(mock.Mock())
@@ -120,7 +122,7 @@ class TestPipelineSourceWithAsyncClient(TestPipelineSource):
120122
_expected_pipeline_type = AsyncPipeline
121123

122124
def _make_client(self):
123-
return AsyncClient()
125+
return make_async_client()
124126

125127
def _make_query(self):
126128
return AsyncQuery(mock.Mock())

0 commit comments

Comments
 (0)